tane/apps/app_seeds/test/data/variety_detail_test.dart
vjrj 7ff4e38a15 feat(block1): variety detail + edit screen with reactive lots
Tapping an inventory item now opens its detail (the /variety/:id route was a
placeholder). Read + edit one variety end-to-end:

- Detail view: photo, category, "also known as" names, notes and lots, driven
  by a reactive VarietyDetailCubit.
- Edit core fields (label/category/notes, LWW) via a bottom sheet.
- Add a lot (harvest year + quantity) — the list refreshes reactively.
- Soft-delete (tombstone) with a confirm dialog.

Repository:
- watchVariety(id): merges Drift table-change streams (variety, lots, names,
  attachments) via StreamGroup and reloads the full detail on any change, so a
  lot added to a *different* table still refreshes the view.
- updateVariety (LWW), addLot, softDeleteVariety.

i18n: detail/edit/addLot strings (ES/EN); switched slang to {param} braces
interpolation (translator- and Weblate-friendly).

Tests: repository (reactive watchVariety, update, soft-delete) and widget tests
(render, edit updates title, add-lot appears, delete shows not-found). Full
suite green: 23 passing, 1 skipped (SQLCipher-only encryption guard).
2026-07-07 15:56:03 +02:00

63 lines
1.9 KiB
Dart

import 'package:async/async.dart';
import 'package:commons_core/commons_core.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/data/variety_repository.dart';
import 'package:tane/db/database.dart';
import '../support/test_support.dart';
void main() {
late AppDatabase db;
late VarietyRepository repo;
setUp(() {
db = newTestDatabase();
repo = newTestRepository(db);
});
tearDown(() => db.close());
test('watchVariety emits null for a missing variety', () async {
expect(await repo.watchVariety('does-not-exist').first, isNull);
});
test('watchVariety reacts to a lot being added', () async {
final id = await repo.addQuickVariety(label: 'Maize', category: 'Poaceae');
final queue = StreamQueue(repo.watchVariety(id));
final initial = await queue.next;
expect(initial!.label, 'Maize');
expect(initial.lots, isEmpty);
await repo.addLot(
varietyId: id,
harvestYear: 2024,
quantity: const Quantity(kind: QuantityKind.cob),
);
final updated = await queue.next;
expect(updated!.lots.single.harvestYear, 2024);
expect(updated.lots.single.quantity?.kind, QuantityKind.cob);
await queue.cancel();
});
test('updateVariety changes scalar fields (last-writer-wins)', () async {
final id = await repo.addQuickVariety(label: 'Old name');
await repo.updateVariety(id: id, label: 'New name', notes: 'a note');
final detail = await repo.watchVariety(id).first;
expect(detail!.label, 'New name');
expect(detail.notes, 'a note');
});
test(
'softDeleteVariety hides it from watchVariety and the inventory',
() async {
final id = await repo.addQuickVariety(label: 'Doomed');
await repo.softDeleteVariety(id);
expect(await repo.watchVariety(id).first, isNull);
expect(await repo.watchInventory().first, isEmpty);
},
);
}