A whole bunch of changes

This commit is contained in:
Courtney Arnold 2026-08-15 17:52:25 -05:00
parent 901ec678a3
commit 956231048e
122 changed files with 5442 additions and 914 deletions

View file

@ -181,4 +181,101 @@ void main() {
expect(report.totalGallons, 18);
expect(report.totalCost, 63);
});
test('a row\'s entries are sorted oldest-first, regardless of insertion order', () {
final report = buildFuelReport(
vehicles: [truck],
fuelEntries: [
entry(id: 'newest', vehicleId: 'v1', date: DateTime(2026, 3, 20), receiptImagePath: '/c.jpg'),
entry(id: 'oldest', vehicleId: 'v1', date: DateTime(2026, 3, 5), receiptImagePath: '/a.jpg'),
entry(id: 'middle', vehicleId: 'v1', date: DateTime(2026, 3, 12), receiptImagePath: '/b.jpg'),
],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 3, 31),
);
expect(report.rows.single.entries.map((e) => e.id), ['oldest', 'middle', 'newest']);
});
test('fillCount and avgPricePerGallon are derived from the totals across all rows', () {
final report = buildFuelReport(
vehicles: [truck, car],
fuelEntries: [
entry(id: 'e1', vehicleId: 'v1', date: DateTime(2026, 3, 5), gallons: 10, totalCost: 40, receiptImagePath: '/a.jpg'),
entry(id: 'e2', vehicleId: 'v2', date: DateTime(2026, 3, 6), gallons: 10, totalCost: 30, receiptImagePath: '/b.jpg'),
],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 3, 31),
);
expect(report.fillCount, 2);
expect(report.avgPricePerGallon, 3.5); // $70 / 20 gal
});
test('avgPricePerGallon is 0, not NaN/infinity, for an empty report', () {
final report = buildFuelReport(
vehicles: [truck],
fuelEntries: const [],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 3, 31),
);
expect(report.avgPricePerGallon, 0);
});
test('allEntries pairs each entry with its vehicle and sorts oldest-first across vehicles', () {
final report = buildFuelReport(
vehicles: [truck, car],
fuelEntries: [
entry(id: 'truck-later', vehicleId: 'v1', date: DateTime(2026, 3, 20), receiptImagePath: '/a.jpg'),
entry(id: 'car-earlier', vehicleId: 'v2', date: DateTime(2026, 3, 5), receiptImagePath: '/b.jpg'),
],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 3, 31),
);
final all = report.allEntries;
expect(all.map((re) => re.entry.id), ['car-earlier', 'truck-later']);
expect(all[0].vehicle.id, 'v2');
expect(all[1].vehicle.id, 'v1');
});
test('monthlyTotals buckets entries by calendar month across vehicles, oldest month first', () {
final report = buildFuelReport(
vehicles: [truck, car],
fuelEntries: [
entry(id: 'mar-1', vehicleId: 'v1', date: DateTime(2026, 3, 5), gallons: 10, totalCost: 35, receiptImagePath: '/a.jpg'),
entry(id: 'mar-2', vehicleId: 'v2', date: DateTime(2026, 3, 20), gallons: 10, totalCost: 35, receiptImagePath: '/b.jpg'),
entry(id: 'apr-1', vehicleId: 'v1', date: DateTime(2026, 4, 2), gallons: 10, totalCost: 40, receiptImagePath: '/c.jpg'),
],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 4, 30),
);
final months = report.monthlyTotals;
expect(months, hasLength(2));
expect(months[0].month, DateTime(2026, 3));
expect(months[0].fillCount, 2);
expect(months[0].totalGallons, 20);
expect(months[0].totalCost, 70);
expect(months[0].avgPricePerGallon, 3.5);
expect(months[1].month, DateTime(2026, 4));
expect(months[1].fillCount, 1);
});
test('entriesByMonth is the grouping monthlyTotals is built from', () {
final report = buildFuelReport(
vehicles: [truck],
fuelEntries: [
entry(id: 'mar-1', vehicleId: 'v1', date: DateTime(2026, 3, 5), receiptImagePath: '/a.jpg'),
entry(id: 'apr-1', vehicleId: 'v1', date: DateTime(2026, 4, 2), receiptImagePath: '/b.jpg'),
],
startDate: DateTime(2026, 3, 1),
endDate: DateTime(2026, 4, 30),
);
final byMonth = report.entriesByMonth;
expect(byMonth[DateTime(2026, 3)]!.map((re) => re.entry.id), ['mar-1']);
expect(byMonth[DateTime(2026, 4)]!.map((re) => re.entry.id), ['apr-1']);
});
}