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:convert'; |
| 2 | |
| 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter/services.dart'; |
| 5 | import 'package:flutter_test/flutter_test.dart'; |
| 6 | import 'package:lifemate/api.dart'; |
| 7 | import 'package:lifemate/planner_series.dart'; |
| 8 | import 'package:lifemate/planner_series_ui.dart'; |
| 9 | |
| 10 | void main() { |
| 11 | setUpAll(() async { |
| 12 | await (FontLoader('LifeGuidePersian') |
| 13 | ..addFont(rootBundle.load('assets/fonts/LifeGuidePersian.ttf'))) |
| 14 | .load(); |
| 15 | }); |
| 16 | |
| 17 | Future<void> open( |
| 18 | WidgetTester tester, |
| 19 | Future<PlannerSeriesOutcome> Function(Map<String, dynamic>, {String? id}) |
| 20 | create, { |
| 21 | ValueChanged<PlannerSeriesOutcome?>? onClosed, |
| 22 | Size size = const Size(390, 844), |
| 23 | double textScale = 1, |
| 24 | DateTime? initialDate, |
| 25 | }) async { |
| 26 | tester.view.physicalSize = size; |
| 27 | tester.view.devicePixelRatio = 1; |
| 28 | addTearDown(tester.view.resetPhysicalSize); |
| 29 | addTearDown(tester.view.resetDevicePixelRatio); |
| 30 | await tester.pumpWidget(MaterialApp( |
| 31 | theme: ThemeData(fontFamily: 'LifeGuidePersian'), |
| 32 | builder: (context, child) => MediaQuery( |
| 33 | data: MediaQuery.of(context) |
| 34 | .copyWith(textScaler: TextScaler.linear(textScale)), |
| 35 | child: child!, |
| 36 | ), |
| 37 | home: Builder(builder: (context) { |
| 38 | return Scaffold( |
| 39 | body: TextButton( |
| 40 | child: const Text('افزودن'), |
| 41 | onPressed: () async { |
| 42 | final result = await showDialog<PlannerSeriesOutcome>( |
| 43 | context: context, |
| 44 | builder: (_) => Directionality( |
| 45 | textDirection: TextDirection.rtl, |
| 46 | child: PlannerSeriesDialog( |
| 47 | api: HttpIdentityApi(baseUrl: 'https://example.invalid'), |
| 48 | initialDate: initialDate ?? DateTime(2026, 10, 19), |
| 49 | clock: () => DateTime.utc(2026, 10, 18, 12), |
| 50 | onCreate: create, |
| 51 | ), |
| 52 | ), |
| 53 | ); |
| 54 | onClosed?.call(result); |
| 55 | }, |
| 56 | ), |
| 57 | ); |
| 58 | }), |
| 59 | )); |
| 60 | await tester.tap(find.text('افزودن')); |
| 61 | await tester.pumpAndSettle(); |
| 62 | } |
| 63 | |
| 64 | Future<void> tapVisible(WidgetTester tester, Finder target) async { |
| 65 | FocusManager.instance.primaryFocus?.unfocus(); |
| 66 | await tester.pumpAndSettle(); |
| 67 | await tester.ensureVisible(target); |
| 68 | await tester.pumpAndSettle(); |
| 69 | await tester.tap(target); |
| 70 | await tester.pumpAndSettle(); |
| 71 | } |
| 72 | |
| 73 | testWidgets('empty title never submits a recurring plan', (tester) async { |
| 74 | var submitted = 0; |
| 75 | await open(tester, (payload, {id}) async { |
| 76 | submitted++; |
| 77 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 78 | }); |
| 79 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 80 | await tester.pumpAndSettle(); |
| 81 | expect(find.text('عنوان را وارد کن.'), findsOneWidget); |
| 82 | expect(submitted, 0); |
| 83 | }); |
| 84 | |
| 85 | testWidgets('weekly selected days retain independent time slots and privacy', |
| 86 | (tester) async { |
| 87 | Map<String, dynamic>? submitted; |
| 88 | PlannerSeriesOutcome? result; |
| 89 | await open(tester, (payload, {id}) async { |
| 90 | submitted = jsonDecode(jsonEncode(payload)) as Map<String, dynamic>; |
| 91 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 92 | }, onClosed: (value) => result = value); |
| 93 | await tester.enterText( |
| 94 | find.byKey(const ValueKey('series-title')), 'برنامهٔ تمرینی ساختگی'); |
| 95 | await tapVisible(tester, find.byKey(const ValueKey('series-weekday-6'))); |
| 96 | await tapVisible(tester, find.byKey(const ValueKey('series-day-6-end'))); |
| 97 | final timeFields = find.descendant( |
| 98 | of: find.byType(TimePickerDialog), matching: find.byType(TextField)); |
| 99 | await tester.enterText(timeFields.at(0), '10'); |
| 100 | await tester.enterText(timeFields.at(1), '30'); |
| 101 | await tester.tap(find.text('OK')); |
| 102 | await tester.pumpAndSettle(); |
| 103 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 104 | await tester.pumpAndSettle(); |
| 105 | expect(submitted!['timezone'], 'Asia/Tehran'); |
| 106 | expect(submitted!['startsOn'], '2026-10-19'); |
| 107 | expect(submitted!['frequency'], 'weekly'); |
| 108 | expect(submitted!['intervalDays'], 1); |
| 109 | expect(submitted!['slots'], [ |
| 110 | {'weekday': 1, 'start': '08:00', 'end': '09:00'}, |
| 111 | {'weekday': 6, 'start': '08:00', 'end': '10:30'}, |
| 112 | ]); |
| 113 | expect(submitted!.containsKey('visibility'), isFalse); |
| 114 | expect(submitted!.containsKey('familyId'), isFalse); |
| 115 | expect(result?.queued, isFalse); |
| 116 | expect(result?.id, matches(RegExp(r'^[a-f0-9-]{36}$'))); |
| 117 | expect(tester.takeException(), isNull); |
| 118 | }); |
| 119 | |
| 120 | testWidgets('daily alternate schedule omits weekdays and accepts reminders', |
| 121 | (tester) async { |
| 122 | Map<String, dynamic>? submitted; |
| 123 | await open(tester, (payload, {id}) async { |
| 124 | submitted = payload; |
| 125 | return PlannerSeriesOutcome(queued: true, id: id!); |
| 126 | }); |
| 127 | await tester.enterText( |
| 128 | find.byKey(const ValueKey('series-title')), 'کار روزدرمیان ساختگی'); |
| 129 | await tapVisible(tester, find.byKey(const ValueKey('series-frequency'))); |
| 130 | await tester.tap(find.text('روزانه').last); |
| 131 | await tester.pumpAndSettle(); |
| 132 | await tapVisible(tester, find.byKey(const ValueKey('series-interval'))); |
| 133 | await tester.tap(find.text('یک روز در میان').last); |
| 134 | await tester.pumpAndSettle(); |
| 135 | await tapVisible(tester, find.byKey(const ValueKey('series-reminder'))); |
| 136 | await tester.tap(find.text('۱۰ دقیقه پیش از شروع').last); |
| 137 | await tester.pumpAndSettle(); |
| 138 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 139 | await tester.pumpAndSettle(); |
| 140 | expect(submitted!['frequency'], 'daily'); |
| 141 | expect(submitted!['intervalDays'], 2); |
| 142 | expect(submitted!['slots'], [ |
| 143 | {'start': '08:00', 'end': '09:00'} |
| 144 | ]); |
| 145 | expect(submitted!['reminderMinutes'], [10]); |
| 146 | expect(find.byType(PlannerSeriesDialog), findsNothing); |
| 147 | }); |
| 148 | |
| 149 | testWidgets( |
| 150 | 'unknown response freezes every control and retries exact request', |
| 151 | (tester) async { |
| 152 | final payloads = <String>[]; |
| 153 | final ids = <String?>[]; |
| 154 | await open(tester, (payload, {id}) async { |
| 155 | payloads.add(jsonEncode(payload)); |
| 156 | ids.add(id); |
| 157 | if (ids.length == 1) throw const ApiException(500, 'unknown_response'); |
| 158 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 159 | }); |
| 160 | await tester.enterText( |
| 161 | find.byKey(const ValueKey('series-title')), 'درخواست با پاسخ نامعلوم'); |
| 162 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 163 | await tester.pumpAndSettle(); |
| 164 | expect( |
| 165 | tester |
| 166 | .widget<TextField>(find.byKey(const ValueKey('series-title'))) |
| 167 | .enabled, |
| 168 | isFalse); |
| 169 | expect( |
| 170 | tester |
| 171 | .widget<DropdownButtonFormField<String>>( |
| 172 | find.byKey(const ValueKey('series-frequency'))) |
| 173 | .onChanged, |
| 174 | isNull); |
| 175 | expect( |
| 176 | tester |
| 177 | .widget<OutlinedButton>( |
| 178 | find.byKey(const ValueKey('series-start-date'))) |
| 179 | .onPressed, |
| 180 | isNull); |
| 181 | expect( |
| 182 | tester |
| 183 | .widget<CheckboxListTile>( |
| 184 | find.byKey(const ValueKey('series-has-end'))) |
| 185 | .onChanged, |
| 186 | isNull); |
| 187 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 188 | await tester.pumpAndSettle(); |
| 189 | expect(ids, hasLength(2)); |
| 190 | expect(ids[0], ids[1]); |
| 191 | expect(payloads[0], payloads[1]); |
| 192 | }); |
| 193 | |
| 194 | testWidgets('same-day end must follow start and no day means no submission', |
| 195 | (tester) async { |
| 196 | var submitted = 0; |
| 197 | await open(tester, (payload, {id}) async { |
| 198 | submitted++; |
| 199 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 200 | }); |
| 201 | await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه'); |
| 202 | await tapVisible(tester, find.byKey(const ValueKey('series-day-1-end'))); |
| 203 | final timeFields = find.descendant( |
| 204 | of: find.byType(TimePickerDialog), matching: find.byType(TextField)); |
| 205 | await tester.enterText(timeFields.at(0), '08'); |
| 206 | await tester.enterText(timeFields.at(1), '00'); |
| 207 | await tester.tap(find.text('OK')); |
| 208 | await tester.pumpAndSettle(); |
| 209 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 210 | await tester.pumpAndSettle(); |
| 211 | expect(find.text('پایان هر نوبت باید پس از شروع و در همان روز باشد.'), |
| 212 | findsOneWidget); |
| 213 | await tapVisible(tester, find.byKey(const ValueKey('series-weekday-1'))); |
| 214 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 215 | await tester.pumpAndSettle(); |
| 216 | expect(find.text('دستکم یک روز هفته را انتخاب کن.'), findsOneWidget); |
| 217 | expect(submitted, 0); |
| 218 | }); |
| 219 | |
| 220 | testWidgets('terminal rejection keeps identity and offers queue recovery', |
| 221 | (tester) async { |
| 222 | await open(tester, (payload, {id}) async { |
| 223 | throw const ApiException(409, 'version_conflict'); |
| 224 | }); |
| 225 | await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه'); |
| 226 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 227 | await tester.pumpAndSettle(); |
| 228 | expect(find.text('بررسی تغییرات در انتظار'), findsOneWidget); |
| 229 | expect( |
| 230 | tester |
| 231 | .widget<FilledButton>(find.byKey(const ValueKey('series-save'))) |
| 232 | .onPressed, |
| 233 | isNull); |
| 234 | expect(find.textContaining('شناسهٔ تازه نساز'), findsOneWidget); |
| 235 | }); |
| 236 | |
| 237 | testWidgets( |
| 238 | 'form scrolls at 320 pixels and 200 percent text without overflow', |
| 239 | (tester) async { |
| 240 | await open(tester, (payload, {id}) async { |
| 241 | return PlannerSeriesOutcome(queued: true, id: id!); |
| 242 | }, size: const Size(320, 740), textScale: 2); |
| 243 | await tapVisible(tester, find.byKey(const ValueKey('series-has-end'))); |
| 244 | expect(find.byKey(const ValueKey('series-end-date')), findsOneWidget); |
| 245 | await tapVisible(tester, find.byKey(const ValueKey('series-weekday-6'))); |
| 246 | await tester.ensureVisible(find.byKey(const ValueKey('series-reminder'))); |
| 247 | await tester.pumpAndSettle(); |
| 248 | expect(tester.takeException(), isNull); |
| 249 | expect(find.byKey(const ValueKey('series-save')).hitTestable(), |
| 250 | findsOneWidget); |
| 251 | expect(tester.getSize(find.byKey(const ValueKey('series-save'))).height, |
| 252 | greaterThanOrEqualTo(48)); |
| 253 | }); |
| 254 | |
| 255 | testWidgets('unsupported start stays visible and cannot be submitted', |
| 256 | (tester) async { |
| 257 | final today = DateTime(2026, 10, 18); |
| 258 | final unsupported = today.add(const Duration(days: 800)); |
| 259 | var submitted = 0; |
| 260 | await open(tester, (payload, {id}) async { |
| 261 | submitted++; |
| 262 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 263 | }, initialDate: unsupported); |
| 264 | await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه'); |
| 265 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 266 | await tester.pumpAndSettle(); |
| 267 | expect(find.text('تاریخ شروع باید در بازهٔ مجاز دو ساله باشد.'), |
| 268 | findsOneWidget); |
| 269 | expect(submitted, 0); |
| 270 | await tapVisible(tester, find.byKey(const ValueKey('series-start-date'))); |
| 271 | final picker = |
| 272 | tester.widget<DatePickerDialog>(find.byType(DatePickerDialog)); |
| 273 | expect(picker.firstDate, today.subtract(const Duration(days: 729))); |
| 274 | expect(picker.lastDate, today.add(const Duration(days: 729))); |
| 275 | expect(picker.initialDate, picker.lastDate); |
| 276 | await tester.tap(find.text('Cancel')); |
| 277 | await tester.pumpAndSettle(); |
| 278 | expect(find.textContaining('${unsupported.year}-'), findsOneWidget); |
| 279 | expect(tester.takeException(), isNull); |
| 280 | }); |
| 281 | |
| 282 | testWidgets('optional end beyond horizon is rejected before enqueue', |
| 283 | (tester) async { |
| 284 | final today = DateTime(2026, 10, 18); |
| 285 | var submitted = 0; |
| 286 | await open(tester, (payload, {id}) async { |
| 287 | submitted++; |
| 288 | return PlannerSeriesOutcome(queued: false, id: id!); |
| 289 | }, initialDate: today.add(const Duration(days: 720))); |
| 290 | await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه'); |
| 291 | await tapVisible(tester, find.byKey(const ValueKey('series-has-end'))); |
| 292 | await tester.tap(find.byKey(const ValueKey('series-save'))); |
| 293 | await tester.pumpAndSettle(); |
| 294 | expect(find.text('تاریخ پایان باید در بازهٔ مجاز دو ساله باشد.'), |
| 295 | findsOneWidget); |
| 296 | expect(submitted, 0); |
| 297 | await tapVisible(tester, find.byKey(const ValueKey('series-end-date'))); |
| 298 | final picker = |
| 299 | tester.widget<DatePickerDialog>(find.byType(DatePickerDialog)); |
| 300 | expect(picker.firstDate, today.subtract(const Duration(days: 729))); |
| 301 | expect(picker.lastDate, today.add(const Duration(days: 729))); |
| 302 | expect(picker.initialDate, picker.lastDate); |
| 303 | expect(tester.takeException(), isNull); |
| 304 | }); |
| 305 | } |