feat(inventory): local sharing — per-lot share terms, filter and printable catalog

The local half of the original Fase 2 (no network, no Offer entity yet):
- Lot sheet gains a 'do you share it?' choice (gift/swap first, sale last,
  never the default); declaring plenty of abundance reveals it with a nudge.
- Lot lines and list tiles badge shared batches; an 'I share' filter and
  a printable PDF catalog (paper bridge for fairs) round out the view.
- Catalog PDF embeds DejaVu (Latin-ext/Cyrillic/Greek); fonts are a
  per-locale resource like the OCR packs.
This commit is contained in:
vjrj 2026-07-09 22:19:55 +02:00
parent e3ec855630
commit ba87bf2719
20 changed files with 982 additions and 36 deletions

View file

@ -0,0 +1,112 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/db/database.dart';
import 'package:tane/db/enums.dart';
import 'package:tane/ui/inventory_list_screen.dart';
import '../support/test_support.dart';
void main() {
late AppDatabase db;
setUp(() => db = newTestDatabase());
tearDown(() => db.close());
testWidgets('marking a lot to give away shows on its tile', (tester) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Maize');
await repo.addLot(varietyId: id, harvestYear: 2024);
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
await tester.tap(find.textContaining('Year 2024')); // open the lot
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(const Key('lot.addShare')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('lot.addShare')));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(const Key('share.shared')));
await tester.tap(find.byKey(const Key('share.shared')));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(const Key('addLot.save')));
await tester.tap(find.byKey(const Key('addLot.save')));
await tester.pumpAndSettle();
// The lot line now carries the share terms.
expect(find.textContaining('To give away'), findsOneWidget);
await disposeTree(tester);
});
testWidgets('declaring plenty reveals the share choice with a nudge', (
tester,
) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Maize');
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail.addLot')));
await tester.pumpAndSettle();
// Reveal abundance and declare plenty.
await tester.ensureVisible(find.byKey(const Key('lot.addAbundance')));
await tester.tap(find.byKey(const Key('lot.addAbundance')));
await tester.pumpAndSettle();
await tester.ensureVisible(
find.byKey(const Key('abundance.plentyToShare')),
);
await tester.tap(find.byKey(const Key('abundance.plentyToShare')));
await tester.pumpAndSettle();
// The share section reveals itself, still private, with a soft nudge.
expect(find.byKey(const Key('share.private')), findsOneWidget);
expect(find.byKey(const Key('share.nudge')), findsOneWidget);
await disposeTree(tester);
});
testWidgets('the sharing filter narrows the list to what I share', (
tester,
) async {
final repo = newTestRepository(db);
final sharedId = await repo.addQuickVariety(label: 'Shared bean');
await repo.addLot(varietyId: sharedId, offerStatus: OfferStatus.exchange);
final privateId = await repo.addQuickVariety(label: 'Private bean');
await repo.addLot(varietyId: privateId);
await tester.pumpWidget(
wrapScreen(repository: repo, child: const InventoryListScreen()),
);
await tester.pumpAndSettle();
// Both listed; the shared one carries its badge, and the print action and
// filter chip are offered.
expect(find.text('Shared bean'), findsOneWidget);
expect(find.text('Private bean'), findsOneWidget);
expect(find.byKey(Key('inventory.shared.$sharedId')), findsOneWidget);
expect(find.byKey(const Key('inventory.printCatalog')), findsOneWidget);
await tester.tap(find.byKey(const Key('inventory.filter.sharing')));
await tester.pumpAndSettle();
expect(find.text('Shared bean'), findsOneWidget);
expect(find.text('Private bean'), findsNothing);
await disposeTree(tester);
});
}