feat: Add services for managing trip-related data
- 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.
This commit is contained in:
63
test/services/trip_checklist_service_test.dart
Normal file
63
test/services/trip_checklist_service_test.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:travel_mate/models/checklist_item.dart';
|
||||
import 'package:travel_mate/services/trip_checklist_service.dart';
|
||||
|
||||
void main() {
|
||||
late TripChecklistService service;
|
||||
const tripId = 'trip-123';
|
||||
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
service = TripChecklistService();
|
||||
});
|
||||
|
||||
test('adds and loads checklist items', () async {
|
||||
final created = ChecklistItem.newItem(id: '1', label: 'Préparer passeport');
|
||||
await service.addItem(tripId, created);
|
||||
|
||||
final result = await service.loadChecklist(tripId);
|
||||
|
||||
expect(result, hasLength(1));
|
||||
expect(result.first.label, 'Préparer passeport');
|
||||
expect(result.first.isDone, isFalse);
|
||||
});
|
||||
|
||||
test('toggles completion state', () async {
|
||||
final item = ChecklistItem.newItem(id: '1', label: 'Acheter billets');
|
||||
await service.addItem(tripId, item);
|
||||
|
||||
final toggled = await service.toggleItem(tripId, '1');
|
||||
|
||||
expect(toggled.first.isDone, isTrue);
|
||||
|
||||
final toggledBack = await service.toggleItem(tripId, '1');
|
||||
expect(toggledBack.first.isDone, isFalse);
|
||||
});
|
||||
|
||||
test('deletes items and keeps list consistent', () async {
|
||||
final itemA = ChecklistItem.newItem(id: '1', label: 'Adapter prise');
|
||||
final itemB = ChecklistItem.newItem(id: '2', label: 'Chargeur');
|
||||
await service.addItem(tripId, itemA);
|
||||
await service.addItem(tripId, itemB);
|
||||
|
||||
final afterDelete = await service.deleteItem(tripId, '1');
|
||||
|
||||
expect(afterDelete, hasLength(1));
|
||||
expect(afterDelete.first.id, '2');
|
||||
|
||||
final persisted = await service.loadChecklist(tripId);
|
||||
expect(persisted, hasLength(1));
|
||||
expect(persisted.first.id, '2');
|
||||
});
|
||||
|
||||
test('handles corrupted payload gracefully', () async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('checklist_$tripId', 'not-json');
|
||||
|
||||
final items = await service.loadChecklist(tripId);
|
||||
|
||||
expect(items, isEmpty);
|
||||
expect(prefs.getString('checklist_$tripId'), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user