- Implement EmergencyService for handling emergency contacts per trip. - Create GuestFlagService to manage guest mode flags for trips. - Introduce NotificationService with local notification capabilities. - Add OfflineFlagService for managing offline caching flags. - Develop PackingService for shared packing lists per trip. - Implement ReminderService for managing reminders/to-dos per trip. - Create SosService for dispatching SOS events to a backend. - Add StorageService with album image upload functionality. - Implement TransportService for managing transport segments per trip. - Create TripChecklistService for storing and retrieving trip checklists. - Add TripDocumentService for persisting trip documents metadata. test: Add unit tests for new services - Implement tests for AlbumService, BudgetService, EmergencyService, GuestFlagService, PackingService, ReminderService, SosService, TransportService, TripChecklistService, and TripDocumentService. - Ensure tests cover adding, loading, deleting, and handling corrupted payloads for each service.
55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:travel_mate/models/emergency_contact.dart';
|
|
import 'package:travel_mate/services/emergency_service.dart';
|
|
|
|
void main() {
|
|
const tripId = 'trip-emergency-1';
|
|
late EmergencyService service;
|
|
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
service = EmergencyService();
|
|
});
|
|
|
|
test('adds and loads contacts', () async {
|
|
final contact = EmergencyContact.newContact(
|
|
id: 'c1',
|
|
name: 'Assistance',
|
|
phone: '+33123456789',
|
|
note: 'Assurance',
|
|
);
|
|
await service.addContact(tripId, contact);
|
|
|
|
final loaded = await service.loadContacts(tripId);
|
|
expect(loaded.single.phone, '+33123456789');
|
|
});
|
|
|
|
test('deletes contact', () async {
|
|
final a = EmergencyContact.newContact(
|
|
id: 'a',
|
|
name: 'Ambassade',
|
|
phone: '+321234',
|
|
);
|
|
final b = EmergencyContact.newContact(
|
|
id: 'b',
|
|
name: 'Marie',
|
|
phone: '+33999',
|
|
);
|
|
await service.addContact(tripId, a);
|
|
await service.addContact(tripId, b);
|
|
|
|
final updated = await service.deleteContact(tripId, 'a');
|
|
expect(updated.map((c) => c.id), contains('b'));
|
|
expect(updated.length, 1);
|
|
});
|
|
|
|
test('corrupted payload cleared', () async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString('emergency_$tripId', 'oops');
|
|
final loaded = await service.loadContacts(tripId);
|
|
expect(loaded, isEmpty);
|
|
expect(prefs.getString('emergency_$tripId'), isNull);
|
|
});
|
|
}
|