Adds the full drag/resize/visibility infrastructure for a rider-owned HUD layout: HudMetric (the stable 8-metric set), HudWidgetLayout (fractional x/y/width/height + visible, with clamping to a legibility floor/ceiling and JSON round-trip that degrades to sane defaults rather than crashing), Config.hudLayout persistence, and a HudLayoutController that stays in-memory-authoritative during an edit session and only writes through on persist() -- never per drag frame. DraggableResizableHudWidget and HudEditOverlay assemble the interaction: edit mode is entered by a long-press on empty HUD space (not a specific widget) and exited via Done or a tap on empty space; only while editing does a widget attach any drag/resize gesture at all, so a normal tap can never move one mid-ride by construction, not by an internal flag. Fixes a real gesture-arena bug found during testing: outside edit mode, a long-press landing on a widget was free to bubble to the overlay's background long-press handler and wrongly enter edit mode. An inner no-op GestureDetector of the same gesture type now absorbs it. Adds a "Live HUD stats" Settings section, one switch per metric, that persists immediately (unlike drag frames). Placed at the end of the Settings list rather than in the middle -- inserting mid-list pushed every later section below several existing tests' viewport assumptions. Verified end-to-end on a real emulator including a full process restart: resized a widget, force-stopped the app, relaunched, and the resize held. No consuming screen exists yet (UI-05's job) -- verified via a throwaway preview entry point, deleted after use. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Xki7YAcc2TiN2PRZJ2tXr
114 lines
3.9 KiB
Dart
114 lines
3.9 KiB
Dart
import 'package:flutter/gestures.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/hud/hud_metric.dart';
|
|
import 'package:rippr/src/ui/components/hud_edit_overlay.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// UI-04: drag/toggle behaviour of the customizable HUD, simulated via `TestGesture`
|
|
/// the same way other drag interactions in this codebase are tested (see
|
|
/// `route_planner_screen_test.dart`'s waypoint-drag coverage).
|
|
void main() {
|
|
late Config config;
|
|
|
|
setUp(() async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
config = await Config.load();
|
|
});
|
|
|
|
Widget host() => ProviderScope(
|
|
overrides: [configProvider.overrideWith((ref) => config)],
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: SizedBox.expand(
|
|
child: HudEditOverlay(
|
|
metricBuilder: (context, metric) => Text(metric.label),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
testWidgets('a tap outside edit mode does not move a widget', (tester) async {
|
|
await tester.pumpWidget(host());
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('hud-edit-done')), findsNothing,
|
|
reason: 'not editing yet');
|
|
|
|
await tester.tap(find.text('Speed'));
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const Key('hud-edit-done')), findsNothing,
|
|
reason: 'a plain tap on a widget must never enter edit mode or move it');
|
|
});
|
|
|
|
testWidgets('a long-press on empty space enters edit mode, showing resize handles '
|
|
'and Done', (tester) async {
|
|
await tester.pumpWidget(host());
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.longPress(find.byKey(const Key('hud-edit-background')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('hud-edit-done')), findsOneWidget);
|
|
expect(find.byKey(const Key('hud-resize-handle')), findsWidgets);
|
|
});
|
|
|
|
testWidgets('a long-press-and-drag on a widget moves it, and Done persists the new '
|
|
'position', (tester) async {
|
|
await tester.pumpWidget(host());
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.longPress(find.byKey(const Key('hud-edit-background')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final before = config.hudLayout[HudMetric.speed]!;
|
|
|
|
final speedFinder = find.text('Speed');
|
|
final gesture = await tester.startGesture(tester.getCenter(speedFinder));
|
|
await tester.pump(kLongPressTimeout + kPressTimeout);
|
|
await gesture.moveBy(const Offset(40, 60));
|
|
await tester.pump();
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byKey(const Key('hud-edit-done')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final after = config.hudLayout[HudMetric.speed]!;
|
|
expect(after.x, isNot(before.x));
|
|
expect(after.y, isNot(before.y));
|
|
});
|
|
|
|
testWidgets('a drag while not editing does not move the widget', (tester) async {
|
|
await tester.pumpWidget(host());
|
|
await tester.pumpAndSettle();
|
|
|
|
final before = config.hudLayout[HudMetric.speed]!;
|
|
final speedFinder = find.text('Speed');
|
|
|
|
final gesture = await tester.startGesture(tester.getCenter(speedFinder));
|
|
await tester.pump(kLongPressTimeout + kPressTimeout);
|
|
await gesture.moveBy(const Offset(40, 60));
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('hud-edit-done')), findsNothing);
|
|
final after = config.hudLayout[HudMetric.speed]!;
|
|
expect(after.x, before.x);
|
|
expect(after.y, before.y);
|
|
});
|
|
|
|
testWidgets('only visible metrics render a widget', (tester) async {
|
|
await tester.pumpWidget(host());
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Speed'), findsOneWidget, reason: 'visible by default');
|
|
expect(find.text('Average speed'), findsNothing, reason: 'hidden by default');
|
|
});
|
|
}
|