feat: add more detailed history and group per day
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user