test(state): cover InventoryCubit and VarietyDetailCubit; refresh block1 status doc

This commit is contained in:
vjrj 2026-07-09 22:03:36 +02:00
parent a96d82add9
commit cf5d302cc1
4 changed files with 292 additions and 47 deletions

View file

@ -19,35 +19,39 @@ void main() {
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 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));
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();
await cubit.submitAndAddAnother();
// Saved to the DB.
final varieties = await db.select(db.varieties).get();
expect(varieties.single.label, 'Basil');
// 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);
});
// 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');