feat: persist timetable and validate confirmed imports
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'package:hepan_everyday/data/snapshot_store.dart';
|
||||
import 'package:hepan_everyday/domain/app_snapshot.dart';
|
||||
import 'package:hepan_everyday/domain/app_settings.dart';
|
||||
import 'package:hepan_everyday/domain/course_occurrence.dart';
|
||||
import 'package:hepan_everyday/services/notification_service.dart';
|
||||
import 'package:hepan_everyday/services/calendar_service.dart';
|
||||
|
||||
class MemoryStore extends SnapshotStore {
|
||||
MemoryStore([this.value]);
|
||||
AppSnapshot? value;
|
||||
bool failSave = false;
|
||||
@override
|
||||
Future<AppSnapshot?> load() async => value;
|
||||
@override
|
||||
Future<void> save(AppSnapshot snapshot) async {
|
||||
if (failSave) throw StateError('磁盘写入失败');
|
||||
value = snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeNotifications extends NotificationService {
|
||||
int reconciliations = 0, cancellations = 0;
|
||||
bool fail = false;
|
||||
@override
|
||||
Future<ReminderResult> reconcile(
|
||||
List<CourseOccurrence> occurrences,
|
||||
AppSettings settings,
|
||||
DateTime now,
|
||||
) async {
|
||||
reconciliations++;
|
||||
if (fail) throw StateError('系统拒绝');
|
||||
return ReminderResult(
|
||||
settings.remindersEnabled ? ReminderStatus.exact : ReminderStatus.off,
|
||||
scheduledCount: occurrences.length,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> cancelOwned() async {
|
||||
cancellations++;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> requestPermissions() async {}
|
||||
}
|
||||
|
||||
class FakeCalendar extends CalendarService {
|
||||
bool access = true;
|
||||
int synchronizations = 0, deletions = 0;
|
||||
@override
|
||||
Future<bool> requestAccess() async => access;
|
||||
@override
|
||||
Future<List<DeviceCalendar>> listWritableCalendars() async => [
|
||||
const DeviceCalendar('local', '测试日历'),
|
||||
];
|
||||
@override
|
||||
Future<Map<String, String>> sync(
|
||||
List<CourseOccurrence> occurrences,
|
||||
String calendarId,
|
||||
Map<String, String> knownEventIds,
|
||||
) async {
|
||||
synchronizations++;
|
||||
return {
|
||||
for (final e in occurrences)
|
||||
e.key: knownEventIds[e.key] ?? 'event-${e.key}',
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteOwned(Map<String, String> eventIds) async {
|
||||
deletions++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user