MotorSignal-App/test/evolution_dashboard_truthfu...

108 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:motorcycle_dash/models/telemetry_sample.dart';
import 'package:motorcycle_dash/features/rides/ride_state_machine.dart';
import 'package:motorcycle_dash/features/dashboard/widgets/evolution_portrait_dashboard.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:motorcycle_dash/features/records/records_service.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late SharedPreferences prefs;
setUp(() async {
SharedPreferences.setMockInitialValues({});
prefs = await SharedPreferences.getInstance();
});
Widget buildDashboard({TelemetrySample? telemetry, RideSession? session}) {
return ProviderScope(
overrides: [
sharedPreferencesProvider.overrideWithValue(prefs),
],
child: MaterialApp(
home: Scaffold(
body: EvolutionPortraitDashboard(
currentSpeedMph: 45.0,
heading: 180.0,
leanAngle: 12.0,
accelG: 0.2,
lateralG: 0.1,
session: session ?? RideSession(
state: RideState.riding,
startTime: DateTime.now(),
tripDistanceMiles: 3.5,
topSpeedMph: 55.0,
averageSpeedMph: 42.0,
maxLeanLeft: 22.0,
maxLeanRight: 25.0,
maxAccelG: 0.6,
maxBrakingG: 0.8,
),
telemetry: telemetry,
),
),
),
);
}
testWidgets('displays GPS 3D FIX when accuracy <= 15m and no fake placeholders', (tester) async {
final sample = TelemetrySample(
timestamp: DateTime.now(),
gpsAccuracy: 8.5,
);
await tester.pumpWidget(buildDashboard(telemetry: sample));
await tester.pump();
// Truthful GPS
expect(find.text('GPS 3D FIX'), findsOneWidget);
// Placeholders removed
expect(find.text('FIXED'), findsNothing);
expect(find.text('HEADSET'), findsNothing);
expect(find.text('92%'), findsNothing);
// Recording status badge
expect(find.text('RECORDING'), findsOneWidget);
});
testWidgets('displays GPS 2D FIX when accuracy is 25m', (tester) async {
final sample = TelemetrySample(
timestamp: DateTime.now(),
gpsAccuracy: 25.0,
);
await tester.pumpWidget(buildDashboard(telemetry: sample));
await tester.pump();
expect(find.text('GPS 2D FIX'), findsOneWidget);
expect(find.text('HEADSET'), findsNothing);
expect(find.text('92%'), findsNothing);
});
testWidgets('displays GPS WEAK when accuracy is 50m', (tester) async {
final sample = TelemetrySample(
timestamp: DateTime.now(),
gpsAccuracy: 50.0,
);
await tester.pumpWidget(buildDashboard(telemetry: sample));
await tester.pump();
expect(find.text('GPS WEAK'), findsOneWidget);
expect(find.text('HEADSET'), findsNothing);
});
testWidgets('displays NO GPS when telemetry is null', (tester) async {
await tester.pumpWidget(buildDashboard(telemetry: null));
await tester.pump();
expect(find.text('NO GPS'), findsOneWidget);
expect(find.text('HEADSET'), findsNothing);
expect(find.text('92%'), findsNothing);
});
}