home added
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:receipity/models/line_item.dart';
|
||||
|
||||
import 'test_helpers.dart';
|
||||
|
||||
void main() {
|
||||
ensureTestSqlite();
|
||||
|
||||
test('deleting a product keeps the trip line and drops the catalog row',
|
||||
() async {
|
||||
final repository = memoryRepository();
|
||||
final shopId = await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 12),
|
||||
items: [LineItem(id: '1', name: 'Milk', price: 1.5)],
|
||||
);
|
||||
|
||||
final products = await repository.getAll();
|
||||
expect(products, hasLength(1));
|
||||
await repository.deleteProduct(products.single.id);
|
||||
|
||||
expect(await repository.getAll(), isEmpty);
|
||||
final items = await repository.getShopItems(shopId);
|
||||
expect(items, hasLength(1));
|
||||
expect(items.single.name, 'Milk');
|
||||
expect(items.single.productId, isNull);
|
||||
});
|
||||
|
||||
test('deleting all products leaves shopping trips in place', () async {
|
||||
final repository = memoryRepository();
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 12),
|
||||
items: [
|
||||
LineItem(id: '1', name: 'Milk', price: 1.5),
|
||||
LineItem(id: '2', name: 'Bread', price: 2),
|
||||
],
|
||||
);
|
||||
await repository.deleteAllProducts();
|
||||
|
||||
expect(await repository.getAll(), isEmpty);
|
||||
expect(await repository.getShops(), hasLength(1));
|
||||
final overview = await repository.getOverview();
|
||||
expect(overview.productCount, 0);
|
||||
expect(overview.tripCount, 1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user