A bundled, curated knowledge layer — the differentiator of a serious seed app. For a variety's crop it shows how the plant reproduces and what it takes to keep the variety true: life cycle, pollination (self/cross + insect/wind), isolation distance, how many plants to save from, dry/wet processing, a difficulty pill, and a short tip — all in human words. - assets/catalog/seed_saving.json: curated public-domain data (Seed to Seed / Seed Savers), keyed by botanical FAMILY (defaults) with per-species/genus OVERRIDES that win — so e.g. Vicia faba is correctly insect-cross-pollinated despite the selfing Fabaceae default, and maize is wind-pollinated with a large population. Notes are locale-keyed (es/en), extensible to any language — a starter set, not a ceiling. - domain/seed_saving.dart (pure): enums + SeedSavingGuide (merge, note fallback) + SeedSavingData.guideFor (species → genus → family). - data/seed_saving_catalog.dart: loads the asset once into an in-memory singleton (no DB table, no migration); injector loads it at startup. - VarietyDetail gains (from the linked species — the reliable key, vs the editable category); detail screen shows a _SeedSavingView when a guide resolves. - i18n seedSaving block (labels + enum values + params) in en/es/pt/ast. - Tests: domain lookup/merge, the real asset's key corrections, and the detail section shows/hides. 314 suite tests green; analyze clean.
54 lines
1.8 KiB
Dart
54 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tane/data/seed_saving_catalog.dart';
|
|
import 'package:tane/db/database.dart';
|
|
import 'package:tane/domain/seed_saving.dart';
|
|
|
|
import '../support/test_support.dart';
|
|
|
|
/// The variety detail shows "how to save this seed" when the bundled catalog
|
|
/// has guidance for the crop's family, and hides it otherwise.
|
|
void main() {
|
|
late AppDatabase db;
|
|
setUp(() {
|
|
db = newTestDatabase();
|
|
SeedSavingCatalog.data = parseSeedSaving('''
|
|
{
|
|
"families": {
|
|
"Solanaceae": { "pollination": "self", "isolationMinM": 3, "isolationMaxM": 6, "processing": "wet", "difficulty": "easy" }
|
|
},
|
|
"species": {}
|
|
}
|
|
''');
|
|
});
|
|
tearDown(() {
|
|
SeedSavingCatalog.data = null;
|
|
return db.close();
|
|
});
|
|
|
|
Future<void> pumpDetailFor(WidgetTester tester, String? category) async {
|
|
final repo = newTestRepository(db);
|
|
final id = await repo.addQuickVariety(label: 'Tomate', category: category);
|
|
await tester.pumpWidget(wrapDetail(repository: repo, varietyId: id));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets('shows the seed-saving section for a known family', (tester) async {
|
|
await pumpDetailFor(tester, 'Solanaceae');
|
|
|
|
expect(find.text('Saving its seed'), findsOneWidget);
|
|
// The pollination line is a Text.rich (label + value), so match the run.
|
|
expect(find.textContaining('Self-pollinating'), findsOneWidget);
|
|
expect(find.text('Easy'), findsOneWidget); // the difficulty pill
|
|
|
|
await disposeTree(tester);
|
|
});
|
|
|
|
testWidgets('hides the section when nothing matches', (tester) async {
|
|
await pumpDetailFor(tester, 'Unknownaceae');
|
|
|
|
expect(find.text('Saving its seed'), findsNothing);
|
|
|
|
await disposeTree(tester);
|
|
});
|
|
}
|