feat(plantare): surface product link + dates; spec the bilateral record

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.
This commit is contained in:
vjrj 2026-07-13 18:06:33 +02:00
parent e57763d0a2
commit adf396d49d
21 changed files with 687 additions and 27 deletions

View file

@ -61,6 +61,34 @@ void main() {
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);

View file

@ -0,0 +1,114 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:tane/app.dart' show materialLocaleFor;
import 'package:tane/db/database.dart';
import 'package:tane/db/enums.dart';
import 'package:tane/i18n/strings.g.dart';
import 'package:tane/ui/plantares_screen.dart';
import '../support/test_support.dart';
/// The Plantares screen used to hide the data it stored: no date, no link to
/// the seed. These pin the surfaced version a named, dated, tappable
/// commitment with an overdue nudge.
void main() {
late AppDatabase db;
setUp(() => db = newTestDatabase());
tearDown(() => db.close());
testWidgets('a tile names the linked seed and flags an overdue return-by',
(tester) async {
final repo = newTestRepository(db);
final vid = await repo.addQuickVariety(label: 'Tomate rosa');
await repo.createPlantare(
direction: PlantareDirection.iReturn,
varietyId: vid,
counterparty: 'Ana',
dueBy: DateTime(2000, 1, 1).millisecondsSinceEpoch, // long past overdue
);
await tester.pumpWidget(
wrapScreen(repository: repo, child: const PlantaresScreen()),
);
await tester.pump(); // let the Drift stream emit
await tester.pump(const Duration(milliseconds: 100));
expect(find.textContaining('Tomate rosa'), findsOneWidget);
expect(find.textContaining('Ana'), findsOneWidget);
expect(find.textContaining('Return by'), findsOneWidget);
expect(find.textContaining('overdue'), findsOneWidget);
await disposeTree(tester);
});
testWidgets('an open commitment with no due date shows no overdue flag',
(tester) async {
final repo = newTestRepository(db);
final vid = await repo.addQuickVariety(label: 'Maíz');
await repo.createPlantare(
direction: PlantareDirection.owedToMe,
varietyId: vid,
);
await tester.pumpWidget(
wrapScreen(repository: repo, child: const PlantaresScreen()),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.textContaining('overdue'), findsNothing);
expect(find.textContaining('Return by'), findsNothing);
await disposeTree(tester);
});
testWidgets('tapping a linked commitment opens its variety', (tester) async {
final repo = newTestRepository(db);
final vid = await repo.addQuickVariety(label: 'Judía');
await repo.createPlantare(
direction: PlantareDirection.iReturn,
varietyId: vid,
);
LocaleSettings.setLocaleSync(AppLocale.en);
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (_, _) => const PlantaresScreen(),
),
GoRoute(
path: '/variety/:id',
builder: (_, state) =>
Scaffold(body: Text('variety ${state.pathParameters['id']}')),
),
],
);
await tester.pumpWidget(
TranslationProvider(
child: RepositoryProvider.value(
value: repo,
child: MaterialApp.router(
routerConfig: router,
locale: materialLocaleFor(AppLocale.en.flutterLocale),
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.byType(ListTile).first);
await tester.pumpAndSettle();
expect(find.text('variety $vid'), findsOneWidget);
await disposeTree(tester);
});
}

View file

@ -48,5 +48,10 @@ void main() {
expectAa(Colors.white, seedGreen, 'white on primary green');
expectAa(Colors.white, seedAppBar, 'white on app-bar green');
});
test('overdue warning text on every background it sits on', () {
expectAa(seedWarning, Colors.white, 'seedWarning on white');
expectAa(seedWarning, seedCanvas, 'seedWarning on canvas');
});
});
}

View file

@ -610,4 +610,35 @@ void main() {
expect(find.byIcon(Icons.star_border), findsNothing);
await disposeTree(tester);
});
testWidgets('shows a commitments section only when the variety has one', (
tester,
) async {
final repo = newTestRepository(db);
final id = await repo.addQuickVariety(label: 'Maize');
await tester.pumpWidget(
wrapDetail(
repository: repo,
varietyId: id,
species: newTestSpeciesRepository(db),
),
);
await tester.pumpAndSettle();
// No commitments yet the section stays hidden (progressive disclosure).
expect(find.byKey(const Key('detail.plantares')), findsNothing);
await repo.createPlantare(
direction: PlantareDirection.iReturn,
varietyId: id,
counterparty: 'Ana',
owedDescription: 'un puñado',
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('detail.plantares')), findsOneWidget);
expect(find.textContaining('un puñado'), findsOneWidget);
expect(find.textContaining('Ana'), findsOneWidget);
await disposeTree(tester);
});
}