LifeMate — Personal, Family & Learning Companion
docs/owner-guide-and-delivery-plan
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:async'; |
| 2 | import 'package:flutter/foundation.dart'; |
| 3 | import 'package:flutter/services.dart'; |
| 4 | import 'package:flutter_test/flutter_test.dart'; |
| 5 | import 'package:lifemate/local_reminders.dart'; |
| 6 | |
| 7 | void main() { |
| 8 | TestWidgetsFlutterBinding.ensureInitialized(); |
| 9 | const channel = MethodChannel('lifeguide/local_reminders'); |
| 10 | const owner = '11111111-1111-4111-8111-111111111111', |
| 11 | item = '22222222-2222-4222-8222-222222222222'; |
| 12 | const scope = 'https://fixture.invalid/api|$owner'; |
| 13 | final now = DateTime.utc(2026, 10, 18, 8); |
| 14 | final calls = <MethodCall>[]; |
| 15 | late AndroidLocalReminderPort port; |
| 16 | LocalReminder row( |
| 17 | {String id = item, |
| 18 | String ownerId = owner, |
| 19 | bool ack = true, |
| 20 | bool pending = false, |
| 21 | DateTime? at, |
| 22 | String name = 'همراه من'}) => |
| 23 | LocalReminder( |
| 24 | id: id, |
| 25 | planItemId: item, |
| 26 | scheduledAt: at ?? now.add(const Duration(hours: 1)), |
| 27 | companionName: name, |
| 28 | ownerUserId: ownerId, |
| 29 | serverAcknowledged: ack, |
| 30 | pendingMutation: pending); |
| 31 | setUp(() { |
| 32 | debugDefaultTargetPlatformOverride = TargetPlatform.android; |
| 33 | calls.clear(); |
| 34 | port = AndroidLocalReminderPort(now: () => now); |
| 35 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 36 | .setMockMethodCallHandler(channel, (call) async { |
| 37 | calls.add(call); |
| 38 | if (['status', 'requestPermission', 'requestExactAlarmAccess'] |
| 39 | .contains(call.method)) { |
| 40 | return { |
| 41 | 'supported': true, |
| 42 | 'permissionGranted': true, |
| 43 | 'active': true, |
| 44 | 'scheduledCount': 1, |
| 45 | 'timing': 'exact', |
| 46 | 'activeScope': scope, |
| 47 | 'validUntilEpochMs': |
| 48 | now.add(const Duration(hours: 24)).millisecondsSinceEpoch, |
| 49 | 'exactAlarmSupported': true, |
| 50 | 'canScheduleExactAlarms': true |
| 51 | }; |
| 52 | } |
| 53 | return true; |
| 54 | }); |
| 55 | }); |
| 56 | tearDown(() { |
| 57 | debugDefaultTargetPlatformOverride = null; |
| 58 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 59 | .setMockMethodCallHandler(channel, null); |
| 60 | }); |
| 61 | test('foreign pending and unacknowledged records never reach native alarms', |
| 62 | () async { |
| 63 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 64 | for (final unsafe in [ |
| 65 | row(ownerId: '33333333-3333-4333-8333-333333333333'), |
| 66 | row(ack: false), |
| 67 | row(pending: true) |
| 68 | ]) { |
| 69 | await expectLater(port.replace(scope, [unsafe], currentUserId: owner), |
| 70 | throwsArgumentError); |
| 71 | } |
| 72 | expect(calls.map((x) => x.method), ['activate']); |
| 73 | }); |
| 74 | test('scope mismatch cannot replace reminders', () async { |
| 75 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 76 | await expectLater( |
| 77 | port.replace('other', [row()], currentUserId: owner), throwsStateError); |
| 78 | }); |
| 79 | test('native payload excludes private task text and owner metadata', |
| 80 | () async { |
| 81 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 82 | await port.replace(scope, [row()], currentUserId: owner); |
| 83 | expect(calls.last.arguments, { |
| 84 | 'scope': scope, |
| 85 | 'reminders': [ |
| 86 | { |
| 87 | 'id': item, |
| 88 | 'planItemId': item, |
| 89 | 'scheduledAtEpochMs': |
| 90 | now.add(const Duration(hours: 1)).millisecondsSinceEpoch, |
| 91 | 'companionName': 'همراه من' |
| 92 | } |
| 93 | ] |
| 94 | }); |
| 95 | }); |
| 96 | test('past and beyond-lease records are dropped', () async { |
| 97 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 98 | await port.replace( |
| 99 | scope, |
| 100 | [ |
| 101 | row(at: now.subtract(const Duration(seconds: 1))), |
| 102 | row( |
| 103 | id: '44444444-4444-4444-8444-444444444444', |
| 104 | at: now.add(const Duration(hours: 25))) |
| 105 | ], |
| 106 | currentUserId: owner); |
| 107 | expect((calls.last.arguments as Map)['reminders'], isEmpty); |
| 108 | }); |
| 109 | test('lease duplicates and control characters fail closed', () async { |
| 110 | await expectLater( |
| 111 | port.activate(scope, validUntil: now.add(const Duration(hours: 25))), |
| 112 | throwsArgumentError); |
| 113 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 114 | await expectLater(port.replace(scope, [row(), row()], currentUserId: owner), |
| 115 | throwsArgumentError); |
| 116 | await expectLater( |
| 117 | port.replace(scope, [row(name: 'bad\nname')], currentUserId: owner), |
| 118 | throwsArgumentError); |
| 119 | }); |
| 120 | test('forty joined emoji fit nickname limit but forty-one do not', () async { |
| 121 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 122 | final name = List.filled(40, '👩🔬').join(); |
| 123 | await port.replace(scope, [row(name: name)], currentUserId: owner); |
| 124 | await expectLater( |
| 125 | port.replace(scope, [row(name: '$name!')], currentUserId: owner), |
| 126 | throwsArgumentError); |
| 127 | }); |
| 128 | test('logout invalidates queued replacement before channel call', () async { |
| 129 | final entered = Completer<void>(), release = Completer<void>(); |
| 130 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 131 | .setMockMethodCallHandler(channel, (call) async { |
| 132 | calls.add(call); |
| 133 | if (call.method == 'activate') { |
| 134 | entered.complete(); |
| 135 | await release.future; |
| 136 | } |
| 137 | return true; |
| 138 | }); |
| 139 | final activating = |
| 140 | port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 141 | await entered.future.timeout(const Duration(seconds: 1)); |
| 142 | final replacing = port.replace(scope, [row()], currentUserId: owner); |
| 143 | final deactivating = port.deactivate(); |
| 144 | release.complete(); |
| 145 | await Future.wait([activating, replacing, deactivating]); |
| 146 | expect(calls.map((x) => x.method), ['activate', 'deactivate']); |
| 147 | }); |
| 148 | test('offline suppression is scoped and opaque', () async { |
| 149 | await port.activate(scope, validUntil: now.add(const Duration(hours: 24))); |
| 150 | await port.suppressPlanItems(scope, {item}); |
| 151 | expect(calls.last.method, 'suppressPlanItems'); |
| 152 | expect(calls.last.arguments, { |
| 153 | 'scope': scope, |
| 154 | 'planItemIds': [item] |
| 155 | }); |
| 156 | await expectLater( |
| 157 | port.suppressPlanItems('other', {item}), throwsStateError); |
| 158 | await expectLater( |
| 159 | port.suppressPlanItems(scope, {'invalid'}), throwsArgumentError); |
| 160 | }); |
| 161 | test('notification and exact-alarm permissions are separate user actions', |
| 162 | () async { |
| 163 | expect(calls, isEmpty); |
| 164 | final normal = await port.requestPermission(); |
| 165 | expect(calls.last.method, 'requestPermission'); |
| 166 | expect(normal.activeScope, scope); |
| 167 | expect(normal.validUntil, now.add(const Duration(hours: 24))); |
| 168 | final exact = await port.requestExactAlarmAccess(); |
| 169 | expect(calls.last.method, 'requestExactAlarmAccess'); |
| 170 | expect(exact.canScheduleExactAlarms, isTrue); |
| 171 | expect(exact.timing, 'exact'); |
| 172 | }); |
| 173 | test('missing plugin never claims background support', () async { |
| 174 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 175 | .setMockMethodCallHandler(channel, null); |
| 176 | expect((await port.status()).supported, isFalse); |
| 177 | await port.deactivate(); |
| 178 | }); |
| 179 | test('non-Android fallback never calls native scheduling', () async { |
| 180 | debugDefaultTargetPlatformOverride = TargetPlatform.iOS; |
| 181 | expect((await port.status()).supported, isFalse); |
| 182 | await port.activate(scope, validUntil: now.add(const Duration(hours: 1))); |
| 183 | await port.replace(scope, [row()], currentUserId: owner); |
| 184 | await port.deactivate(); |
| 185 | expect(calls, isEmpty); |
| 186 | }); |
| 187 | } |