fix: preserve queued settings and recover interrupted or corrupt state
This commit is contained in:
@@ -38,6 +38,60 @@ void main() {
|
||||
);
|
||||
});
|
||||
tearDown(() => controller.dispose());
|
||||
test(
|
||||
'queued changes to different settings preserve disabling reminders',
|
||||
() async {
|
||||
await controller.initialize();
|
||||
|
||||
await Future.wait([
|
||||
controller.updateSettings(
|
||||
(current) => current.copyWith(remindersEnabled: false),
|
||||
),
|
||||
controller.updateSettings(
|
||||
(current) => current.copyWith(colorMode: ColorMode.single),
|
||||
),
|
||||
]);
|
||||
expect(store.value!.settings.remindersEnabled, isFalse);
|
||||
expect(store.value!.settings.colorMode, ColorMode.single);
|
||||
},
|
||||
);
|
||||
test('partial first calendar sync survives restart and is cleaned before another destination', () async {
|
||||
store.value = store.value!.copyWith(
|
||||
courses: [
|
||||
course(id: 'a'),
|
||||
course(id: 'b'),
|
||||
],
|
||||
);
|
||||
final provider = CalendarProvider()..failAfterFirst = true;
|
||||
final first = AppController(
|
||||
store,
|
||||
notifications,
|
||||
AndroidCalendarService(provider),
|
||||
controller.clock,
|
||||
);
|
||||
await first.initialize();
|
||||
await first.enableCalendarFromUserAction('local');
|
||||
expect(provider.records, hasLength(1));
|
||||
first.dispose();
|
||||
provider.failAfterFirst = false;
|
||||
final reopened = AppController(
|
||||
store,
|
||||
notifications,
|
||||
AndroidCalendarService(provider),
|
||||
controller.clock,
|
||||
);
|
||||
await reopened.initialize();
|
||||
expect(provider.records, isEmpty);
|
||||
await reopened.enableCalendarFromUserAction('other');
|
||||
expect(
|
||||
provider.records.values.every((e) => e.calendarId == 'other'),
|
||||
isTrue,
|
||||
);
|
||||
expect(provider.records, hasLength(2));
|
||||
await reopened.disableCalendar(deleteEvents: true);
|
||||
expect(provider.records, isEmpty);
|
||||
reopened.dispose();
|
||||
});
|
||||
test('turning off after interrupted first sync cleans events even without saved IDs', () async {
|
||||
store.value = store.value!.copyWith(
|
||||
courses: [
|
||||
@@ -122,7 +176,7 @@ void main() {
|
||||
await controller.initialize();
|
||||
store.failSave = true;
|
||||
await controller.updateSettings(
|
||||
controller.snapshot.settings.copyWith(reminderMinutes: 30),
|
||||
(current) => current.copyWith(reminderMinutes: 30),
|
||||
);
|
||||
expect(controller.lastError, isNotNull);
|
||||
await controller.showDemo();
|
||||
@@ -148,7 +202,7 @@ void main() {
|
||||
await controller.initialize();
|
||||
store.failSave = true;
|
||||
await controller.updateSettings(
|
||||
controller.snapshot.settings.copyWith(reminderMinutes: 30),
|
||||
(current) => current.copyWith(reminderMinutes: 30),
|
||||
);
|
||||
expect(controller.snapshot.settings.reminderMinutes, 15);
|
||||
expect(controller.lastError, isNotNull);
|
||||
@@ -157,10 +211,10 @@ void main() {
|
||||
await controller.initialize();
|
||||
await Future.wait([
|
||||
controller.updateSettings(
|
||||
controller.snapshot.settings.copyWith(reminderMinutes: 30),
|
||||
(current) => current.copyWith(reminderMinutes: 30),
|
||||
),
|
||||
controller.updateSettings(
|
||||
controller.snapshot.settings.copyWith(reminderMinutes: 60),
|
||||
(current) => current.copyWith(reminderMinutes: 60),
|
||||
),
|
||||
]);
|
||||
expect(store.value!.settings.reminderMinutes, 60);
|
||||
|
||||
Reference in New Issue
Block a user