97 lines
2.3 KiB
Dart
97 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:groci/models/shop.dart';
|
|
import 'package:groci/utils/shop_calendar.dart';
|
|
import 'package:groci/utils/shop_log_filter.dart';
|
|
|
|
Shop _shop({
|
|
required int id,
|
|
required DateTime at,
|
|
String supermarket = 'Jumbo',
|
|
String? name,
|
|
List<String> tags = const [],
|
|
}) {
|
|
return Shop(
|
|
id: id,
|
|
supermarket: supermarket,
|
|
name: name,
|
|
shoppedAt: at,
|
|
total: 10,
|
|
itemCount: 1,
|
|
tags: tags,
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
group('monthGrid', () {
|
|
test('pads August 2026 from Saturday with Monday-first weeks', () {
|
|
final cells = monthGrid(DateTime(2026, 8));
|
|
expect(cells.length % 7, 0);
|
|
expect(cells[0], isNull);
|
|
expect(cells[1], isNull);
|
|
expect(cells[2], isNull);
|
|
expect(cells[3], isNull);
|
|
expect(cells[4], isNull);
|
|
expect(cells[5], DateTime(2026, 8, 1));
|
|
expect(cells[35], DateTime(2026, 8, 31));
|
|
expect(cells.last, isNull);
|
|
});
|
|
});
|
|
|
|
test('tripCountsByDay groups multiple trips on the same day', () {
|
|
final counts = tripCountsByDay([
|
|
DateTime(2026, 8, 12, 9),
|
|
DateTime(2026, 8, 12, 18),
|
|
DateTime(2026, 8, 13),
|
|
]);
|
|
expect(counts[DateTime(2026, 8, 12)], 2);
|
|
expect(counts[DateTime(2026, 8, 13)], 1);
|
|
expect(heatmapLevel(0), 0);
|
|
expect(heatmapLevel(1), 1);
|
|
expect(heatmapLevel(4), 4);
|
|
expect(heatmapLevel(9), 4);
|
|
});
|
|
|
|
group('filterShops', () {
|
|
final shops = [
|
|
_shop(id: 1, at: DateTime(2026, 8, 12), tags: const ['weekly']),
|
|
_shop(
|
|
id: 2,
|
|
at: DateTime(2026, 8, 13),
|
|
name: 'Work lunch',
|
|
tags: const ['work'],
|
|
),
|
|
];
|
|
const names = {
|
|
1: ['Milk', 'Bread'],
|
|
2: ['Coffee'],
|
|
};
|
|
|
|
test('filters by product name', () {
|
|
final found = filterShops(
|
|
shops: shops,
|
|
productNames: names,
|
|
query: 'milk',
|
|
);
|
|
expect(found.map((shop) => shop.id), [1]);
|
|
});
|
|
|
|
test('filters by selected day', () {
|
|
final found = filterShops(
|
|
shops: shops,
|
|
productNames: names,
|
|
selectedDay: DateTime(2026, 8, 13),
|
|
);
|
|
expect(found.single.id, 2);
|
|
});
|
|
|
|
test('filters by tag', () {
|
|
final found = filterShops(
|
|
shops: shops,
|
|
productNames: names,
|
|
tag: 'weekly',
|
|
);
|
|
expect(found.single.id, 1);
|
|
});
|
|
});
|
|
}
|