Files
TPSchedule/mobile/test/data/multiple_reminder_settings_test.dart
T

41 lines
1.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:hepan_everyday/domain/app_snapshot.dart';
import 'package:hepan_everyday/domain/app_settings.dart';
void main() {
test('changing input list cannot change saved reminder choices', () {
final choices = [5, 15];
final settings = AppSettings(reminderOffsets: choices);
choices.clear();
expect(settings.reminderOffsets, [5, 15]);
expect(() => settings.reminderOffsets.add(30), throwsUnsupportedError);
});
test('legacy single advance setting migrates to one selected time', () {
final json = AppSnapshot(settings: AppSettings(reminderMinutes: 30))
.toJson();
(json['settings'] as Map).remove('reminderOffsets');
final migrated = AppSnapshot.fromJson(json).toJson();
expect((migrated['settings'] as Map)['reminderOffsets'], [30]);
});
test('selected times are normalized and survive snapshot round trip', () {
final json = AppSnapshot().toJson();
(json['settings'] as Map)['reminderOffsets'] = [15, 5, 15];
final saved = AppSnapshot.fromJson(AppSnapshot.fromJson(json).toJson())
.toJson();
expect((saved['settings'] as Map)['reminderOffsets'], [5, 15]);
});
for (final invalid in [
[],
[0],
[7],
['15'],
[15, 90],
]) {
test('invalid selected reminder times $invalid are rejected', () {
final json = AppSnapshot().toJson();
(json['settings'] as Map)['reminderOffsets'] = invalid;
expect(() => AppSnapshot.fromJson(json), throwsFormatException);
});
}
}