Files
rippr/test/settings_screen_test.dart
uhryniuk fa6b1b8ef2 UI-05: rebuild Record screen as the Map HUD (design north star)
Replaces the scrolling stats-card layout with the full-bleed Map HUD:
UI-04's draggable/resizable HUD widgets float over UI-01's shared
background map (full opacity on this tab), and the old Pause/Stop/Resume/
Discard buttons become full-bleed, icon-only segments matching the
mockup's tertiary-container/error-container colors exactly. The idle
state keeps its prior compact layout deliberately -- HUD widgets only
appear once a ride exists, preserving the existing "a resting screen
must not look like a ride going nowhere" guarantee rather than
reinterpreting it.

State-machine logic (ticker, wakelock, speed subscription, error
handling) is untouched; every pre-existing record-screen test passed
unchanged against the rebuilt screen. Added tests that actually tap
Start/Pause/Stop and verify engine state changes, confirm HUD widgets
render over the map rather than replacing it, and verify the
mounted-mode speed digit's real contrast ratio against GlassPanel's
translucent surface specifically (the ticket's own named risk).

Corrects a UI-04 mistake found while implementing this ticket: the HUD's
default four metrics were ordered Speed/Distance/Elapsed/Max Speed, a
guess made before reading the actual Map HUD mockup HTML closely. The
real fixed row is Speed/Avg Speed/Dist/Time -- reordered HudMetric to
match and updated every test that asserted the old order.

Adds PulsingLocationMarker (UI-03) to RideMap's live usage via a new
showLocationMarker flag, and explicit tertiaryContainer/errorContainer
tokens to ripprColors so the control bar matches the design system's
literal values rather than an auto-derived tonal palette.

Verified end-to-end on a real emulator: Start, Pause, Resume, and Stop
all correctly drive the trip state machine with the full live map behind
everything. A lengthy false alarm during this verification (taps
appearing to do nothing) turned out to be a screenshot-scale
mis-measurement on the verification side, not an app defect -- resolved
by sampling pixel colors directly from the raw screenshot to find the
control bar's true on-screen position.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Xki7YAcc2TiN2PRZJ2tXr
2026-08-24 08:22:51 -05:00

253 lines
9.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rippr/src/app/providers.dart';
import 'package:rippr/src/config/config.dart';
import 'package:rippr/src/domain/models.dart';
import 'package:rippr/src/hud/hud_metric.dart';
import 'package:rippr/src/ui/settings/settings_screen.dart';
import 'package:rippr/src/ui/theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// V3-02: every `Config` value must be viewable and editable here, and every write must
/// actually reach `Config` -- not just update local widget state that looks right until
/// the next app launch.
void main() {
late Config config;
setUp(() async {
SharedPreferences.setMockInitialValues({});
config = await Config.load();
});
Widget host() => ProviderScope(
overrides: [configProvider.overrideWith((ref) => config)],
child: MaterialApp(theme: ripprTheme(), home: const SettingsScreen()),
);
testWidgets('the map switch reflects and writes through to Config', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
final initial = tester
.widget<SwitchListTile>(find.byKey(const Key('map-enabled-switch')))
.value;
expect(initial, isTrue, reason: 'Config.mapEnabled defaults to true');
await tester.tap(find.byKey(const Key('map-enabled-switch')));
await tester.pumpAndSettle();
expect(config.mapEnabled, isFalse,
reason: 'the switch must write through to Config, not just local state');
});
testWidgets('changing the map switch is visible to other providers immediately',
(tester) async {
// V3-02's acceptance criterion: "changing the map toggle takes effect without an
// app restart". mapEnabledProvider is what trip detail actually reads.
await tester.pumpWidget(host());
await tester.pumpAndSettle();
final container = ProviderScope.containerOf(
tester.element(find.byType(SettingsScreen)),
);
expect(container.read(mapEnabledProvider), isTrue);
await tester.tap(find.byKey(const Key('map-enabled-switch')));
await tester.pumpAndSettle();
expect(container.read(mapEnabledProvider), isFalse);
});
testWidgets('the unit selector writes through to Config', (tester) async {
// The default depends on the test runner's own locale (see config_test.dart), so
// start from an explicit, known value rather than assuming metric.
await config.setUnitSystem(UnitSystem.metric);
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await tester.tap(find.text('Imperial'));
await tester.pumpAndSettle();
expect(config.unitSystem, UnitSystem.imperial);
await tester.tap(find.text('Metric'));
await tester.pumpAndSettle();
expect(config.unitSystem, UnitSystem.metric);
});
testWidgets('the mounted mode switch writes through to Config (V3-05)',
(tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
final initial = tester
.widget<SwitchListTile>(find.byKey(const Key('mounted-mode-switch')))
.value;
expect(initial, isFalse, reason: 'a pocketed ride is still the common case');
await tester.tap(find.byKey(const Key('mounted-mode-switch')));
await tester.pumpAndSettle();
expect(config.mountedMode, isTrue);
});
testWidgets('the crash reporting switch writes through to Config (V3-12)',
(tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
final initial = tester
.widget<SwitchListTile>(find.byKey(const Key('crash-reporting-switch')))
.value;
expect(initial, isFalse, reason: 'off until a privacy policy exists');
await tester.tap(find.byKey(const Key('crash-reporting-switch')));
await tester.pumpAndSettle();
expect(config.crashReportingEnabled, isTrue);
});
/// The Sync section has been pushed below the default test viewport by every section
/// added above it since this suite was first written (V3-05, then V3-12) -- a
/// `ListView` does not mount elements outside its viewport/cache extent, so `find`
/// cannot see them until scrolled into view.
Future<void> scrollToSync(WidgetTester tester) async {
await tester.drag(find.byType(ListView).first, const Offset(0, -600));
await tester.pumpAndSettle();
}
group('upload endpoint', () {
testWidgets('a valid https URL is saved', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollToSync(tester);
await tester.enterText(
find.byKey(const Key('endpoint-field')),
'https://example.test/ingest',
);
await tester.tap(find.byKey(const Key('save-endpoint')));
await tester.pumpAndSettle();
expect(config.uploadEndpoint, 'https://example.test/ingest');
expect(find.text('Endpoint saved'), findsOneWidget);
});
testWidgets('an invalid endpoint is rejected with a readable message, not '
'silently stored', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollToSync(tester);
await tester.enterText(
find.byKey(const Key('endpoint-field')),
'not a url at all',
);
await tester.tap(find.byKey(const Key('save-endpoint')));
await tester.pumpAndSettle();
expect(config.uploadEndpoint, '',
reason: 'garbage input must never reach storage');
expect(find.textContaining('http'), findsWidgets);
});
testWidgets('a non-http scheme is rejected', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollToSync(tester);
await tester.enterText(
find.byKey(const Key('endpoint-field')),
'ftp://example.test/ingest',
);
await tester.tap(find.byKey(const Key('save-endpoint')));
await tester.pumpAndSettle();
expect(config.uploadEndpoint, '');
});
testWidgets('clearing the endpoint is a valid way to disable upload',
(tester) async {
await config.setUploadEndpoint('https://example.test/ingest');
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollToSync(tester);
await tester.enterText(find.byKey(const Key('endpoint-field')), '');
await tester.tap(find.byKey(const Key('save-endpoint')));
await tester.pumpAndSettle();
expect(config.uploadEndpoint, '');
expect(find.text('Upload disabled'), findsOneWidget);
});
});
testWidgets('the device id is shown and a copy control exists', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollToSync(tester);
expect(find.text(config.deviceId), findsOneWidget);
expect(find.byKey(const Key('copy-device-id')), findsOneWidget);
// Tapping must not throw even though no real clipboard exists in the test harness.
await tester.tap(find.byKey(const Key('copy-device-id')));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
group('Live HUD stats (UI-04)', () {
// The section sits at the bottom of a long ListView -- these rows are not built
// until scrolled into view (a plain `ListView(children:)` still lazily materialises
// via a sliver, same as `.builder`), so every test here scrolls first.
Future<void> scrollTo(WidgetTester tester, Key key) => tester.scrollUntilVisible(
find.byKey(key),
200,
scrollable: find.byType(Scrollable).first,
);
testWidgets('a metric switch reflects and writes through to Config', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollTo(tester, const Key('hud-visible-maxSpeed'));
final initial = tester
.widget<SwitchListTile>(find.byKey(const Key('hud-visible-maxSpeed')))
.value;
expect(initial, isFalse, reason: 'metrics beyond the fixed row start hidden');
await tester.tap(find.byKey(const Key('hud-visible-maxSpeed')));
await tester.pumpAndSettle();
expect(config.hudLayout[HudMetric.maxSpeed]!.visible, isTrue,
reason: 'the switch must write through to Config immediately, not wait '
'for a HUD edit-mode session to end');
});
testWidgets('a metric already visible by default shows as on', (tester) async {
await tester.pumpWidget(host());
await tester.pumpAndSettle();
await scrollTo(tester, const Key('hud-visible-speed'));
final speedSwitch = tester
.widget<SwitchListTile>(find.byKey(const Key('hud-visible-speed')))
.value;
expect(speedSwitch, isTrue);
});
});
testWidgets('shows a spinner rather than crashing while Config is still loading',
(tester) async {
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(home: SettingsScreen()),
),
);
await tester.pump();
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(tester.takeException(), isNull);
});
}