fix: initialize reminder channel and clarify notification permission diagnostics

This commit is contained in:
Codex
2026-10-27 17:37:03 +08:00
parent db953b8b3d
commit fbcb7fb637
9 changed files with 165 additions and 10 deletions
@@ -7,6 +7,54 @@ import 'package:hepan_everyday/services/local_notification_service.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('fresh notification initialization creates the course category before checks', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
AndroidFlutterLocalNotificationsPlugin.registerWith();
const channel = MethodChannel('dexterous.com/flutter/local_notifications');
const system = MethodChannel('com.tpschedule.app/reminders');
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
final categories = <Map<Object?, Object?>>[];
messenger.setMockMethodCallHandler(channel, (call) async {
switch (call.method) {
case 'initialize':
return true;
case 'createNotificationChannel':
final data = call.arguments as Map;
categories.add({
...Map<Object?, Object?>.from(data),
// Android returns a numeric color even when no LED was set.
'ledColor': data['ledColor'] ?? 0,
});
return null;
case 'getNotificationAppLaunchDetails':
return {'notificationLaunchedApp': false};
case 'areNotificationsEnabled':
case 'canScheduleExactNotifications':
return true;
case 'getNotificationChannels':
return categories;
case 'pendingNotificationRequests':
return [];
}
return null;
});
messenger.setMockMethodCallHandler(
system,
(_) async => <Object?, Object?>{},
);
addTearDown(() {
debugDefaultTargetPlatformOverride = null;
messenger.setMockMethodCallHandler(channel, null);
messenger.setMockMethodCallHandler(system, null);
});
final gateway = PluginReminderGateway();
final diagnosis = await gateway.diagnose();
expect(diagnosis['channelImportance'], Importance.high.value);
expect(diagnosis['appNotificationsEnabled'], isTrue);
expect(diagnosis['channelExists'], isTrue);
expect(categories.single['id'], 'hepan_lessons');
});
test(
'querying future reminders does not depend on active notification access',
() async {