A whole lot of stuff

This commit is contained in:
Courtney Arnold 2026-08-18 11:04:58 -05:00
parent faf319322a
commit ad850d2be6
50 changed files with 3013 additions and 213 deletions

View file

@ -23,6 +23,8 @@ import 'package:fuel_tax_tracker/services/database_service.dart';
/// other upsert in this app (see [DatabaseService.saveVehicle]).
void main() {
final vehicle = Vehicle(id: 'v1', vin: '1FMPU18L1TLB51349', updatedAt: DateTime.utc(2026, 1, 1));
final otherVehicle =
Vehicle(id: 'v2', vin: '1HGCM82633A004352', nickname: 'Second Car', updatedAt: DateTime.utc(2026, 1, 1));
final entry = FuelEntry(
id: 'e1',
vehicleId: 'v1',
@ -83,6 +85,25 @@ void main() {
final rawRow = (await database.rawDb.query('fuel_entries', where: 'id = ?', whereArgs: ['e1'])).single;
expect(rawRow['dirty'], 1);
});
test('saving again with a different vehicleId moves the entry to that vehicle', () async {
await database.saveVehicle(vehicle);
await database.saveVehicle(otherVehicle);
await database.saveFuelEntry(entry);
await database.saveFuelEntry(FuelEntry(
id: entry.id,
vehicleId: otherVehicle.id,
date: entry.date,
gallons: entry.gallons,
pricePerGallon: entry.pricePerGallon,
totalCost: entry.totalCost,
updatedAt: DateTime.utc(2026, 3, 6),
));
final saved = (await database.getFuelEntries()).single;
expect(saved.vehicleId, otherVehicle.id);
});
});
group('EditFuelEntryScreen', () {
@ -142,6 +163,50 @@ void main() {
expect(find.text('Required'), findsOneWidget);
expect(find.byType(EditFuelEntryScreen), findsOneWidget, reason: 'did not navigate away');
});
testWidgets('shows a vehicle picker pre-selected to the entry\'s current vehicle',
(tester) async {
final appState = AppState()
..isLoading = false
..vehicles = [vehicle, otherVehicle]
..fuelEntries = [entry];
await tester.pumpWidget(
ChangeNotifierProvider.value(
value: appState,
child: MaterialApp(home: EditFuelEntryScreen(entry: entry)),
),
);
expect(find.widgetWithText(DropdownButtonFormField<String>, vehicle.displayLabel),
findsOneWidget);
});
testWidgets('picking a different vehicle updates the selection shown', (tester) async {
final appState = AppState()
..isLoading = false
..vehicles = [vehicle, otherVehicle]
..fuelEntries = [entry];
await tester.pumpWidget(
ChangeNotifierProvider.value(
value: appState,
child: MaterialApp(home: EditFuelEntryScreen(entry: entry)),
),
);
await tester.tap(find.byType(DropdownButtonFormField<String>));
await tester.pumpAndSettle();
// Two matches once the menu is open: the closed field's current
// selection, and the same label repeated as a menu item.
await tester.tap(find.text(otherVehicle.displayLabel).last);
await tester.pumpAndSettle();
expect(find.widgetWithText(DropdownButtonFormField<String>, otherVehicle.displayLabel),
findsOneWidget);
expect(find.widgetWithText(DropdownButtonFormField<String>, vehicle.displayLabel),
findsNothing);
});
});
}