fixes before build
This commit is contained in:
+35
-9
@@ -6,8 +6,29 @@ import 'test_helpers.dart';
|
||||
void main() {
|
||||
ensureTestSqlite();
|
||||
|
||||
test('deleting a product keeps the trip line and drops the catalog row',
|
||||
() async {
|
||||
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('addShopItem appends a line and updates the trip total', () async {
|
||||
final repository = memoryRepository();
|
||||
final shopId = await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
@@ -15,15 +36,20 @@ void main() {
|
||||
items: [LineItem(id: '1', name: 'Milk', price: 1.5)],
|
||||
);
|
||||
|
||||
final products = await repository.getAll();
|
||||
expect(products, hasLength(1));
|
||||
await repository.deleteProduct(products.single.id);
|
||||
await repository.addShopItem(
|
||||
shopId: shopId,
|
||||
item: LineItem(id: '2', name: 'Bread', price: 2),
|
||||
);
|
||||
|
||||
expect(await repository.getAll(), isEmpty);
|
||||
final shop = (await repository.getShop(shopId))!;
|
||||
expect(shop.total, 3.5);
|
||||
final items = await repository.getShopItems(shopId);
|
||||
expect(items, hasLength(1));
|
||||
expect(items.single.name, 'Milk');
|
||||
expect(items.single.productId, isNull);
|
||||
expect(items, hasLength(2));
|
||||
expect(items.map((item) => item.name), ['Milk', 'Bread']);
|
||||
expect((await repository.getAll()).map((product) => product.name).toSet(), {
|
||||
'Milk',
|
||||
'Bread',
|
||||
});
|
||||
});
|
||||
|
||||
test('deleting all products leaves shopping trips in place', () async {
|
||||
|
||||
@@ -10,6 +10,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('ranks closer matches higher', () {
|
||||
expect(fuzzyScore('melk', 'MELK')! > fuzzyScore('melk', 'JUMBO BIO VOLLE MELK')!, isTrue);
|
||||
expect(
|
||||
fuzzyScore('melk', 'MELK')! > fuzzyScore('melk', 'JUMBO BIO VOLLE MELK')!,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:receipity/models/line_item.dart';
|
||||
import 'package:receipity/models/product.dart';
|
||||
import 'package:receipity/utils/product_names.dart';
|
||||
|
||||
import 'test_helpers.dart';
|
||||
|
||||
Product _product(int id, String name, {String? supermarket}) => Product(
|
||||
id: id,
|
||||
name: name,
|
||||
lastPrice: 1,
|
||||
timesSeen: 1,
|
||||
updatedAt: DateTime(2026, 1, 1),
|
||||
supermarket: supermarket,
|
||||
);
|
||||
|
||||
void main() {
|
||||
ensureTestSqlite();
|
||||
|
||||
group('nameConflictGroups', () {
|
||||
test('groups products that differ only by case at the same store', () {
|
||||
final groups = nameConflictGroups([
|
||||
_product(1, 'Broccoli', supermarket: 'Jumbo'),
|
||||
_product(2, 'BROCCOLI', supermarket: 'Jumbo'),
|
||||
_product(3, 'Milk', supermarket: 'Jumbo'),
|
||||
]);
|
||||
|
||||
expect(groups, hasLength(1));
|
||||
expect(groups.single.map((product) => product.id), [1, 2]);
|
||||
});
|
||||
|
||||
test('ignores same name at different stores', () {
|
||||
final groups = nameConflictGroups([
|
||||
_product(1, 'Broccoli', supermarket: 'Jumbo'),
|
||||
_product(2, 'BROCCOLI', supermarket: 'Lidl'),
|
||||
]);
|
||||
|
||||
expect(groups, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('buildNameConflictGroups', () {
|
||||
test('finds conflicts from trip lines linked to different products', () {
|
||||
final groups = buildNameConflictGroups(
|
||||
products: [
|
||||
_product(1, 'Broccoli', supermarket: 'Jumbo'),
|
||||
_product(2, 'BROCCOLI', supermarket: 'Jumbo'),
|
||||
],
|
||||
shopLines: const [
|
||||
(productId: 1, name: 'Broccoli', supermarket: 'Jumbo'),
|
||||
(productId: 2, name: 'BROCCOLI', supermarket: 'Jumbo'),
|
||||
],
|
||||
);
|
||||
|
||||
expect(groups, hasLength(1));
|
||||
expect(groups.single.products.map((product) => product.id), [1, 2]);
|
||||
expect(groups.single.supermarket, 'Jumbo');
|
||||
});
|
||||
});
|
||||
|
||||
group('findSpellingVariants', () {
|
||||
test('finds multiple receipt spellings for one product at one store', () {
|
||||
final variants = findSpellingVariants(
|
||||
products: [_product(1, 'Broccoli', supermarket: 'Jumbo')],
|
||||
shopLines: const [
|
||||
(productId: 1, name: 'Broccoli', supermarket: 'Jumbo'),
|
||||
(productId: 1, name: 'BROCCOLI', supermarket: 'Jumbo'),
|
||||
],
|
||||
);
|
||||
|
||||
expect(variants, hasLength(1));
|
||||
expect(variants.single.product.id, 1);
|
||||
expect(variants.single.supermarket, 'Jumbo');
|
||||
expect(variants.single.variants, ['Broccoli', 'BROCCOLI']);
|
||||
});
|
||||
|
||||
test('ignores different spellings at different stores', () {
|
||||
final variants = findSpellingVariants(
|
||||
products: [_product(1, 'Broccoli', supermarket: 'Jumbo')],
|
||||
shopLines: const [
|
||||
(productId: 1, name: 'Broccoli', supermarket: 'Jumbo'),
|
||||
(productId: 1, name: 'BROCCOLI', supermarket: 'Lidl'),
|
||||
],
|
||||
);
|
||||
|
||||
expect(variants, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
test('same name at different supermarkets creates separate products', () async {
|
||||
final repository = memoryRepository();
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 1),
|
||||
items: [LineItem(id: '1', name: 'Milk', price: 1.5)],
|
||||
);
|
||||
await repository.saveShop(
|
||||
supermarket: 'Lidl',
|
||||
shoppedAt: DateTime(2026, 8, 2),
|
||||
items: [LineItem(id: '2', name: 'Milk', price: 1.2)],
|
||||
);
|
||||
|
||||
final products = await repository.getAll();
|
||||
expect(products, hasLength(2));
|
||||
expect(products.map((p) => p.supermarket).toSet(), {'Jumbo', 'Lidl'});
|
||||
expect(await repository.getProductNameIssues(), isEmpty);
|
||||
});
|
||||
|
||||
test('getNameConflictGroups finds duplicates in the database', () async {
|
||||
final repository = memoryRepository();
|
||||
await seedCaseConflictCatalog(repository);
|
||||
|
||||
final groups = await repository.getNameConflictGroups();
|
||||
expect(groups, hasLength(1));
|
||||
expect(groups.single.map((product) => product.name).toSet(), {
|
||||
'Broccoli',
|
||||
'BROCCOLI',
|
||||
});
|
||||
});
|
||||
|
||||
test('getProductNameIssues finds receipt spelling variants', () async {
|
||||
final repository = memoryRepository();
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 1),
|
||||
items: [LineItem(id: '1', name: 'Broccoli', price: 1.5)],
|
||||
);
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 2),
|
||||
items: [LineItem(id: '2', name: 'BROCCOLI', price: 1.8)],
|
||||
);
|
||||
|
||||
final issues = await repository.getProductNameIssues();
|
||||
expect(issues.mergeGroups, isEmpty);
|
||||
expect(issues.spellingVariants, hasLength(1));
|
||||
expect(issues.spellingVariants.single.supermarket, 'Jumbo');
|
||||
expect(issues.spellingVariants.single.variants, ['Broccoli', 'BROCCOLI']);
|
||||
});
|
||||
|
||||
test('dismissNameIssue hides a spelling variant', () async {
|
||||
final repository = memoryRepository();
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 1),
|
||||
items: [LineItem(id: '1', name: 'Broccoli', price: 1.5)],
|
||||
);
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 2),
|
||||
items: [LineItem(id: '2', name: 'BROCCOLI', price: 1.8)],
|
||||
);
|
||||
|
||||
final issue =
|
||||
(await repository.getProductNameIssues()).spellingVariants.single;
|
||||
await repository.dismissNameIssue(issue.key);
|
||||
|
||||
expect(await repository.getProductNameIssues(), isEmpty);
|
||||
});
|
||||
|
||||
test('mergeProducts combines purchases onto the kept product', () async {
|
||||
final repository = memoryRepository();
|
||||
await seedCaseConflictCatalog(repository);
|
||||
|
||||
await repository.mergeProducts(keepId: 1, sourceIds: [2]);
|
||||
|
||||
final after = await repository.getAll();
|
||||
expect(after, hasLength(1));
|
||||
expect(after.single.name, 'Broccoli');
|
||||
expect(after.single.timesSeen, 2);
|
||||
expect(await repository.getPurchases(1), hasLength(2));
|
||||
});
|
||||
|
||||
test('unifyProductSpelling updates catalog and receipt lines', () async {
|
||||
final repository = memoryRepository();
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 1),
|
||||
items: [LineItem(id: '1', name: 'Broccoli', price: 1.5)],
|
||||
);
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 2),
|
||||
items: [LineItem(id: '2', name: 'BROCCOLI', price: 1.8)],
|
||||
);
|
||||
final product = (await repository.getAll()).single;
|
||||
|
||||
await repository.unifyProductSpelling(
|
||||
productId: product.id,
|
||||
name: 'BROCCOLI',
|
||||
supermarket: 'Jumbo',
|
||||
);
|
||||
|
||||
final updated = (await repository.getProduct(product.id))!;
|
||||
expect(updated.name, 'BROCCOLI');
|
||||
expect((await repository.getProductNameIssues()).isEmpty, isTrue);
|
||||
});
|
||||
}
|
||||
@@ -56,6 +56,7 @@ Totaal korting: -2,00
|
||||
expect(result.items.map((item) => item.name), ['AARDBEIEN']);
|
||||
expect(result.items.single.price, 5.98);
|
||||
expect(result.items.single.discount, -2.00);
|
||||
expect(result.items.single.originalPrice, 7.98);
|
||||
expect(result.validationPassed, isTrue);
|
||||
});
|
||||
|
||||
|
||||
@@ -39,3 +39,70 @@ Future<void> pumpUntilFound(
|
||||
}
|
||||
throw TestFailure('Timed out waiting for $finder');
|
||||
}
|
||||
|
||||
const _seedTs = '2026-08-01T00:00:00.000';
|
||||
|
||||
Future<void> seedCaseConflictCatalog(ProductRepository repository) async {
|
||||
await repository.replaceAllData(
|
||||
darkMode: false,
|
||||
supermarkets: [
|
||||
{'id': 1, 'name': 'Jumbo', 'color': 0xFFEEC21B, 'sort_order': 0},
|
||||
],
|
||||
products: [
|
||||
{
|
||||
'id': 1,
|
||||
'name': 'Broccoli',
|
||||
'normalized_name': 'BROCCOLI_A',
|
||||
'last_price': 1.5,
|
||||
'times_seen': 1,
|
||||
'favourite': 0,
|
||||
'supermarket': 'Jumbo',
|
||||
'created_at': _seedTs,
|
||||
'updated_at': _seedTs,
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'name': 'BROCCOLI',
|
||||
'normalized_name': 'BROCCOLI_B',
|
||||
'last_price': 1.8,
|
||||
'times_seen': 1,
|
||||
'favourite': 0,
|
||||
'supermarket': 'Jumbo',
|
||||
'created_at': _seedTs,
|
||||
'updated_at': _seedTs,
|
||||
},
|
||||
],
|
||||
shops: [
|
||||
{
|
||||
'id': 1,
|
||||
'supermarket': 'Jumbo',
|
||||
'shopped_at': '2026-08-01T00:00:00.000',
|
||||
'total': 1.5,
|
||||
'created_at': _seedTs,
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'supermarket': 'Jumbo',
|
||||
'shopped_at': '2026-08-02T00:00:00.000',
|
||||
'total': 1.8,
|
||||
'created_at': _seedTs,
|
||||
},
|
||||
],
|
||||
shopItems: [
|
||||
{
|
||||
'id': 1,
|
||||
'shop_id': 1,
|
||||
'product_id': 1,
|
||||
'name': 'Broccoli',
|
||||
'price': 1.5,
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'shop_id': 2,
|
||||
'product_id': 2,
|
||||
'name': 'BROCCOLI',
|
||||
'price': 1.8,
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -232,4 +232,115 @@ void main() {
|
||||
|
||||
expect(find.text('Jumbo'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('review screen strikes through the pre-discount price', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ReviewScreen(
|
||||
items: [
|
||||
LineItem(id: '1', name: 'Berries', price: 6.85, discount: -1.15),
|
||||
],
|
||||
rawText: 'Berries 8.00\nKorting -1.15',
|
||||
repository: memoryRepository(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('€ 8.00'), findsOneWidget);
|
||||
expect(find.text('€ 6.85'), findsOneWidget);
|
||||
final original = tester.widget<Text>(find.text('€ 8.00'));
|
||||
expect(original.style?.decoration, TextDecoration.lineThrough);
|
||||
});
|
||||
|
||||
testWidgets('product name is saved when leaving the screen', (tester) async {
|
||||
final repository = memoryRepository();
|
||||
await tester.runAsync(() async {
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime.now(),
|
||||
items: [LineItem(id: '1', name: 'Milk', price: 1.5)],
|
||||
);
|
||||
});
|
||||
|
||||
await tester.pumpWidget(ReceipityApp(repository: repository));
|
||||
await pumpUntilFound(tester, find.text('Overview'));
|
||||
await tester.tap(find.text('Products').last);
|
||||
await pumpUntilFound(tester, find.text('Milk'));
|
||||
await tester.tap(find.text('Milk'));
|
||||
await pumpUntilFound(tester, find.text('Name'));
|
||||
|
||||
await tester.enterText(find.byType(TextField).first, 'Oat milk');
|
||||
await tester.tap(find.byTooltip('Back'));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 150)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
expect(find.text('Oat milk'), findsOneWidget);
|
||||
expect(find.text('Milk'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('products screen marks case-only duplicates', (tester) async {
|
||||
final repository = memoryRepository();
|
||||
await tester.runAsync(() => seedCaseConflictCatalog(repository));
|
||||
|
||||
await tester.pumpWidget(ReceipityApp(repository: repository));
|
||||
await pumpUntilFound(tester, find.text('Overview'));
|
||||
await tester.tap(find.text('Products').last);
|
||||
await pumpUntilFound(tester, find.text('1 duplicate product'));
|
||||
|
||||
expect(find.text('Broccoli'), findsOneWidget);
|
||||
expect(find.text('BROCCOLI'), findsOneWidget);
|
||||
expect(find.byTooltip('Resolve name issues'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('products screen marks receipt spelling variants', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = memoryRepository();
|
||||
await tester.runAsync(() async {
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 1),
|
||||
items: [LineItem(id: '1', name: 'Broccoli', price: 1.5)],
|
||||
);
|
||||
await repository.saveShop(
|
||||
supermarket: 'Jumbo',
|
||||
shoppedAt: DateTime(2026, 8, 2),
|
||||
items: [LineItem(id: '2', name: 'BROCCOLI', price: 1.8)],
|
||||
);
|
||||
});
|
||||
|
||||
await tester.pumpWidget(ReceipityApp(repository: repository));
|
||||
await pumpUntilFound(tester, find.text('Overview'));
|
||||
await tester.tap(find.text('Products').last);
|
||||
await pumpUntilFound(tester, find.text('1 product, multiple spellings'));
|
||||
|
||||
expect(find.text('Broccoli'), findsOneWidget);
|
||||
expect(find.byTooltip('Resolve name issues'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('resolve name issues sheet shows merge and leave as is', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = memoryRepository();
|
||||
await tester.runAsync(() => seedCaseConflictCatalog(repository));
|
||||
|
||||
await tester.pumpWidget(ReceipityApp(repository: repository));
|
||||
await pumpUntilFound(tester, find.text('Overview'));
|
||||
await tester.tap(find.text('Products').last);
|
||||
await pumpUntilFound(tester, find.text('1 duplicate product'));
|
||||
|
||||
await tester.tap(find.text('1 duplicate product'));
|
||||
await pumpUntilFound(tester, find.text('Resolve name issues'));
|
||||
|
||||
expect(find.text('Resolve name issues'), findsOneWidget);
|
||||
expect(find.text('Separate products to merge'), findsOneWidget);
|
||||
expect(find.text('Broccoli'), findsWidgets);
|
||||
expect(find.text('BROCCOLI'), findsWidgets);
|
||||
expect(find.text('Merge'), findsOneWidget);
|
||||
expect(find.text('Leave as is'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user