Four rounds of web-app features never reached the phone: fuel, maintenance, document and reminder tracking; attachments; the currency setting and the locale split; and technical check history. The README claimed full parity throughout, so the gap was invisible. Catch the phone up, mirroring the web components field for field. Car detail grows the web app's tabs, in its order: technical checks, maintenance, fuel (with the summary panel), documents and reminders, beside the existing service and parts lists. The derived figures are the server's and are rendered as "—" wherever it sent null — a window with a missed fill has no consumption, and a plausible-looking 0.0 there would be a lie. Attachments hang off service records, technical checks, workshop visits, refills, documents and parts on identical terms, so one field and one apply helper cover all six rather than being copied per form. As on the web, the form only collects intent: the file endpoints address a record that must already exist, so a create-with-file is two calls, and a failure on the second reports as an attachment error because the metadata is committed. Two bugs fixed on the way: - _carPayload omitted technicalCheckIntervalDays. The API rewrites every column from the body, so any car edit — including the one-tap odometer update — silently zeroed the car's inspection interval. - main() never called initializeDateFormatting, so month names ignored the chosen language that the new Language picker exists to set. Luxembourgish and Romansh are deliberately left off the language list: intl ships no symbols for them and throws rather than falling back, which would take out every date on screen. The browser has full ICU data and has no such limit, so the web app can offer them. The server only validates a locale's shape, so an unrenderable tag can still arrive from the web; format.dart resolves through a supported-language check and falls back to en-US. Labels for the language/region/currency lists are hand-kept because Dart has no Intl.DisplayNames. The lists mirror validCurrencies in me.go. file_picker is pinned to ^10: v8 compiles against android-34, which no longer builds against the other plugins' compileSdk requirement of 36. Adds the project's first test, covering the parts that fail silently rather than loudly — null derived fields, the badge wording, and the locale guard. The phone was not authorized over ADB, so the UI was not exercised on a device: this is analyzer-, test- and build-clean, and every JSON field name and route was cross-checked against models.go and server.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
148 lines
5.5 KiB
Dart
148 lines
5.5 KiB
Dart
// Parses server-shaped JSON through the models and checks the status/format
|
||
// helpers.
|
||
//
|
||
// These cover the parts where a mistake is invisible until it reaches a user: a
|
||
// derived field the server left out must stay null rather than becoming a
|
||
// plausible-looking zero, the badge wording has to match the web app's, and an
|
||
// unsupported locale (settable from the web, whose lists are wider than the
|
||
// phone's) must not throw out of every date on screen.
|
||
import "package:flutter_test/flutter_test.dart";
|
||
import "package:intl/date_symbol_data_local.dart";
|
||
import "package:carcontrol_phone/format.dart";
|
||
import "package:carcontrol_phone/main.dart";
|
||
import "package:carcontrol_phone/models.dart";
|
||
|
||
void main() {
|
||
setUpAll(() async {
|
||
await initializeDateFormatting();
|
||
appSettings.locale = "pl-PL";
|
||
appSettings.currency = "PLN";
|
||
appSettings.dateFormat = "DMY";
|
||
});
|
||
|
||
test("FuelEntry keeps uncomputed derived fields null, not zero", () {
|
||
final partial = FuelEntry.fromJson({
|
||
"id": "a",
|
||
"car": "c",
|
||
"date": "2026-07-01T00:00:00Z",
|
||
"km": 1000,
|
||
"liters": 20.0,
|
||
"cost": 120.0,
|
||
"fullTank": false,
|
||
"hasFile": false,
|
||
});
|
||
expect(partial.consumptionL100, isNull);
|
||
expect(partial.distanceKm, isNull);
|
||
expect(formatConsumption(partial.consumptionL100), "—");
|
||
|
||
final full = FuelEntry.fromJson({
|
||
"id": "b",
|
||
"car": "c",
|
||
"date": "2026-07-10T00:00:00Z",
|
||
"km": 1500,
|
||
"liters": 35.0,
|
||
"cost": 210.0,
|
||
"fullTank": true,
|
||
"consumptionL100": 6.85,
|
||
"distanceKm": 500,
|
||
"kmPerLiter": 14.6,
|
||
"pricePerLiter": 6.0,
|
||
"fileName": "receipt.pdf",
|
||
"hasFile": true,
|
||
});
|
||
expect(full.consumptionL100, 6.85);
|
||
// 6.85 as a float64 is really 6.8499…, so one-decimal rounding yields 6.8 —
|
||
// the same answer JS toFixed(1) gives the web app.
|
||
expect(formatConsumption(full.consumptionL100), "6.8 L/100km");
|
||
expect(full.hasFile, isTrue);
|
||
expect(full.fileName, "receipt.pdf");
|
||
});
|
||
|
||
test("expiryStatus wording follows the server assessment", () {
|
||
CarDocument doc(String state, int? days) => CarDocument.fromJson({
|
||
"id": "d",
|
||
"car": "c",
|
||
"type": "insurance",
|
||
"title": "OC",
|
||
"expiry": {"state": state, "daysUntilExpiry": days},
|
||
"hasFile": false,
|
||
});
|
||
expect(expiryStatus(doc("expired", -5).expiry).label, "Expired 5d ago");
|
||
expect(expiryStatus(doc("expiring_soon", 0).expiry).label, "Expires today");
|
||
expect(expiryStatus(doc("expiring_soon", 12).expiry).label, "Renew in 12d");
|
||
expect(expiryStatus(doc("valid", 200).expiry).label, "Valid · 200d");
|
||
expect(expiryStatus(doc("no_expiry", null).expiry).label, "No expiry");
|
||
expect(expiryStatus(doc("expired", -5).expiry).key, StatusKey.overdue);
|
||
});
|
||
|
||
test("reminderStatus leads with the driving trigger", () {
|
||
Reminder rem(Map<String, dynamic> extra) =>
|
||
Reminder.fromJson({"id": "r", "car": "c", "title": "t", "type": "service", ...extra});
|
||
|
||
expect(reminderStatus(rem({"status": "done", "done": true})).label, "Done");
|
||
expect(reminderStatus(rem({"status": "no_trigger"})).label, "No trigger");
|
||
expect(
|
||
reminderStatus(rem({"status": "overdue", "daysLeft": -3, "kmLeft": -200})).label,
|
||
"Overdue 3d · 200 km");
|
||
expect(reminderStatus(rem({"status": "due_soon", "daysLeft": 0})).label, "Due in today");
|
||
// The km count is grouped per the chosen locale (pl-PL uses a space), which
|
||
// is the whole point of routing every number through the one helper.
|
||
expect(reminderStatus(rem({"status": "upcoming", "daysLeft": 40, "kmLeft": 5000})).label,
|
||
"Due in 40d · 5 000 km");
|
||
});
|
||
|
||
test("TechnicalCheck: a failed check derives no next date", () {
|
||
final failed = TechnicalCheck.fromJson({
|
||
"id": "t",
|
||
"car": "c",
|
||
"date": "2026-07-01T00:00:00Z",
|
||
"result": "failed",
|
||
"cost": 99.0,
|
||
"expiry": {"state": "no_expiry", "daysUntilExpiry": null},
|
||
"hasFile": false,
|
||
});
|
||
expect(failed.nextCheckDate, isNull);
|
||
expect(failed.passed, isFalse);
|
||
});
|
||
|
||
test("Maintenance derived warranty + total", () {
|
||
final m = MaintenanceEntry.fromJson({
|
||
"id": "m",
|
||
"car": "c",
|
||
"date": "2026-07-01T00:00:00Z",
|
||
"km": 1000,
|
||
"type": "repair",
|
||
"status": "completed",
|
||
"laborCost": 100.0,
|
||
"partsCost": 50.0,
|
||
"totalCost": 150.0,
|
||
"warrantyActive": true,
|
||
"warrantyDaysLeft": 10,
|
||
"hasFile": false,
|
||
});
|
||
expect(m.totalCost, 150.0);
|
||
expect(warrantyStatus(m)!.label, "Warranty ends in 10d");
|
||
expect(warrantyStatus(m)!.key, StatusKey.soon);
|
||
|
||
final noWarranty = MaintenanceEntry.fromJson(
|
||
{"id": "m", "car": "c", "date": "2026-07-01T00:00:00Z", "hasFile": false});
|
||
expect(warrantyStatus(noWarranty), isNull);
|
||
});
|
||
|
||
test("money and numbers follow the chosen locale/currency", () {
|
||
expect(formatMoney(1234.5).contains("zł"), isTrue);
|
||
expect(formatMoney(null), "—");
|
||
// An unsupported language must not throw — it can be set from the web.
|
||
appSettings.locale = "rm-CH";
|
||
expect(() => formatDate(DateTime(2026, 7, 17)), returnsNormally);
|
||
expect(() => formatMoney(10), returnsNormally);
|
||
expect(() => formatKm(15000), returnsNormally);
|
||
appSettings.locale = "pl-PL";
|
||
});
|
||
|
||
test("Car carries the technical check interval", () {
|
||
final car = Car.fromJson({"id": "c", "name": "Yaris", "technicalCheckIntervalDays": 730});
|
||
expect(car.technicalCheckIntervalDays, 730);
|
||
});
|
||
}
|