feat(quick-add): save & add another for rapid manual entry
The quick-add sheet no longer closes on every save: a new 'Save & add another' action saves the seed, clears the form (keeping the chosen lot type), refocuses the name field and shows an 'N added' running count, so a whole shelf can be entered without reopening the sheet each time. Plain Save still closes it. Adds a dedicated label field with its own controller, submitAndAddAnother() on the cubit, and cubit + widget tests.
This commit is contained in:
parent
89b61bc9e4
commit
d3711e39b0
9 changed files with 240 additions and 18 deletions
67
apps/app_seeds/test/state/quick_add_cubit_test.dart
Normal file
67
apps/app_seeds/test/state/quick_add_cubit_test.dart
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/db/database.dart';
|
||||
import 'package:tane/db/enums.dart';
|
||||
import 'package:tane/state/quick_add_cubit.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase db;
|
||||
late QuickAddCubit cubit;
|
||||
|
||||
setUp(() {
|
||||
db = newTestDatabase();
|
||||
cubit = QuickAddCubit(newTestRepository(db));
|
||||
});
|
||||
tearDown(() async {
|
||||
await cubit.close();
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('submitAndAddAnother with an empty label errors and saves nothing',
|
||||
() async {
|
||||
await cubit.submitAndAddAnother();
|
||||
expect(cubit.state.showLabelError, isTrue);
|
||||
expect(cubit.state.addedCount, 0);
|
||||
expect(await db.select(db.varieties).get(), isEmpty);
|
||||
});
|
||||
|
||||
test('submitAndAddAnother saves, resets the form and keeps the lot type',
|
||||
() async {
|
||||
cubit
|
||||
..setLotType(LotType.plant)
|
||||
..labelChanged('Basil')
|
||||
..setQuantity(const Quantity(kind: QuantityKind.plant, count: 3));
|
||||
|
||||
await cubit.submitAndAddAnother();
|
||||
|
||||
// Saved to the DB.
|
||||
final varieties = await db.select(db.varieties).get();
|
||||
expect(varieties.single.label, 'Basil');
|
||||
|
||||
// Form reset for the next one, but the chosen lot type is kept and the
|
||||
// sheet is NOT told to close (submitted stays false).
|
||||
expect(cubit.state.label, '');
|
||||
expect(cubit.state.quantity, isNull);
|
||||
expect(cubit.state.lotType, LotType.plant);
|
||||
expect(cubit.state.submitted, isFalse);
|
||||
expect(cubit.state.addedCount, 1);
|
||||
});
|
||||
|
||||
test('addedCount accumulates across several saves', () async {
|
||||
cubit.labelChanged('One');
|
||||
await cubit.submitAndAddAnother();
|
||||
cubit.labelChanged('Two');
|
||||
await cubit.submitAndAddAnother();
|
||||
|
||||
expect(cubit.state.addedCount, 2);
|
||||
expect(await db.select(db.varieties).get(), hasLength(2));
|
||||
});
|
||||
|
||||
test('submit still closes the sheet (submitted = true)', () async {
|
||||
cubit.labelChanged('Once');
|
||||
await cubit.submit();
|
||||
expect(cubit.state.submitted, isTrue);
|
||||
});
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ void main() {
|
|||
child: TaneApp(
|
||||
repository: repo,
|
||||
species: newTestSpeciesRepository(db),
|
||||
onboarding: newTestOnboardingStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -57,4 +58,61 @@ void main() {
|
|||
await disposeTree(tester);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'save & add another keeps the sheet open and accumulates a count',
|
||||
(tester) async {
|
||||
LocaleSettings.setLocaleSync(AppLocale.en);
|
||||
final db = newTestDatabase();
|
||||
addTearDown(db.close);
|
||||
final repo = newTestRepository(db);
|
||||
|
||||
await tester.pumpWidget(
|
||||
TranslationProvider(
|
||||
child: TaneApp(
|
||||
repository: repo,
|
||||
species: newTestSpeciesRepository(db),
|
||||
onboarding: newTestOnboardingStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home.inventory')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('inventory.addFab')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// First seed via "save & add another": the sheet stays open.
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('quickAdd.labelField')),
|
||||
'Alpha',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('quickAdd.saveAndAddAnother')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('quickAdd.labelField')), findsOneWidget);
|
||||
expect(find.text('1 added'), findsOneWidget);
|
||||
|
||||
// The field was cleared; add a second one.
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('quickAdd.labelField')),
|
||||
'Beta',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('quickAdd.saveAndAddAnother')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('2 added'), findsOneWidget);
|
||||
|
||||
// A third one via plain Save closes the sheet.
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('quickAdd.labelField')),
|
||||
'Gamma',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('quickAdd.save')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('quickAdd.labelField')), findsNothing);
|
||||
|
||||
// All three landed in the inventory.
|
||||
expect(await db.select(db.varieties).get(), hasLength(3));
|
||||
await disposeTree(tester);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue