scan to list working fine

This commit is contained in:
davmar
2026-08-29 11:23:24 +02:00
parent 2d8fc46a30
commit 2a5a922aab
13 changed files with 1233 additions and 8 deletions
+154
View File
@@ -0,0 +1,154 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:receipity/services/receipt_parser.dart';
void main() {
test('parses name and price at the end of a line', () {
final items = ReceiptParser.parse('''
MILK 1.50
BREAD 2.00
TOTAL 3.50
CASH 5.00
CHANGE 1.50
''');
expect(items.map((item) => item.name), ['MILK', 'BREAD']);
expect(items.map((item) => item.price), [1.50, 2.00]);
});
test('uses the next line when quantity and total are split', () {
final items = ReceiptParser.parse('''
EGGS
2 X 1.50 3.00
BUTTER 2.25
SUBTOTAL 5.25
''');
expect(items, hasLength(2));
expect(items[0].name, 'EGGS');
expect(items[0].price, 3.00);
expect(items[0].quantity, 2);
expect(items[0].unitPrice, 1.50);
expect(items[1].name, 'BUTTER');
expect(items[1].price, 2.25);
});
test('computes a total when the quantity line has no line total', () {
final items = ReceiptParser.parse('''
BROODSTICKS OLIJF
4 X 1,25
''');
expect(items, hasLength(1));
expect(items.single.name, 'BROODSTICKS OLIJF');
expect(items.single.price, 5.00);
expect(items.single.quantity, 4);
});
test('drops discount rows and Dutch totals', () {
final items = ReceiptParser.parse('''
AARDBEIEN 7,98
ACTIE AARDBEIEN -2,00
Totaal 82,99
VISA 82,99
Totaal korting: -2,21
''');
expect(items.map((item) => item.name), ['AARDBEIEN']);
expect(items.single.price, 7.98);
});
test('pairs a name column with a price column from OCR', () {
final items = ReceiptParser.parse(_jumboColumnOcr);
expect(items.map((item) => item.name), isNot(contains('OMSCHRIJVING')));
expect(items.map((item) => item.name), isNot(contains('Totaal')));
expect(items.map((item) => item.name), isNot(contains('ACTIE AARDBEIEN')));
expect(items.first.name, 'JUMBO BIO VOLLE MELK');
expect(items.first.price, 2.09);
final eggs = items.firstWhere((item) => item.name.startsWith('BIOLOGISCH EI'));
expect(eggs.quantity, 2);
expect(eggs.price, 5.58);
expect(items.last.name, 'JUMBO PREM LUIER M4');
expect(items.last.price, 6.20);
expect(items, hasLength(26));
});
}
const _jumboColumnOcr = '''
OMSCHRIJVING
JUMBO BIO VOLLE MELK
JUMBO BIO BLOEMKOOLS
JUMBO BIO ROM TOMAAT
JUMBO BIO SIZ LINZEN
JUMBO BIO SIZ CHAMP.
JUMBO FRITO
BIOLOGISCH EI 6 ST
2 X 2,79
KABELJAUW GROENE KR
JUMBO BIO KIPDI JFILE
JUMBO RASP MOZZAREL
JUMBO KAASBL BELEGEN
GALBAN MOZZAREL MAXI
TORTELL DROGE HAM
PATURATIN NATURAL
PAPRIKA ROOD
BIO COTTAGE CHEESE
FP BIO JB PLAK
BIO VASTKOKEND AARD
2 X 1,99
AARDBEIEN
2 X 3,99
ACTIE AARDBEIEN
BROCCOLI
PREI
CITROENEN
KOMKOMMER
2 X 0,95
ACTIE KOMKOMMER
BOL KNOFLOOK
BROODSTICKS OLIJF
4 X 1,25
Krui dernhof 26
1112 PS Diemen
0206904928
www.jumbo. com
JUMBO PREM LUIER M4
Totaal
Betaal d:
VISA
Totaal korting:
BEDRAG IN €
2,09
2,39
2,89
2,89
2,39
0,87
5,58
9,54
4.74
2,49
3,89
2,77
2,49
2,59
1,09
0,99
4,12
3,98
7,98
-2,00
1,24
0,69
2,11
1,90
-0,21
1,79
5,00
6,20
82,99
82,99
-2,21
''';
+30 -1
View File
@@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:receipity/main.dart';
import 'package:receipity/models/line_item.dart';
import 'package:receipity/review_screen.dart';
import 'package:receipity/services/product_repository.dart';
void main() {
testWidgets('scan screen shows capture actions', (tester) async {
await tester.pumpWidget(const ReceipityApp());
await tester.pumpWidget(ReceipityApp());
expect(find.text('Receipity'), findsOneWidget);
expect(find.text('Take photo'), findsOneWidget);
@@ -14,4 +18,29 @@ void main() {
findsOneWidget,
);
});
testWidgets('review screen lists items and can delete one', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: ReviewScreen(
items: [
LineItem(id: '1', name: 'Milk', price: 1.5),
LineItem(id: '2', name: 'Bread', price: 2),
],
rawText: 'Milk 1.50\nBread 2.00',
repository: ProductRepository(),
),
),
);
expect(find.text('Milk'), findsOneWidget);
expect(find.text('Bread'), findsOneWidget);
expect(find.text('Add item'), findsOneWidget);
expect(find.text('Confirm'), findsOneWidget);
await tester.drag(find.text('Milk'), const Offset(-500, 0));
await tester.pumpAndSettle();
expect(find.text('Milk'), findsNothing);
expect(find.text('Bread'), findsOneWidget);
});
}