LifeMate — Personal, Family & Learning Companion
feat/personal-encrypted-recovery
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | import 'dart:io'; |
| 2 | |
| 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter/services.dart'; |
| 5 | import 'package:flutter_localizations/flutter_localizations.dart'; |
| 6 | import 'package:flutter_test/flutter_test.dart'; |
| 7 | import 'package:lifemate/standalone/model.dart'; |
| 8 | import 'package:lifemate/standalone/reminder_coordinator.dart'; |
| 9 | import 'package:lifemate/standalone/reminder_settings.dart'; |
| 10 | import 'package:lifemate/standalone/reminders.dart'; |
| 11 | import 'package:lifemate/standalone/store.dart'; |
| 12 | import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; |
| 13 | import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; |
| 14 | import 'package:sqflite_common_ffi/sqflite_ffi.dart'; |
| 15 | |
| 16 | void main() { |
| 17 | const channel = MethodChannel('lifeguide/device_planner_reminders'); |
| 18 | final now = DateTime(2026, 10, 21, 8); |
| 19 | late Directory directory; |
| 20 | late StandaloneStore store; |
| 21 | late StandaloneReminderCoordinator coordinator; |
| 22 | final methods = <String>[]; |
| 23 | bool enabled = false, active = false, failSettings = false; |
| 24 | bool permissionGranted = true; |
| 25 | int scheduled = 0; |
| 26 | |
| 27 | setUpAll(() async { |
| 28 | sqfliteFfiInit(); |
| 29 | await (FontLoader('LifeGuidePersian') |
| 30 | ..addFont(rootBundle.load('assets/fonts/LifeGuidePersian.ttf'))) |
| 31 | .load(); |
| 32 | }); |
| 33 | setUp(() async { |
| 34 | SharedPreferencesAsyncPlatform.instance = |
| 35 | InMemorySharedPreferencesAsync.empty(); |
| 36 | enabled = false; |
| 37 | active = false; |
| 38 | failSettings = false; |
| 39 | permissionGranted = true; |
| 40 | scheduled = 0; |
| 41 | methods.clear(); |
| 42 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 43 | .setMockMethodCallHandler(channel, (call) async { |
| 44 | methods.add(call.method); |
| 45 | if (call.method == 'openNotificationSettings' && failSettings) { |
| 46 | throw PlatformException(code: 'settings_unavailable'); |
| 47 | } |
| 48 | if (call.method == 'setEnabled') { |
| 49 | enabled = (call.arguments as Map)['enabled'] == true; |
| 50 | } |
| 51 | if (call.method == 'activate') active = true; |
| 52 | if (call.method == 'deactivate') { |
| 53 | active = false; |
| 54 | scheduled = 0; |
| 55 | } |
| 56 | if (call.method == 'replace') { |
| 57 | scheduled = ((call.arguments as Map)['reminders'] as List).length; |
| 58 | } |
| 59 | if (['status', 'requestPermission', 'requestExactAlarmAccess'] |
| 60 | .contains(call.method)) { |
| 61 | return { |
| 62 | 'supported': true, |
| 63 | 'enabled': enabled, |
| 64 | 'permissionGranted': permissionGranted, |
| 65 | 'active': active, |
| 66 | 'scheduledCount': scheduled, |
| 67 | 'timing': 'approximate' |
| 68 | }; |
| 69 | } |
| 70 | return true; |
| 71 | }); |
| 72 | directory = await Directory.systemTemp.createTemp('lifeguide-reminder-ui-'); |
| 73 | store = await StandaloneStore.open( |
| 74 | path: '${directory.path}/planner.sqlite', |
| 75 | factory: databaseFactoryFfiNoIsolate); |
| 76 | await store.createProfile( |
| 77 | displayName: 'نمونه ساختگی', |
| 78 | category: StandaloneProfileCategory.girlMinor); |
| 79 | await store.createPlan(StandalonePlanDraft( |
| 80 | title: 'برنامهٔ ساختگی', |
| 81 | kind: StandalonePlanKind.task, |
| 82 | recurrence: StandaloneRecurrence.once, |
| 83 | startDate: now, |
| 84 | startMinute: 600, |
| 85 | endMinute: 660, |
| 86 | reminderMinutes: 5)); |
| 87 | coordinator = StandaloneReminderCoordinator( |
| 88 | port: StandaloneReminderPort(now: () => now), now: () => now); |
| 89 | }); |
| 90 | tearDown(() async { |
| 91 | coordinator.dispose(); |
| 92 | await store.close(); |
| 93 | await directory.delete(recursive: true); |
| 94 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 95 | .setMockMethodCallHandler(channel, null); |
| 96 | }); |
| 97 | Future<void> idle(WidgetTester tester) async { |
| 98 | for (var i = 0; i < 100; i++) { |
| 99 | await Future<void>.delayed(const Duration(milliseconds: 10)); |
| 100 | await tester.pumpAndSettle(); |
| 101 | if (find.byType(LinearProgressIndicator).evaluate().isEmpty && |
| 102 | coordinator.status != null) { |
| 103 | return; |
| 104 | } |
| 105 | } |
| 106 | fail('Reminder settings never finished reading actual SQLite.'); |
| 107 | } |
| 108 | |
| 109 | Future<void> open(WidgetTester tester, {double scale = 1}) async { |
| 110 | await tester.pumpWidget(MaterialApp( |
| 111 | theme: ThemeData(fontFamily: 'LifeGuidePersian'), |
| 112 | locale: const Locale('fa'), |
| 113 | supportedLocales: const [Locale('fa')], |
| 114 | localizationsDelegates: const [ |
| 115 | GlobalMaterialLocalizations.delegate, |
| 116 | GlobalWidgetsLocalizations.delegate, |
| 117 | GlobalCupertinoLocalizations.delegate, |
| 118 | ], |
| 119 | builder: (context, child) => MediaQuery( |
| 120 | data: MediaQuery.of(context) |
| 121 | .copyWith(textScaler: TextScaler.linear(scale)), |
| 122 | child: child!), |
| 123 | home: StandaloneReminderSettings( |
| 124 | store: store, coordinator: coordinator))); |
| 125 | await idle(tester); |
| 126 | } |
| 127 | |
| 128 | Future<void> openSystemSettings(WidgetTester tester) async { |
| 129 | final button = |
| 130 | find.byKey(const Key('personal-notification-system-settings')); |
| 131 | expect(button, findsOneWidget); |
| 132 | await tester.ensureVisible(button); |
| 133 | await tester.tap(button); |
| 134 | await tester.pumpAndSettle(); |
| 135 | await Future<void>.delayed(const Duration(milliseconds: 20)); |
| 136 | await tester.pumpAndSettle(); |
| 137 | } |
| 138 | |
| 139 | testWidgets( |
| 140 | 'system notification settings never opts in or changes saved plans', |
| 141 | (tester) async { |
| 142 | await tester.runAsync(() async { |
| 143 | await open(tester); |
| 144 | final before = (await store.listPlans()).single; |
| 145 | methods.clear(); |
| 146 | await openSystemSettings(tester); |
| 147 | expect(methods, ['openNotificationSettings']); |
| 148 | expect(enabled, isFalse); |
| 149 | expect(coordinator.status!.enabled, isFalse); |
| 150 | expect((await store.listPlans()).single.id, before.id); |
| 151 | expect(tester.takeException(), isNull); |
| 152 | }); |
| 153 | }, variant: TargetPlatformVariant.only(TargetPlatform.android)); |
| 154 | testWidgets('failed settings intent leaves existing reminder schedule intact', |
| 155 | (tester) async { |
| 156 | await tester.runAsync(() async { |
| 157 | await coordinator.enable(store); |
| 158 | await open(tester); |
| 159 | final before = coordinator.status!; |
| 160 | expect(scheduled, 1); |
| 161 | failSettings = true; |
| 162 | methods.clear(); |
| 163 | await openSystemSettings(tester); |
| 164 | expect(methods, ['openNotificationSettings']); |
| 165 | expect(enabled, isTrue); |
| 166 | expect(active, isTrue); |
| 167 | expect(scheduled, 1); |
| 168 | expect(coordinator.status, same(before)); |
| 169 | expect(find.textContaining('تنظیمات اعلان باز نشد'), findsOneWidget); |
| 170 | expect(tester.takeException(), isNull); |
| 171 | }); |
| 172 | }, variant: TargetPlatformVariant.only(TargetPlatform.android)); |
| 173 | |
| 174 | testWidgets('return from Android settings rereads permission and stays OFF', |
| 175 | (tester) async { |
| 176 | await tester.runAsync(() async { |
| 177 | await open(tester); |
| 178 | await openSystemSettings(tester); |
| 179 | methods.clear(); |
| 180 | permissionGranted = false; |
| 181 | tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused); |
| 182 | tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed); |
| 183 | await idle(tester); |
| 184 | expect(methods, contains('status')); |
| 185 | expect(methods, isNot(contains('requestPermission'))); |
| 186 | expect(methods, isNot(contains('setEnabled'))); |
| 187 | expect(methods, isNot(contains('activate'))); |
| 188 | expect(coordinator.status!.enabled, isFalse); |
| 189 | expect(coordinator.status!.permissionGranted, isFalse); |
| 190 | expect(find.textContaining('مجوز اعلان: داده نشده'), findsOneWidget); |
| 191 | expect((await store.listPlans()), hasLength(1)); |
| 192 | expect(tester.takeException(), isNull); |
| 193 | }); |
| 194 | }, variant: TargetPlatformVariant.only(TargetPlatform.android)); |
| 195 | |
| 196 | testWidgets( |
| 197 | 'sound settings is usable at width 320 and text scale 200 percent', |
| 198 | (tester) async { |
| 199 | tester.view.devicePixelRatio = 1; |
| 200 | tester.view.physicalSize = const Size(320, 800); |
| 201 | addTearDown(tester.view.resetPhysicalSize); |
| 202 | addTearDown(tester.view.resetDevicePixelRatio); |
| 203 | await tester.runAsync(() async { |
| 204 | await open(tester, scale: 2); |
| 205 | final button = |
| 206 | find.byKey(const Key('personal-notification-system-settings')); |
| 207 | await tester.ensureVisible(button); |
| 208 | final size = tester.getSize(button); |
| 209 | expect(size.width, greaterThanOrEqualTo(48)); |
| 210 | expect(size.height, greaterThanOrEqualTo(48)); |
| 211 | expect(size.width, lessThanOrEqualTo(320)); |
| 212 | methods.clear(); |
| 213 | await openSystemSettings(tester); |
| 214 | expect(methods, ['openNotificationSettings']); |
| 215 | expect(tester.takeException(), isNull); |
| 216 | }); |
| 217 | }, variant: TargetPlatformVariant.only(TargetPlatform.android)); |
| 218 | } |