feat(seed-saving): per-crop 'how to save this seed' guidance
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.
This commit is contained in:
parent
bfff95fe8d
commit
7c2e3f207f
19 changed files with 954 additions and 2 deletions
51
apps/app_seeds/test/data/seed_saving_asset_test.dart
Normal file
51
apps/app_seeds/test/data/seed_saving_asset_test.dart
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/domain/seed_saving.dart';
|
||||
|
||||
/// Guards the committed bundled seed-saving asset: it must parse, cover the
|
||||
/// major families, and carry the notable per-species corrections the UI relies
|
||||
/// on. Reads the file directly — no Flutter asset bundle — so it runs as a
|
||||
/// plain VM test.
|
||||
void main() {
|
||||
final data =
|
||||
parseSeedSaving(File('assets/catalog/seed_saving.json').readAsStringSync());
|
||||
|
||||
test('resolves the major families', () {
|
||||
for (final family in const [
|
||||
'Solanaceae',
|
||||
'Fabaceae',
|
||||
'Cucurbitaceae',
|
||||
'Brassicaceae',
|
||||
'Asteraceae',
|
||||
'Apiaceae',
|
||||
'Amaranthaceae',
|
||||
'Poaceae',
|
||||
]) {
|
||||
expect(data.guideFor(family: family)?.hasAny, isTrue, reason: family);
|
||||
}
|
||||
});
|
||||
|
||||
test('faba bean is corrected to insect cross-pollination', () {
|
||||
// The whole point of species overrides: unlike other legumes, Vicia faba
|
||||
// crosses — the guidance must not inherit Fabaceae "self".
|
||||
final g = data.guideFor(scientificName: 'Vicia faba', family: 'Fabaceae');
|
||||
expect(g?.pollination, Pollination.cross);
|
||||
expect(g?.vector, PollinationVector.insect);
|
||||
expect(g?.noteFor('es'), isNotNull);
|
||||
});
|
||||
|
||||
test('tomato self-pollinates and is wet-processed', () {
|
||||
final g = data.guideFor(
|
||||
scientificName: 'Solanum lycopersicum', family: 'Solanaceae');
|
||||
expect(g?.pollination, Pollination.self);
|
||||
expect(g?.processing, SeedProcessing.wet);
|
||||
expect(g?.difficulty, SavingDifficulty.easy);
|
||||
});
|
||||
|
||||
test('maize is wind-pollinated with a large population', () {
|
||||
final g = data.guideFor(scientificName: 'Zea mays', family: 'Poaceae');
|
||||
expect(g?.vector, PollinationVector.wind);
|
||||
expect(g?.recommendedPlants, greaterThanOrEqualTo(50));
|
||||
});
|
||||
}
|
||||
67
apps/app_seeds/test/domain/seed_saving_test.dart
Normal file
67
apps/app_seeds/test/domain/seed_saving_test.dart
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/domain/seed_saving.dart';
|
||||
|
||||
/// Pure lookup/merge logic for the seed-saving guidance: a per-species entry
|
||||
/// overrides its family default, a bare genus is a fallback, and unknown crops
|
||||
/// resolve to null.
|
||||
void main() {
|
||||
final data = parseSeedSaving('''
|
||||
{
|
||||
"families": {
|
||||
"Fabaceae": { "lifeCycle": "annual", "pollination": "self", "processing": "dry", "difficulty": "easy" },
|
||||
"Solanaceae": { "pollination": "self", "isolationMinM": 3, "isolationMaxM": 15 }
|
||||
},
|
||||
"species": {
|
||||
"Vicia faba": { "pollination": "cross", "vector": "insect", "isolationMinM": 180, "note": {"es": "aísla", "en": "isolate"} },
|
||||
"Cucurbita": { "pollination": "cross", "vector": "insect" }
|
||||
}
|
||||
}
|
||||
''');
|
||||
|
||||
test('a species entry overrides its family default', () {
|
||||
final g = data.guideFor(scientificName: 'Vicia faba', family: 'Fabaceae');
|
||||
expect(g, isNotNull);
|
||||
// Family said self+easy+annual; the species override flips pollination.
|
||||
expect(g!.pollination, Pollination.cross);
|
||||
expect(g.vector, PollinationVector.insect);
|
||||
expect(g.isolationMinM, 180);
|
||||
// Fields the species didn't set fall through to the family.
|
||||
expect(g.lifeCycle, LifeCycle.annual);
|
||||
expect(g.difficulty, SavingDifficulty.easy);
|
||||
expect(g.processing, SeedProcessing.dry);
|
||||
});
|
||||
|
||||
test('a bare genus key is a fallback when the species is unlisted', () {
|
||||
final g = data.guideFor(scientificName: 'Cucurbita maxima', family: null);
|
||||
expect(g?.pollination, Pollination.cross);
|
||||
expect(g?.vector, PollinationVector.insect);
|
||||
});
|
||||
|
||||
test('family-only lookup returns the family default', () {
|
||||
final g = data.guideFor(family: 'Solanaceae');
|
||||
expect(g?.pollination, Pollination.self);
|
||||
expect(g?.isolationMaxM, 15);
|
||||
});
|
||||
|
||||
test('lookup is case-insensitive', () {
|
||||
expect(data.guideFor(family: 'fabaceae'), isNotNull);
|
||||
expect(data.guideFor(scientificName: 'vicia faba'), isNotNull);
|
||||
});
|
||||
|
||||
test('an unknown crop resolves to null', () {
|
||||
expect(data.guideFor(scientificName: 'Musa acuminata', family: 'Musaceae'),
|
||||
isNull);
|
||||
});
|
||||
|
||||
test('noteFor falls back to English then any language', () {
|
||||
final g = data.guideFor(scientificName: 'Vicia faba')!;
|
||||
expect(g.noteFor('es'), 'aísla');
|
||||
expect(g.noteFor('fr'), 'isolate'); // no fr → en
|
||||
});
|
||||
|
||||
test('mergedWith unions notes with the override winning', () {
|
||||
const base = SeedSavingGuide(note: {'es': 'a', 'en': 'b'});
|
||||
const over = SeedSavingGuide(note: {'es': 'c'});
|
||||
expect(base.mergedWith(over).note, {'es': 'c', 'en': 'b'});
|
||||
});
|
||||
}
|
||||
54
apps/app_seeds/test/ui/seed_saving_section_test.dart
Normal file
54
apps/app_seeds/test/ui/seed_saving_section_test.dart
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue