53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:groci/models/supermarket.dart';
|
|
import 'package:groci/utils/supermarkets.dart';
|
|
|
|
void main() {
|
|
test('detects Jumbo and Lidl from receipt text', () {
|
|
expect(detectSupermarket('Jumbo\nMelk 1,50'), 'Jumbo');
|
|
expect(
|
|
detectSupermarket('Dekamarkt\nMelk 1,50', names: ['Dekamarkt']),
|
|
'Dekamarkt',
|
|
);
|
|
expect(detectSupermarket('LIDL SUPERMARKT\nBananas 1.20'), 'Lidl');
|
|
});
|
|
|
|
test('detects Albert Heijn aliases', () {
|
|
expect(detectSupermarket('Albert Heijn\nKaas 2,00'), 'Albert Heijn');
|
|
expect(detectSupermarket('AH TO GO\nCoffee 1,80'), 'Albert Heijn');
|
|
expect(detectSupermarket('AH\nMilk 1.00'), 'Albert Heijn');
|
|
});
|
|
|
|
test('returns null when no supermarket is present', () {
|
|
expect(detectSupermarket('Milk 1.50\nBread 2.00'), isNull);
|
|
});
|
|
|
|
test('sortStoresByLastTrip puts the latest trip store first', () {
|
|
const jumbo = Supermarket(id: 1, name: 'Jumbo', colorValue: 1, sortOrder: 0);
|
|
const lidl = Supermarket(id: 2, name: 'Lidl', colorValue: 2, sortOrder: 1);
|
|
const ah = Supermarket(
|
|
id: 3,
|
|
name: 'Albert Heijn',
|
|
colorValue: 3,
|
|
sortOrder: 2,
|
|
);
|
|
|
|
final afterJumbo = sortStoresByLastTrip([jumbo, lidl, ah], ['Jumbo']);
|
|
expect(afterJumbo.map((store) => store.name), [
|
|
'Jumbo',
|
|
'Lidl',
|
|
'Albert Heijn',
|
|
]);
|
|
|
|
final afterAh = sortStoresByLastTrip(
|
|
[jumbo, lidl, ah],
|
|
['Albert Heijn', 'Jumbo'],
|
|
);
|
|
expect(afterAh.map((store) => store.name), [
|
|
'Albert Heijn',
|
|
'Jumbo',
|
|
'Lidl',
|
|
]);
|
|
});
|
|
}
|