Fix release notification resource and add multiple advance reminders
This commit is contained in:
@@ -35,4 +35,57 @@ void main() {
|
||||
await gateway.initialize();
|
||||
expect(attempts, 2);
|
||||
});
|
||||
test(
|
||||
'disabled course notification channel is reported even with app permission',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
AndroidFlutterLocalNotificationsPlugin.registerWith();
|
||||
const channel = MethodChannel(
|
||||
'dexterous.com/flutter/local_notifications',
|
||||
);
|
||||
var importance = 0;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
switch (call.method) {
|
||||
case 'initialize':
|
||||
return true;
|
||||
case 'getNotificationAppLaunchDetails':
|
||||
return {'notificationLaunchedApp': false};
|
||||
case 'areNotificationsEnabled':
|
||||
return true;
|
||||
case 'canScheduleExactNotifications':
|
||||
return true;
|
||||
case 'getNotificationChannels':
|
||||
return [
|
||||
{
|
||||
'id': 'hepan_lessons',
|
||||
'name': '课前提醒',
|
||||
'description': '课程开始前的提醒',
|
||||
'importance': importance,
|
||||
'showBadge': true,
|
||||
'playSound': true,
|
||||
'enableVibration': true,
|
||||
'enableLights': false,
|
||||
'bypassDnd': false,
|
||||
'ledColor': 0,
|
||||
'audioAttributesUsage': 5,
|
||||
},
|
||||
];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
addTearDown(() {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
final gateway = PluginReminderGateway();
|
||||
expect(
|
||||
(await gateway.permissions(request: false)).notifications,
|
||||
isFalse,
|
||||
);
|
||||
importance = 4;
|
||||
expect((await gateway.permissions(request: false)).notifications, isTrue);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:hepan_everyday/services/local_notification_service.dart';
|
||||
import 'package:hepan_everyday/services/notification_service.dart';
|
||||
import 'package:hepan_everyday/domain/schedule_engine.dart';
|
||||
import 'package:hepan_everyday/domain/app_settings.dart';
|
||||
import 'package:hepan_everyday/domain/app_snapshot.dart';
|
||||
|
||||
import '../domain/schedule_engine_test.dart' show course;
|
||||
|
||||
@@ -40,6 +41,78 @@ void main() {
|
||||
gateway = AlarmGateway();
|
||||
service = LocalNotificationService(gateway);
|
||||
});
|
||||
AppSettings multiple(List<int> minutes) {
|
||||
final json = AppSnapshot(settings: settings).toJson();
|
||||
(json['settings'] as Map<String, dynamic>)['reminderOffsets'] = minutes;
|
||||
return AppSnapshot.fromJson(json).settings;
|
||||
}
|
||||
|
||||
test(
|
||||
'selected advance times produce independent alarms and survive refresh',
|
||||
() async {
|
||||
final events = ScheduleEngine.occurrences([course(last: 2)], term);
|
||||
await service.reconcile(
|
||||
events,
|
||||
multiple([5, 15]),
|
||||
DateTime.utc(2026, 9, 9),
|
||||
);
|
||||
expect(gateway.alarms, hasLength(2));
|
||||
expect(gateway.alarms.values.map((a) => a.fireAt.toUtc()).toSet(), {
|
||||
DateTime.utc(2026, 9, 9, 0, 15),
|
||||
DateTime.utc(2026, 9, 9, 0, 25),
|
||||
});
|
||||
final ids = gateway.alarms.keys.toSet();
|
||||
await service.reconcile(
|
||||
events,
|
||||
multiple([15, 5]),
|
||||
DateTime.utc(2026, 9, 9),
|
||||
);
|
||||
expect(gateway.alarms.keys.toSet(), ids);
|
||||
await service.reconcile(events, multiple([5]), DateTime.utc(2026, 9, 9));
|
||||
expect(gateway.alarms, hasLength(1));
|
||||
expect(
|
||||
gateway.alarms.values.single.fireAt.toUtc(),
|
||||
DateTime.utc(2026, 9, 9, 0, 25),
|
||||
);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'elapsed earlier reminder does not remove the later selected reminder',
|
||||
() async {
|
||||
final events = ScheduleEngine.occurrences([course()], term);
|
||||
await service.reconcile(
|
||||
events,
|
||||
multiple([5, 15]),
|
||||
DateTime.utc(2026, 9, 9, 0, 20),
|
||||
);
|
||||
expect(gateway.alarms, hasLength(1));
|
||||
expect(
|
||||
gateway.alarms.values.single.fireAt.toUtc(),
|
||||
DateTime.utc(2026, 9, 9, 0, 25),
|
||||
);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'limit selects earliest reminder instants across all selected times',
|
||||
() async {
|
||||
final events = ScheduleEngine.occurrences(
|
||||
List.generate(501, (i) => course(id: 'c-$i')),
|
||||
term,
|
||||
);
|
||||
final result = await service.reconcile(
|
||||
events,
|
||||
multiple([5, 15]),
|
||||
DateTime.utc(2026, 9, 9),
|
||||
);
|
||||
expect(result.scheduledCount, 400);
|
||||
expect(
|
||||
gateway.alarms.values.every(
|
||||
(a) => a.fireAt.isAtSameMomentAs(DateTime.utc(2026, 9, 9, 0, 15)),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'continuous course schedules one alarm fifteen minutes before school start',
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user