95 lines
3.5 KiB
Dart
95 lines
3.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:motorcycle_dash/services/alerts/road_alert_models.dart';
|
|
import 'package:motorcycle_dash/services/alerts/community_traffic_parser.dart';
|
|
import 'package:motorcycle_dash/services/alerts/community_traffic_provider.dart';
|
|
import 'package:motorcycle_dash/services/alerts/mock_road_alert_provider.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('Police & Speed-Trap Provider Tests', () {
|
|
test('CommunityTrafficParser maps POLICE and POLICE_VISIBLE to police category', () {
|
|
final jsonSample = {
|
|
'alerts': [
|
|
{
|
|
'id': 'police_101',
|
|
'type': 'POLICE',
|
|
'subtype': 'POLICE_VISIBLE',
|
|
'latitude': 37.7750,
|
|
'longitude': -122.4190,
|
|
'street': 'US-101 N',
|
|
'reportDescription': 'Officer visible on shoulder',
|
|
'confidence': 9,
|
|
},
|
|
{
|
|
'id': 'speedcam_202',
|
|
'type': 'SPEED_CAM',
|
|
'subtype': 'RED_LIGHT_CAMERA',
|
|
'latitude': 37.7800,
|
|
'longitude': -122.4200,
|
|
'street': 'Market St',
|
|
'reportDescription': 'Fixed speed camera',
|
|
'confidence': 10,
|
|
},
|
|
{
|
|
'id': 'hazard_303',
|
|
'type': 'HAZARD',
|
|
'subtype': 'DEBRIS_ON_ROAD',
|
|
'latitude': 37.7700,
|
|
'longitude': -122.4150,
|
|
'street': 'Mission St',
|
|
'reportDescription': 'Tire debris in lane',
|
|
'confidence': 8,
|
|
}
|
|
]
|
|
};
|
|
|
|
final alerts = CommunityTrafficParser.parseAlertsJson(
|
|
jsonSample,
|
|
providerId: 'community_test',
|
|
providerName: 'Community Test API',
|
|
);
|
|
|
|
expect(alerts.length, equals(3));
|
|
|
|
final policeAlert = alerts.firstWhere((a) => a.id == 'police_101');
|
|
expect(policeAlert.category, equals(RoadAlertCategory.police));
|
|
expect(policeAlert.roadName, equals('US-101 N'));
|
|
expect(policeAlert.source, equals('Community Test API'));
|
|
expect(policeAlert.sourceType, equals(RoadAlertSourceType.userReported));
|
|
|
|
final cameraAlert = alerts.firstWhere((a) => a.id == 'speedcam_202');
|
|
expect(cameraAlert.category, equals(RoadAlertCategory.speedCamera));
|
|
|
|
final hazardAlert = alerts.firstWhere((a) => a.id == 'hazard_303');
|
|
expect(hazardAlert.category, equals(RoadAlertCategory.hazard));
|
|
});
|
|
|
|
test('CommunityTrafficRoadAlertProvider advertises police and speed camera support', () {
|
|
final provider = CommunityTrafficRoadAlertProvider();
|
|
expect(provider.id, equals('community_traffic'));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.police));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.speedCamera));
|
|
expect(provider.supportedCategories, contains(RoadAlertCategory.accident));
|
|
});
|
|
|
|
test('MockRoadAlertProvider debug guard', () async {
|
|
final mockProvider = MockRoadAlertProvider();
|
|
final alerts = await mockProvider.getAlerts(
|
|
latitude: 37.7749,
|
|
longitude: -122.4194,
|
|
radiusMeters: 1000.0,
|
|
);
|
|
|
|
if (kDebugMode) {
|
|
expect(alerts.isNotEmpty, isTrue);
|
|
expect(alerts.any((a) => a.category == RoadAlertCategory.police), isTrue);
|
|
expect(alerts.any((a) => a.category == RoadAlertCategory.speedCamera), isTrue);
|
|
} else {
|
|
expect(alerts.isEmpty, isTrue);
|
|
}
|
|
});
|
|
});
|
|
}
|