V3-02 + V3-03: settings screen, and metric/imperial units
Built together because V3-02's settings screen needed something real for V3-03's units to control -- executed in reverse of the ticket numbering, but both tickets are independently complete. V3-03: UnitSystem (metric/imperial) lives in domain/models.dart alongside Activity, defaulting from Platform.localeName on first launch. Storage stays SI everywhere -- conversion happens only in ui/format.dart, at the last possible moment, which is now documented as the file's central invariant. Threaded through all three screens plus the speed histogram's bucket labels, which relabel for display without changing how speedHistogram itself bins. Export was deliberately left untouched: gpx()/geoJson() take no UnitSystem parameter at all, a stronger guarantee than validating one would be. V3-02: SettingsScreen reachable from the record screen. Map render toggle (nothing previously exposed mapEnabledProvider to the user, despite it existing since T15 -- there was nothing to "move off trip detail" as drafted), unit selector, upload endpoint with http(s) validation, a copyable device id, and a licences page via Flutter's built-in showLicensePage. Skipped package_info_plus (static version string instead) and a privacy-policy link (none published yet) as disproportionate to an S-sized ticket. Neither ticket needed the ConfigNotifier the implementation notes proposed: unitSystemProvider reuses the exact StateProvider-seeded-from-Config pattern mapEnabledProvider already established, since Config mutates its own backing SharedPreferences in place and re-assigning the same instance would never notify a watcher anyway. A real locale-dependent flake was caught, not just anticipated: a test asserting a fresh Config defaults to metric failed, because this machine's own locale resolves to a region in the imperial set. Fixed by seeding an explicit value before asserting, and config_test.dart's locale test was written from the start to only prove the fallback path doesn't throw, not to assert which value it returns. 221 tests (211 -> 221): 13 format_test, 9 config_test, 9 settings_screen_test, 1 confirming the record screen's settings button is genuinely wired. Analyze clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:rippr/src/domain/models.dart';
|
||||
import 'package:rippr/src/ui/activity_display.dart';
|
||||
import 'package:rippr/src/recording/location_source.dart';
|
||||
import 'package:rippr/src/ui/detail/trip_detail_screen.dart';
|
||||
import 'package:rippr/src/ui/format.dart';
|
||||
import 'package:rippr/src/ui/record/record_screen.dart';
|
||||
import 'package:rippr/src/ui/theme.dart';
|
||||
import 'package:rippr/src/ui/trips/trips_screen.dart';
|
||||
@@ -67,13 +68,18 @@ void main() {
|
||||
///
|
||||
/// The theme is deliberately included: the black-on-black bug was invisible to logic
|
||||
/// tests and only a rendered widget can catch its equivalent.
|
||||
Widget host(Widget child, {bool map = true}) => ProviderScope(
|
||||
Widget host(
|
||||
Widget child, {
|
||||
bool map = true,
|
||||
UnitSystem units = UnitSystem.metric,
|
||||
}) => ProviderScope(
|
||||
overrides: [
|
||||
databaseProvider.overrideWithValue(db),
|
||||
locationSourceProvider.overrideWithValue(source),
|
||||
// The map is off by default in tests that are not about the map: it fetches
|
||||
// tiles, which a widget test cannot serve, and it changes scroll geometry.
|
||||
mapEnabledProvider.overrideWith((ref) => map),
|
||||
unitSystemProvider.overrideWith((ref) => units),
|
||||
],
|
||||
child: MaterialApp(theme: ripprTheme(), home: child),
|
||||
);
|
||||
@@ -187,6 +193,21 @@ void main() {
|
||||
expect(colour, isNot(ripprBackground));
|
||||
expect(colour, isNot(Colors.black));
|
||||
});
|
||||
|
||||
screenTest('a settings entry point exists and is wired (V3-02)', (tester) async {
|
||||
var opened = false;
|
||||
await tester.pumpWidget(
|
||||
host(RecordScreen(onOpenSettings: () => opened = true)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('open-settings')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('open-settings')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, isTrue,
|
||||
reason: 'the button must actually invoke the callback that navigates');
|
||||
});
|
||||
});
|
||||
|
||||
group('trips list', () {
|
||||
@@ -380,5 +401,43 @@ void main() {
|
||||
expect(find.text(activityLabel(Activity.walking)), findsOneWidget);
|
||||
expect((await repo.tripById(id))!.activity, Activity.walking);
|
||||
});
|
||||
|
||||
screenTest('switching units changes the rendered distance label (V3-03)',
|
||||
(tester) async {
|
||||
final id = await seedCompletedTrip(
|
||||
startedAt: 1000, endedAt: 5000, points: 11);
|
||||
final trip = (await repo.tripById(id))!;
|
||||
|
||||
await tester.pumpWidget(
|
||||
host(TripDetailScreen(tripId: id), map: false),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final (metricValue, metricUnit) = formatDistanceParts(trip.distanceM);
|
||||
expect(find.text(metricValue), findsWidgets);
|
||||
// BigStat renders its unit as " $unit", with a leading space, next to the figure.
|
||||
expect(find.text(' $metricUnit'), findsOneWidget);
|
||||
|
||||
// A full unmount first: Riverpod's ProviderScope does not reliably re-seed a
|
||||
// StateProvider's initial value on an override change alone if the same
|
||||
// container survives the rebuild, so pumping a second host() directly on top of
|
||||
// the first would silently keep reading the metric container.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
host(TripDetailScreen(tripId: id), map: false, units: UnitSystem.imperial),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final (imperialValue, imperialUnit) = formatDistanceParts(
|
||||
trip.distanceM,
|
||||
unit: UnitSystem.imperial,
|
||||
);
|
||||
expect(find.text(' $imperialUnit'), findsOneWidget);
|
||||
expect(imperialUnit, isNot(metricUnit));
|
||||
// A short 11-point ride at ~11 m hops is short enough that the two rounded values
|
||||
// could coincidentally match as text; the unit label changing is what this test is
|
||||
// really proving, but assert the value differs too when it is safe to.
|
||||
if (metricValue != imperialValue) {
|
||||
expect(find.text(imperialValue), findsWidgets);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user