Merge branch 'worktree-print-labels': print seed labels with QR
# Conflicts: # apps/app_seeds/lib/i18n/strings.g.dart # apps/app_seeds/lib/ui/inventory_list_screen.dart
This commit is contained in:
commit
63f48db5c2
21 changed files with 1522 additions and 115 deletions
|
|
@ -0,0 +1,90 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/data/export_import/seed_label_codec.dart';
|
||||
|
||||
void main() {
|
||||
group('SeedLabelCodec.encode', () {
|
||||
test('encodes all fields as a tanemaki://seed URI', () {
|
||||
final uri = SeedLabelCodec.encode(
|
||||
const SeedLabelData(
|
||||
varietyLabel: 'Acelga de Perales',
|
||||
scientificName: 'Beta vulgaris',
|
||||
commonName: 'Acelga',
|
||||
year: 2006,
|
||||
origin: 'Perales',
|
||||
),
|
||||
);
|
||||
expect(uri, startsWith('tanemaki://seed?'));
|
||||
final parsed = Uri.parse(uri);
|
||||
expect(parsed.scheme, 'tanemaki');
|
||||
expect(parsed.host, 'seed');
|
||||
expect(parsed.queryParameters, {
|
||||
'v': 'Acelga de Perales',
|
||||
's': 'Beta vulgaris',
|
||||
'c': 'Acelga',
|
||||
'y': '2006',
|
||||
'o': 'Perales',
|
||||
});
|
||||
});
|
||||
|
||||
test('omits absent fields, keeping the payload small', () {
|
||||
final uri = SeedLabelCodec.encode(
|
||||
const SeedLabelData(varietyLabel: 'Alubia de Tolosa'),
|
||||
);
|
||||
final parsed = Uri.parse(uri);
|
||||
expect(parsed.queryParameters, {'v': 'Alubia de Tolosa'});
|
||||
expect(uri, isNot(contains('&s=')));
|
||||
expect(uri, isNot(contains('y=')));
|
||||
});
|
||||
|
||||
test('treats blank optional fields as absent', () {
|
||||
final uri = SeedLabelCodec.encode(
|
||||
const SeedLabelData(
|
||||
varietyLabel: 'Maíz',
|
||||
scientificName: ' ',
|
||||
origin: '',
|
||||
),
|
||||
);
|
||||
expect(Uri.parse(uri).queryParameters, {'v': 'Maíz'});
|
||||
});
|
||||
});
|
||||
|
||||
group('SeedLabelCodec round-trip', () {
|
||||
test('decode reverses encode for full data', () {
|
||||
const data = SeedLabelData(
|
||||
varietyLabel: 'Tomate Rosa',
|
||||
scientificName: 'Solanum lycopersicum',
|
||||
commonName: 'Tomate',
|
||||
year: 2024,
|
||||
origin: 'Huerta de la abuela, León',
|
||||
);
|
||||
expect(SeedLabelCodec.decode(SeedLabelCodec.encode(data)), data);
|
||||
});
|
||||
|
||||
test('survives unicode, spaces and separators', () {
|
||||
const data = SeedLabelData(
|
||||
varietyLabel: 'Grelo & nabo "do país"',
|
||||
origin: 'A Coruña / Galiza',
|
||||
commonName: 'بامية', // RTL script
|
||||
);
|
||||
final decoded = SeedLabelCodec.decode(SeedLabelCodec.encode(data));
|
||||
expect(decoded, data);
|
||||
});
|
||||
});
|
||||
|
||||
group('SeedLabelCodec.decode', () {
|
||||
test('rejects a foreign scheme', () {
|
||||
expect(SeedLabelCodec.decode('https://seed?v=x'), isNull);
|
||||
expect(SeedLabelCodec.decode('tanemaki://other?v=x'), isNull);
|
||||
});
|
||||
|
||||
test('rejects a payload without a variety', () {
|
||||
expect(SeedLabelCodec.decode('tanemaki://seed?s=Beta%20vulgaris'), isNull);
|
||||
});
|
||||
|
||||
test('ignores an unparseable year rather than throwing', () {
|
||||
final decoded = SeedLabelCodec.decode('tanemaki://seed?v=Maíz&y=old');
|
||||
expect(decoded?.varietyLabel, 'Maíz');
|
||||
expect(decoded?.year, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import 'dart:typed_data';
|
|||
|
||||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/data/species_repository.dart';
|
||||
import 'package:tane/data/variety_repository.dart';
|
||||
import 'package:tane/db/database.dart';
|
||||
import 'package:tane/db/enums.dart';
|
||||
|
|
@ -85,4 +86,51 @@ void main() {
|
|||
expect(stamps.toSet().length, 2);
|
||||
expect(() => stamps.map(Hlc.parse).toList(), returnsNormally);
|
||||
});
|
||||
|
||||
group('labelRows', () {
|
||||
test('expands one entry per lot and resolves the locale common name', () async {
|
||||
final speciesRepo = newTestSpeciesRepository(db);
|
||||
await speciesRepo.seedBundled(const [
|
||||
SpeciesSeed(
|
||||
scientificName: 'Beta vulgaris',
|
||||
family: 'Amaranthaceae',
|
||||
commonNames: {
|
||||
'en': ['Chard'],
|
||||
'es': ['Acelga'],
|
||||
},
|
||||
),
|
||||
]);
|
||||
final speciesId = (await db.select(db.species).getSingle()).id;
|
||||
|
||||
final v = await repo.addQuickVariety(
|
||||
label: 'Acelga de Perales',
|
||||
category: 'Amaranthaceae',
|
||||
);
|
||||
await repo.linkSpecies(v, speciesId);
|
||||
await repo.addLot(varietyId: v, harvestYear: 2006, originName: 'Perales');
|
||||
await repo.addLot(varietyId: v, harvestYear: 2008);
|
||||
|
||||
final rows = await repo.labelRows({v}, languageCode: 'es');
|
||||
expect(rows.length, 2); // one per lot
|
||||
expect(rows.first.commonName, 'Acelga'); // locale-picked, not 'Chard'
|
||||
expect(rows.first.scientificName, 'Beta vulgaris');
|
||||
expect(rows.map((r) => r.harvestYear), [2006, 2008]);
|
||||
expect(rows.first.originName, 'Perales');
|
||||
});
|
||||
|
||||
test('yields a single name-only entry for a variety with no lots', () async {
|
||||
final v = await repo.addQuickVariety(label: 'Alubia de Tolosa');
|
||||
final rows = await repo.labelRows({v}, languageCode: 'en');
|
||||
expect(rows.single.varietyLabel, 'Alubia de Tolosa');
|
||||
expect(rows.single.harvestYear, isNull);
|
||||
expect(rows.single.commonName, isNull);
|
||||
});
|
||||
|
||||
test('includes only varieties in the selection', () async {
|
||||
final selected = await repo.addQuickVariety(label: 'Selected');
|
||||
await repo.addQuickVariety(label: 'Not selected');
|
||||
final rows = await repo.labelRows({selected}, languageCode: 'en');
|
||||
expect(rows.map((r) => r.varietyLabel), ['Selected']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue