Tapping an inventory item now opens its detail (the /variety/:id route was a
placeholder). Read + edit one variety end-to-end:
- Detail view: photo, category, "also known as" names, notes and lots, driven
by a reactive VarietyDetailCubit.
- Edit core fields (label/category/notes, LWW) via a bottom sheet.
- Add a lot (harvest year + quantity) — the list refreshes reactively.
- Soft-delete (tombstone) with a confirm dialog.
Repository:
- watchVariety(id): merges Drift table-change streams (variety, lots, names,
attachments) via StreamGroup and reloads the full detail on any change, so a
lot added to a *different* table still refreshes the view.
- updateVariety (LWW), addLot, softDeleteVariety.
i18n: detail/edit/addLot strings (ES/EN); switched slang to {param} braces
interpolation (translator- and Weblate-friendly).
Tests: repository (reactive watchVariety, update, soft-delete) and widget tests
(render, edit updates title, add-lot appears, delete shows not-found). Full
suite green: 23 passing, 1 skipped (SQLCipher-only encryption guard).
85 lines
3 KiB
Dart
85 lines
3 KiB
Dart
import 'package:commons_core/commons_core.dart';
|
|
import 'package:drift/native.dart';
|
|
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:tane/data/variety_repository.dart';
|
|
import 'package:tane/db/database.dart';
|
|
import 'package:tane/i18n/strings.g.dart';
|
|
import 'package:tane/state/inventory_cubit.dart';
|
|
import 'package:tane/state/variety_detail_cubit.dart';
|
|
import 'package:tane/ui/variety_detail_screen.dart';
|
|
|
|
/// A fresh in-memory database for host tests (unencrypted; encryption is
|
|
/// verified separately in the SQLCipher-only security test).
|
|
AppDatabase newTestDatabase() => AppDatabase(NativeDatabase.memory());
|
|
|
|
/// Unmounts the widget tree *inside* the test and drains the zero-duration
|
|
/// timer Drift schedules when its stream subscription is cancelled. Without
|
|
/// this, flutter_test reports "a Timer is still pending after disposal". Call
|
|
/// at the end of any widget test that mounts an [InventoryCubit].
|
|
Future<void> disposeTree(WidgetTester tester) async {
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump(const Duration(milliseconds: 10));
|
|
}
|
|
|
|
VarietyRepository newTestRepository(
|
|
AppDatabase db, {
|
|
String nodeId = 'test-node',
|
|
}) => VarietyRepository(db, idGen: IdGen(), nodeId: nodeId);
|
|
|
|
/// Wraps [child] with the providers a screen expects (repository, inventory
|
|
/// cubit) plus i18n and Material localizations, pinned to [locale].
|
|
Widget wrapScreen({
|
|
required VarietyRepository repository,
|
|
required Widget child,
|
|
AppLocale locale = AppLocale.en,
|
|
}) {
|
|
LocaleSettings.setLocaleSync(locale);
|
|
return TranslationProvider(
|
|
child: RepositoryProvider.value(
|
|
value: repository,
|
|
child: BlocProvider(
|
|
create: (_) => InventoryCubit(repository),
|
|
child: MaterialApp(
|
|
locale: locale.flutterLocale,
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
home: child,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Wraps the [VarietyDetailScreen] for [varietyId] with its cubit + i18n.
|
|
Widget wrapDetail({
|
|
required VarietyRepository repository,
|
|
required String varietyId,
|
|
AppLocale locale = AppLocale.en,
|
|
}) {
|
|
LocaleSettings.setLocaleSync(locale);
|
|
return TranslationProvider(
|
|
child: RepositoryProvider.value(
|
|
value: repository,
|
|
child: BlocProvider(
|
|
create: (_) => VarietyDetailCubit(repository, varietyId),
|
|
child: MaterialApp(
|
|
locale: locale.flutterLocale,
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
home: const VarietyDetailScreen(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|