36 lines
1.0 KiB
Dart
36 lines
1.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kooltab2/models/closed_tab_item.dart';
|
|
import 'package:kooltab2/utils/history_grouping.dart';
|
|
|
|
void main() {
|
|
test('groups items by purchase day with newest day first', () {
|
|
final items = [
|
|
_closedItem('older', DateTime(2026, 8, 1, 22)),
|
|
_closedItem('newer-b', DateTime(2026, 8, 3, 18)),
|
|
_closedItem('newer-a', DateTime(2026, 8, 3, 10)),
|
|
];
|
|
|
|
final groups = groupClosedTabItemsByDay(
|
|
items,
|
|
fallbackDate: DateTime(2026, 8, 4),
|
|
);
|
|
|
|
expect(groups, hasLength(2));
|
|
expect(groups.first.day, DateTime(2026, 8, 3));
|
|
expect(groups.first.items.map((item) => item.id), ['newer-b', 'newer-a']);
|
|
expect(groups.last.day, DateTime(2026, 8, 1));
|
|
});
|
|
}
|
|
|
|
ClosedTabItem _closedItem(String id, DateTime purchasedAt) {
|
|
return ClosedTabItem(
|
|
id: id,
|
|
closedTabId: 'closed-tab',
|
|
productId: 'product-$id',
|
|
productName: id,
|
|
quantity: 1,
|
|
unitPriceInCents: 100,
|
|
purchasedAt: purchasedAt,
|
|
);
|
|
}
|