64 lines
2.9 KiB
Dart
64 lines
2.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:motorcycle_dash/services/alerts/road_alert_models.dart';
|
|
import 'package:motorcycle_dash/services/alerts/tomtom_road_alert_provider.dart';
|
|
import 'package:motorcycle_dash/services/alerts/local_road_alert_provider.dart';
|
|
import 'package:motorcycle_dash/services/alerts/road_alert_providers.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('Road Alert System Tests', () {
|
|
test('RoadAlertCategory display names and colors', () {
|
|
expect(RoadAlertCategory.police.displayName, equals('Police'));
|
|
expect(RoadAlertCategory.accident.displayName, equals('Accident'));
|
|
expect(RoadAlertCategory.hazard.displayName, equals('Hazard'));
|
|
|
|
expect(RoadAlertCategory.police.color, isNotNull);
|
|
expect(RoadAlertCategory.accident.icon, isNotNull);
|
|
});
|
|
|
|
test('TomTomRoadAlertProvider capability advertising', () {
|
|
final provider = TomTomRoadAlertProvider();
|
|
expect(provider.id, equals('tomtom'));
|
|
expect(provider.name, equals('TomTom Traffic'));
|
|
|
|
// Verify TomTom explicitly advertises its supported categories (No police/speed-traps)
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.accident));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.hazard));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.construction));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.roadClosure));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.traffic));
|
|
|
|
expect(provider.supportedCategories, isNot(contains(RoadAlertCategory.police)));
|
|
expect(provider.supportedCategories, isNot(contains(RoadAlertCategory.speedCamera)));
|
|
});
|
|
|
|
test('LocalRoadAlertProvider returns demo alerts', () async {
|
|
final localProvider = LocalRoadAlertProvider();
|
|
final alerts = await localProvider.getAlerts(
|
|
latitude: 37.7749,
|
|
longitude: -122.4194,
|
|
radiusMeters: 1000.0,
|
|
);
|
|
|
|
expect(alerts.isNotEmpty, isTrue);
|
|
expect(alerts.any((a) => a.category == RoadAlertCategory.hazard), isTrue);
|
|
expect(alerts.any((a) => a.category == RoadAlertCategory.construction), isTrue);
|
|
});
|
|
|
|
test('Road alert providers & setting defaults', () {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final container = ProviderContainer();
|
|
addTearDown(container.dispose);
|
|
|
|
expect(container.read(roadAlertsEnabledProvider), isTrue);
|
|
expect(container.read(audioAlertsEnabledProvider), isTrue);
|
|
expect(container.read(alertRadiusMetersProvider), equals(804.7));
|
|
expect(container.read(tomtomApiKeyProvider), isEmpty);
|
|
expect(container.read(tomtomStatusProvider), equals(RoadAlertProviderStatus.notConfigured));
|
|
});
|
|
});
|
|
}
|