tane/apps/app_seeds/test/ui/variety_detail_screen_test.dart
vjrj 3942975dba feat(inventory): informal quantity scale (number + unit) + seed/plant lots
Rework quantities the way seeds are actually described — a number of an informal
unit — and let a lot hold seeds or plants (plantel).

Quantity model (commons_core):
- Quantity is now { kind, count?, label } — "3 cobs", "2 packets", "a few".
  Count is optional; uncountable vibes (a few, some, pinch) carry no number.
- QuantityKind reorganised into an ascending scale: vibes → containers
  (teaspoon/spoon/cup/jar/sack) → seed & fruit forms → plant units, each tagged
  countable/not. Stored by name; count reuses the existing numeric column.

Lot type (schema v2):
- Lots gain a `type` (seed | plant); germination stays meaningful for seeds.
  schemaVersion 2 with a from1To2 migration (adds the column), drift_schema_v2
  exported, migration test covers v1→v2.

UI:
- New QuantityPicker: a horizontal scale of large seed-glyph icons + a number
  stepper (shown only for countable units), plus a seed/plant SegmentedButton.
  Used in quick-add and add-lot. Lot lines render "3 cobs" / "a few".
- i18n: unit singular/plural (ES/EN, Weblate-friendly), lot-type labels.

Build: slang moved to its CLI (disabled in build_runner to avoid a multi-file
collision); CI runs `dart run slang` before build_runner. 38 tests green,
Linux migrates the existing v1 DB and runs.
2026-07-08 10:51:02 +02:00

200 lines
5.9 KiB
Dart

import 'package:commons_core/commons_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/data/species_repository.dart';
import 'package:tane/db/database.dart';
import '../support/test_support.dart';
void main() {
late AppDatabase db;
setUp(() => db = newTestDatabase());
tearDown(() => db.close());
testWidgets('renders the variety label, category and its lots', (
tester,
) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Maize', category: 'Poaceae');
await repo.addLot(
varietyId: id,
harvestYear: 2024,
quantity: const Quantity(kind: QuantityKind.cob),
);
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
expect(find.text('Maize'), findsOneWidget); // app bar title
expect(find.text('Poaceae'), findsOneWidget); // category chip
expect(find.text('Year 2024 · cob'), findsOneWidget); // lot line
await disposeTree(tester);
});
testWidgets('editing the name updates the title', (tester) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Old name');
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail.edit')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('editVariety.name')),
'New name',
);
await tester.tap(find.byKey(const Key('editVariety.save')));
await tester.pumpAndSettle();
expect(find.text('New name'), findsOneWidget);
await disposeTree(tester);
});
testWidgets('adding a lot shows it in the list', (tester) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Bean');
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
expect(find.text('No lots yet.'), findsOneWidget);
await tester.tap(find.byKey(const Key('detail.addLot')));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('addLot.year')), '2023');
await tester.tap(find.text('handful')); // pick the unit from the scale
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('quantity.count')), '2');
await tester.tap(find.byKey(const Key('addLot.save')));
await tester.pumpAndSettle();
expect(find.text('Year 2023 · 2 handfuls'), findsOneWidget);
await disposeTree(tester);
});
testWidgets('deleting the variety shows the not-found state', (tester) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Doomed');
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail.delete')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail.deleteConfirm')));
await tester.pumpAndSettle();
// The variety is soft-deleted: the reactive view re-emits null.
expect(find.text('This seed is no longer here.'), findsOneWidget);
await disposeTree(tester);
});
testWidgets(
'linking a species from the edit sheet shows its scientific name',
(tester) async {
final repo = newTestRepository(db);
final species = newTestSpeciesRepository(db);
await species.seedBundled(const [
SpeciesSeed(
scientificName: 'Solanum lycopersicum',
family: 'Solanaceae',
commonNames: {
'en': ['Tomato'],
},
),
]);
final id = await repo.addQuickVariety(label: "Grandma's tomato");
await tester.pumpWidget(
wrapDetail(repository: repo, varietyId: id, species: species),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail.edit')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('editVariety.species')),
'toma',
);
await tester.pumpAndSettle();
await tester.tap(find.text('Tomato (Solanum lycopersicum)'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editVariety.save')));
await tester.pumpAndSettle();
// Detail now shows the scientific name and the family-prefilled category.
expect(find.text('Solanum lycopersicum'), findsOneWidget);
expect(find.text('Solanaceae'), findsOneWidget);
await disposeTree(tester);
},
);
testWidgets('recording a germination test shows the rate badge on the lot', (
tester,
) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Maize');
await repo.addLot(
varietyId: id,
harvestYear: 2024,
quantity: const Quantity(kind: QuantityKind.cob),
);
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.grass_outlined).first);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('germination.germinated')),
'18',
);
await tester.enterText(
find.byKey(const Key('germination.sampleSize')),
'20',
);
await tester.tap(find.byKey(const Key('germination.save')));
await tester.pumpAndSettle();
expect(find.text('90%'), findsOneWidget); // germination badge on the lot
await disposeTree(tester);
});
}