import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:motorcycle_dash/services/map/map_providers.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('Map Smoothness & Orientation Angle Normalization (#79 & #80)', () { test('shortestAngleDiff correctly calculates minimal circular angular distance', () { // Direct small adjustments expect(shortestAngleDiff(10.0, 20.0), closeTo(10.0, 0.001)); expect(shortestAngleDiff(20.0, 10.0), closeTo(-10.0, 0.001)); // Circular transition crossing 0° / 360° // Moving from 359° to 1° should be +2° clockwise, NOT -358° counter-clockwise expect(shortestAngleDiff(359.0, 1.0), closeTo(2.0, 0.001)); // Moving from 1° to 359° should be -2° counter-clockwise, NOT +358° clockwise expect(shortestAngleDiff(1.0, 359.0), closeTo(-2.0, 0.001)); // 350° to 10° should be +20° expect(shortestAngleDiff(350.0, 10.0), closeTo(20.0, 0.001)); // 10° to 350° should be -20° expect(shortestAngleDiff(10.0, 350.0), closeTo(-20.0, 0.001)); // Half-circle expect(shortestAngleDiff(0.0, 180.0).abs(), closeTo(180.0, 0.001)); }); test('normalizeAngle correctly constrains values to [0.0, 360.0)', () { expect(normalizeAngle(0.0), closeTo(0.0, 0.001)); expect(normalizeAngle(360.0), closeTo(0.0, 0.001)); expect(normalizeAngle(365.0), closeTo(5.0, 0.001)); expect(normalizeAngle(-10.0), closeTo(350.0, 0.001)); expect(normalizeAngle(-370.0), closeTo(350.0, 0.001)); expect(normalizeAngle(720.0), closeTo(0.0, 0.001)); }); }); group('MapOrientation State & Persistence (#80)', () { setUp(() { SharedPreferences.setMockInitialValues({}); }); test('MapOrientationNotifier toggles and persists orientation', () async { final notifier = MapOrientationNotifier(); expect(notifier.state, MapOrientation.northUp); await notifier.toggle(); expect(notifier.state, MapOrientation.headingUp); await notifier.toggle(); expect(notifier.state, MapOrientation.northUp); await notifier.setOrientation(MapOrientation.headingUp); expect(notifier.state, MapOrientation.headingUp); final prefs = await SharedPreferences.getInstance(); expect(prefs.getString('selected_map_orientation'), 'headingUp'); }); }); }