The Plantaré screen stored madeOn/dueBy/varietyId but showed none of them,
so it felt half-built. Surface what's already there (no schema change):
- watchPlantareViews() joins each commitment with its variety label
- tile shows the made-on date, a "Return by {date}" line (amber + "overdue"
when an open promise is past due, via new seedWarning colour), the variety
name, and taps through to /variety/:id
- add sheet gains an optional return-by date picker (createPlantare already
took dueBy)
- variety detail shows a read-only commitments section (hidden when empty,
no add button — honours the single hand-over door)
- i18n en/es/pt/ast; tests for the join, dueBy round-trip, tile, and section
Also specs the deferred two-sided record in docs/design/plantare-bilateral.md
(Nostr pubkey counterparty, PlantareTransport propose->accept->counter-sign,
deferred key/signature/movement columns, provenance DAG, reputation anchor),
with a faithful transcription of the paper Plantaré v0.4 (BAH-Semillero 2009,
CC-BY-SA). Cross-linked from data-model §2.7 and sharing-model §6.
114 lines
4.2 KiB
Dart
114 lines
4.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tane/db/database.dart';
|
|
import 'package:tane/db/enums.dart';
|
|
|
|
import '../support/test_support.dart';
|
|
|
|
/// A Plantare is a reproduction commitment (data-model §2.7): create it, list
|
|
/// it, mark it returned/forgiven, and remove it (soft-delete).
|
|
void main() {
|
|
late AppDatabase db;
|
|
setUp(() => db = newTestDatabase());
|
|
tearDown(() => db.close());
|
|
|
|
test('records a commitment and lists it (globally and per variety)', () async {
|
|
final repo = newTestRepository(db);
|
|
final vid = await repo.addQuickVariety(label: 'Tomate rosa');
|
|
final id = await repo.createPlantare(
|
|
direction: PlantareDirection.iReturn,
|
|
varietyId: vid,
|
|
counterparty: 'Ana',
|
|
owedDescription: 'un puñado la próxima temporada',
|
|
);
|
|
|
|
final all = await repo.watchPlantares().first;
|
|
expect(all, hasLength(1));
|
|
expect(all.single.id, id);
|
|
expect(all.single.direction, PlantareDirection.iReturn);
|
|
expect(all.single.counterparty, 'Ana');
|
|
expect(all.single.status, PlantareStatus.open);
|
|
expect(all.single.madeOn, greaterThan(0));
|
|
|
|
final forVariety = await repo.watchPlantaresForVariety(vid).first;
|
|
expect(forVariety.single.id, id);
|
|
// A different variety has none.
|
|
final other = await repo.addQuickVariety(label: 'Judía');
|
|
expect(await repo.watchPlantaresForVariety(other).first, isEmpty);
|
|
});
|
|
|
|
test('marking it returned stamps the settle time; forgiving keeps it settled',
|
|
() async {
|
|
final repo = newTestRepository(db);
|
|
final id = await repo.createPlantare(direction: PlantareDirection.owedToMe);
|
|
|
|
await repo.setPlantareStatus(id, PlantareStatus.returned);
|
|
var row = (await repo.watchPlantares().first).single;
|
|
expect(row.status, PlantareStatus.returned);
|
|
expect(row.settledOn, isNotNull);
|
|
|
|
// Reopening clears the settle stamp.
|
|
await repo.setPlantareStatus(id, PlantareStatus.open);
|
|
row = (await repo.watchPlantares().first).single;
|
|
expect(row.status, PlantareStatus.open);
|
|
expect(row.settledOn, isNull);
|
|
});
|
|
|
|
test('deleting a commitment tombstones it (drops from the list)', () async {
|
|
final repo = newTestRepository(db);
|
|
final id = await repo.createPlantare(direction: PlantareDirection.iReturn);
|
|
expect(await repo.watchPlantares().first, hasLength(1));
|
|
await repo.deletePlantare(id);
|
|
expect(await repo.watchPlantares().first, isEmpty);
|
|
});
|
|
|
|
test('watchPlantareViews joins the linked variety label (null when unlinked)',
|
|
() async {
|
|
final repo = newTestRepository(db);
|
|
final vid = await repo.addQuickVariety(label: 'Tomate rosa');
|
|
await repo.createPlantare(
|
|
direction: PlantareDirection.iReturn,
|
|
varietyId: vid,
|
|
);
|
|
await repo.createPlantare(direction: PlantareDirection.owedToMe);
|
|
|
|
final views = await repo.watchPlantareViews().first;
|
|
expect(views, hasLength(2));
|
|
final linked = views.firstWhere((v) => v.plantare.varietyId == vid);
|
|
expect(linked.varietyLabel, 'Tomate rosa');
|
|
final unlinked = views.firstWhere((v) => v.plantare.varietyId == null);
|
|
expect(unlinked.varietyLabel, isNull);
|
|
});
|
|
|
|
test('a return-by date round-trips through create', () async {
|
|
final repo = newTestRepository(db);
|
|
final due = DateTime(2027, 3, 1).millisecondsSinceEpoch;
|
|
await repo.createPlantare(
|
|
direction: PlantareDirection.iReturn,
|
|
dueBy: due,
|
|
);
|
|
expect((await repo.watchPlantares().first).single.dueBy, due);
|
|
});
|
|
|
|
test('commitments survive a backup round-trip (in exportInventory/import)',
|
|
() async {
|
|
final repoA = newTestRepository(db);
|
|
final vid = await repoA.addQuickVariety(label: 'Maíz');
|
|
await repoA.createPlantare(
|
|
direction: PlantareDirection.iReturn,
|
|
varietyId: vid,
|
|
counterparty: 'Colectivo semillero',
|
|
owedDescription: 'una mazorca',
|
|
);
|
|
|
|
final snapshot = await repoA.exportInventory();
|
|
expect(snapshot.plantares, hasLength(1));
|
|
|
|
final dbB = newTestDatabase();
|
|
addTearDown(dbB.close);
|
|
final repoB = newTestRepository(dbB);
|
|
await repoB.importInventory(snapshot);
|
|
final onB = await repoB.watchPlantares().first;
|
|
expect(onB.single.counterparty, 'Colectivo semillero');
|
|
expect(onB.single.owedDescription, 'una mazorca');
|
|
});
|
|
}
|