LifeMate — Personal, Family & Learning Companion
fix/local-task-persistence
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 'dart:convert'; |
| 3 | |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_test/flutter_test.dart'; |
| 6 | import 'package:lifemate/api.dart'; |
| 7 | import 'package:lifemate/local_data_store.dart'; |
| 8 | import 'package:lifemate/local_only_api.dart'; |
| 9 | import 'package:lifemate/main.dart'; |
| 10 | import 'package:lifemate/phase3_ui.dart'; |
| 11 | import 'package:shared_preferences/shared_preferences.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 | |
| 15 | import 'app_test.dart' show FakeApi; |
| 16 | import 'local_test_preferences.dart' show resetNativeLocalWriteGuard; |
| 17 | |
| 18 | // This simulates the preferences plugin boundary, not Android process restart. |
| 19 | final class _ControlledWrites extends InMemorySharedPreferencesAsync { |
| 20 | _ControlledWrites(super.data) : super.withData(); |
| 21 | bool failWrites = false; |
| 22 | Completer<void>? pendingWrite; |
| 23 | |
| 24 | @override |
| 25 | Future<bool> setString( |
| 26 | String key, String value, SharedPreferencesOptions options) async { |
| 27 | if (pendingWrite != null) await pendingWrite!.future; |
| 28 | if (failWrites) throw StateError('simulated persistent storage failure'); |
| 29 | return super.setString(key, value, options); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | late LocalDataSession _testSession; |
| 34 | const _restartMessage = |
| 35 | 'وضعیت ذخیره نامشخص است. برنامه را از تنظیمات دستگاه «توقف اجباری» کن و دوباره باز کن.'; |
| 36 | |
| 37 | LocalOnlyApi _open( |
| 38 | {String category = 'girl_minor', LocalDataSession? session}) => |
| 39 | LocalOnlyApi( |
| 40 | category: category, |
| 41 | displayName: 'آرام مهرآیین', |
| 42 | store: LocalDataStore( |
| 43 | category: category, |
| 44 | displayName: 'آرام مهرآیین', |
| 45 | session: session ?? _testSession), |
| 46 | ); |
| 47 | |
| 48 | // This inspects the simulated native snapshot independently of a poisoned API. |
| 49 | Future<Map<String, dynamic>> _nativeSnapshot() async => |
| 50 | jsonDecode((await SharedPreferencesAsync().getString(LocalDataStore.key))!) |
| 51 | as Map<String, dynamic>; |
| 52 | |
| 53 | Future<LocalOnlyApi> _restartProcessMock() async { |
| 54 | // This plugin mock fails before publishing, so its snapshot is confirmed disk. |
| 55 | // Replace both native process state and the preferences adapter explicitly. |
| 56 | final raw = await SharedPreferencesAsync().getString(LocalDataStore.key); |
| 57 | resetNativeLocalWriteGuard(); |
| 58 | SharedPreferencesAsyncPlatform.instance = |
| 59 | _ControlledWrites({if (raw != null) LocalDataStore.key: raw}); |
| 60 | return _open(session: LocalDataSession()); |
| 61 | } |
| 62 | |
| 63 | Future<void> _expectRestartRequired(Future<Object?> operation) async { |
| 64 | await expectLater( |
| 65 | operation, |
| 66 | throwsA(isA<ApiException>().having( |
| 67 | (error) => error.code, |
| 68 | 'code', |
| 69 | 'local_storage_restart_required', |
| 70 | ))); |
| 71 | } |
| 72 | |
| 73 | Future<_ControlledWrites> _controlWrites( |
| 74 | WidgetTester tester, LocalOnlyApi api) async { |
| 75 | await api.getProfile(); |
| 76 | return SharedPreferencesAsyncPlatform.instance! as _ControlledWrites; |
| 77 | } |
| 78 | |
| 79 | class _RoleChangingApi extends FakeApi { |
| 80 | String currentRole = 'teen_minor'; |
| 81 | |
| 82 | @override |
| 83 | Future<List<Map<String, dynamic>>> listFamilies() async => [ |
| 84 | {'id': 'family-1', 'name': 'خانواده', 'role': currentRole}, |
| 85 | ]; |
| 86 | } |
| 87 | |
| 88 | class _ProductionItemApi extends FakeApi { |
| 89 | @override |
| 90 | Future<List<Map<String, dynamic>>> listPlanItems({ |
| 91 | DateTime? from, |
| 92 | DateTime? to, |
| 93 | String? kind, |
| 94 | }) async => |
| 95 | [ |
| 96 | {'id': 'server-item', 'kind': 'task', 'title': 'کار سرور'}, |
| 97 | ]; |
| 98 | } |
| 99 | |
| 100 | Future<void> _planner(WidgetTester tester, LocalOnlyApi api) async { |
| 101 | await tester.pumpWidget(MaterialApp( |
| 102 | key: UniqueKey(), |
| 103 | home: Scaffold(body: PlannerPage(api: api, localOnly: true)), |
| 104 | )); |
| 105 | await tester.pumpAndSettle(); |
| 106 | } |
| 107 | |
| 108 | Future<void> _createForm(WidgetTester tester, |
| 109 | {String title = 'تمرین ریاضی'}) async { |
| 110 | await tester.tap(find.text('جدید')); |
| 111 | await tester.pumpAndSettle(); |
| 112 | await tester.enterText(find.byKey(const Key('plan-title')), title); |
| 113 | } |
| 114 | |
| 115 | Future<void> _itemMenu(WidgetTester tester, String action) async { |
| 116 | await tester.tap(find.byType(PopupMenuButton<String>)); |
| 117 | await tester.pumpAndSettle(); |
| 118 | await tester.tap(find.text(action)); |
| 119 | await tester.pumpAndSettle(); |
| 120 | } |
| 121 | |
| 122 | void _localWidgetTest(String name, Future<void> Function(WidgetTester) body) { |
| 123 | testWidgets(name, (tester) async { |
| 124 | await tester.runAsync(() => body(tester)); |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | void main() { |
| 129 | setUp(() { |
| 130 | resetNativeLocalWriteGuard(); |
| 131 | _testSession = LocalDataSession(); |
| 132 | SharedPreferences.setMockInitialValues({}); |
| 133 | SharedPreferencesAsyncPlatform.instance = _ControlledWrites({}); |
| 134 | }); |
| 135 | |
| 136 | test('restart-required storage errors describe full process recovery', () { |
| 137 | expect( |
| 138 | localDataErrorText( |
| 139 | const ApiException(500, 'local_storage_restart_required')), |
| 140 | _restartMessage); |
| 141 | }); |
| 142 | |
| 143 | _localWidgetTest('saved assignment survives recreated planner UI', |
| 144 | (tester) async { |
| 145 | await _planner(tester, _open()); |
| 146 | await _createForm(tester); |
| 147 | await tester.tap(find.byKey(const Key('plan-kind'))); |
| 148 | await tester.pumpAndSettle(); |
| 149 | await tester.tap(find.text('تکلیف').last); |
| 150 | await tester.pumpAndSettle(); |
| 151 | await tester.tap(find.text('ذخیره')); |
| 152 | await tester.pumpAndSettle(); |
| 153 | |
| 154 | await _planner(tester, _open()); |
| 155 | expect(find.text('تمرین ریاضی'), findsOneWidget); |
| 156 | expect((await _open().listPlanItems()).single['kind'], 'assignment'); |
| 157 | }); |
| 158 | |
| 159 | _localWidgetTest('planner requires a title before saving', (tester) async { |
| 160 | await _planner(tester, _open()); |
| 161 | await _createForm(tester, title: ' '); |
| 162 | await tester.tap(find.text('ذخیره')); |
| 163 | await tester.pumpAndSettle(); |
| 164 | |
| 165 | expect(find.text('عنوان را وارد کن.'), findsOneWidget); |
| 166 | expect(await _open().listPlanItems(), isEmpty); |
| 167 | }); |
| 168 | |
| 169 | _localWidgetTest('local planner keeps older and future saved items visible', |
| 170 | (tester) async { |
| 171 | await _open().createPlanItem({ |
| 172 | 'kind': 'assignment', |
| 173 | 'title': 'تکلیف قبلی', |
| 174 | 'dueAt': DateTime.now() |
| 175 | .subtract(const Duration(days: 40)) |
| 176 | .toUtc() |
| 177 | .toIso8601String(), |
| 178 | }); |
| 179 | await _open().createPlanItem({ |
| 180 | 'kind': 'task', |
| 181 | 'title': 'کار آینده', |
| 182 | 'dueAt': DateTime.now() |
| 183 | .add(const Duration(days: 40)) |
| 184 | .toUtc() |
| 185 | .toIso8601String(), |
| 186 | }); |
| 187 | await _planner(tester, _open()); |
| 188 | |
| 189 | expect(find.text('تکلیف قبلی'), findsOneWidget); |
| 190 | expect(find.text('کار آینده'), findsOneWidget); |
| 191 | }); |
| 192 | |
| 193 | _localWidgetTest('edited title survives recreated planner UI', |
| 194 | (tester) async { |
| 195 | await _open().createPlanItem({ |
| 196 | 'kind': 'assignment', |
| 197 | 'title': 'تمرین ریاضی', |
| 198 | 'dueAt': DateTime.now().toUtc().toIso8601String(), |
| 199 | }); |
| 200 | await _planner(tester, _open()); |
| 201 | await _itemMenu(tester, 'ویرایش عنوان'); |
| 202 | await tester.enterText(find.byKey(const Key('plan-title')), 'تمرین علوم'); |
| 203 | await tester.tap(find.text('ذخیره')); |
| 204 | await tester.pumpAndSettle(); |
| 205 | |
| 206 | await _planner(tester, _open()); |
| 207 | expect(find.text('تمرین علوم'), findsOneWidget); |
| 208 | expect(find.text('تمرین ریاضی'), findsNothing); |
| 209 | }); |
| 210 | |
| 211 | _localWidgetTest('archive requires confirmation and survives recreated UI', |
| 212 | (tester) async { |
| 213 | await _open().createPlanItem({ |
| 214 | 'kind': 'assignment', |
| 215 | 'title': 'تمرین ریاضی', |
| 216 | 'dueAt': DateTime.now().toUtc().toIso8601String(), |
| 217 | }); |
| 218 | await _planner(tester, _open()); |
| 219 | await _itemMenu(tester, 'بایگانی'); |
| 220 | expect(find.text('بایگانی مورد'), findsOneWidget); |
| 221 | await tester.tap(find.text('انصراف')); |
| 222 | await tester.pumpAndSettle(); |
| 223 | expect(find.text('تمرین ریاضی'), findsOneWidget); |
| 224 | |
| 225 | await _itemMenu(tester, 'بایگانی'); |
| 226 | await tester.tap(find.widgetWithText(FilledButton, 'بایگانی')); |
| 227 | await tester.pumpAndSettle(); |
| 228 | await _planner(tester, _open()); |
| 229 | expect(find.text('تمرین ریاضی'), findsNothing); |
| 230 | await tester.pumpWidget(MaterialApp( |
| 231 | home: Scaffold(body: TodayPage(api: _open(), localOnly: true)), |
| 232 | )); |
| 233 | await tester.pumpAndSettle(); |
| 234 | expect(find.text('تمرین ریاضی'), findsNothing); |
| 235 | }); |
| 236 | |
| 237 | _localWidgetTest( |
| 238 | 'uncertain local save needs full process restart without sync queue', |
| 239 | (tester) async { |
| 240 | final api = _open(); |
| 241 | final platform = await _controlWrites(tester, api); |
| 242 | await _planner(tester, api); |
| 243 | platform.failWrites = true; |
| 244 | await _createForm(tester); |
| 245 | await tester.tap(find.text('ذخیره')); |
| 246 | await tester.pumpAndSettle(); |
| 247 | |
| 248 | expect(tester.takeException(), isNull); |
| 249 | expect(find.text(_restartMessage), findsOneWidget); |
| 250 | expect(find.byType(AlertDialog), findsOneWidget); |
| 251 | expect((await _nativeSnapshot())['items'], isEmpty); |
| 252 | await _expectRestartRequired(_open().listPlanItems()); |
| 253 | expect( |
| 254 | (await SharedPreferences.getInstance()) |
| 255 | .containsKey('phase3.sync.queue'), |
| 256 | isFalse); |
| 257 | |
| 258 | platform.failWrites = false; |
| 259 | await tester.tap(find.text('ذخیره')); |
| 260 | await tester.pumpAndSettle(); |
| 261 | expect(find.text(_restartMessage), findsOneWidget); |
| 262 | expect((await _nativeSnapshot())['items'], isEmpty); |
| 263 | await _expectRestartRequired(api.listPlanItems()); |
| 264 | |
| 265 | final restarted = await _restartProcessMock(); |
| 266 | expect(await restarted.listPlanItems(), isEmpty); |
| 267 | await _planner(tester, restarted); |
| 268 | await _createForm(tester); |
| 269 | await tester.tap(find.text('ذخیره')); |
| 270 | await tester.pumpAndSettle(); |
| 271 | expect((await restarted.listPlanItems()).single['title'], 'تمرین ریاضی'); |
| 272 | }); |
| 273 | |
| 274 | _localWidgetTest('save button stays disabled until durable write completes', |
| 275 | (tester) async { |
| 276 | final api = _open(); |
| 277 | final platform = await _controlWrites(tester, api); |
| 278 | await _planner(tester, api); |
| 279 | await _createForm(tester); |
| 280 | platform.pendingWrite = Completer<void>(); |
| 281 | await tester.tap(find.text('ذخیره')); |
| 282 | await tester.pump(); |
| 283 | |
| 284 | final button = tester.widget<FilledButton>( |
| 285 | find.widgetWithText(FilledButton, 'در حال ذخیره...'), |
| 286 | ); |
| 287 | expect(button.onPressed, isNull); |
| 288 | platform.pendingWrite!.complete(); |
| 289 | platform.pendingWrite = null; |
| 290 | await tester.pumpAndSettle(); |
| 291 | expect(await _open().listPlanItems(), hasLength(1)); |
| 292 | }); |
| 293 | |
| 294 | _localWidgetTest( |
| 295 | 'uncertain Today completion stays visible without server cache or queue', |
| 296 | (tester) async { |
| 297 | final api = _open(); |
| 298 | await api.createPlanItem({ |
| 299 | 'kind': 'assignment', |
| 300 | 'title': 'تمرین ریاضی', |
| 301 | 'dueAt': DateTime.now().toUtc().toIso8601String(), |
| 302 | }); |
| 303 | final platform = await _controlWrites(tester, api); |
| 304 | const serverCache = '[{"id":"server-item","title":"نسخه سرور"}]'; |
| 305 | SharedPreferences.setMockInitialValues({'phase3.today.cache': serverCache}); |
| 306 | await tester.pumpWidget(MaterialApp( |
| 307 | home: Scaffold(body: TodayPage(api: api, localOnly: true)), |
| 308 | )); |
| 309 | await tester.pumpAndSettle(); |
| 310 | expect(find.text('تمرین ریاضی'), findsOneWidget); |
| 311 | expect(find.text('نسخه سرور'), findsNothing); |
| 312 | platform.failWrites = true; |
| 313 | await tester.tap(find.byTooltip('انجام شد')); |
| 314 | await tester.pumpAndSettle(); |
| 315 | |
| 316 | expect(tester.takeException(), isNull); |
| 317 | expect(find.text(_restartMessage), findsOneWidget); |
| 318 | expect(find.text('تمرین ریاضی'), findsOneWidget); |
| 319 | final legacy = await SharedPreferences.getInstance(); |
| 320 | expect(legacy.getString('phase3.today.cache'), serverCache); |
| 321 | expect(legacy.containsKey('phase3.sync.queue'), isFalse); |
| 322 | expect(((await _nativeSnapshot())['items'] as List).single['status'], |
| 323 | 'planned'); |
| 324 | platform.failWrites = false; |
| 325 | await tester.tap(find.text('تلاش دوباره')); |
| 326 | await tester.pumpAndSettle(); |
| 327 | expect(find.text(_restartMessage), findsOneWidget); |
| 328 | expect(find.text('تمرین ریاضی'), findsOneWidget); |
| 329 | await _expectRestartRequired(api.listPlanItems()); |
| 330 | |
| 331 | final restarted = await _restartProcessMock(); |
| 332 | expect((await restarted.listPlanItems()).single['status'], 'planned'); |
| 333 | await tester.pumpWidget(MaterialApp( |
| 334 | key: UniqueKey(), |
| 335 | home: Scaffold(body: TodayPage(api: restarted, localOnly: true)), |
| 336 | )); |
| 337 | await tester.pumpAndSettle(); |
| 338 | await tester.tap(find.byTooltip('انجام شد')); |
| 339 | await tester.pumpAndSettle(); |
| 340 | expect(find.text('تمرین ریاضی'), findsNothing); |
| 341 | }); |
| 342 | |
| 343 | _localWidgetTest( |
| 344 | 'uncertain reschedule preserves confirmed data until full process restart', |
| 345 | (tester) async { |
| 346 | final api = _open(); |
| 347 | final start = DateTime.now(); |
| 348 | final due = start.add(const Duration(hours: 2)); |
| 349 | await api.createPlanItem({ |
| 350 | 'kind': 'assignment', |
| 351 | 'title': 'تمرین ریاضی', |
| 352 | 'startsAt': start.toUtc().toIso8601String(), |
| 353 | 'dueAt': due.toUtc().toIso8601String(), |
| 354 | }); |
| 355 | final platform = await _controlWrites(tester, api); |
| 356 | await _planner(tester, api); |
| 357 | platform.failWrites = true; |
| 358 | await _itemMenu(tester, 'انتقال به فردا'); |
| 359 | |
| 360 | expect(tester.takeException(), isNull); |
| 361 | expect(find.text(_restartMessage), findsOneWidget); |
| 362 | expect(((await _nativeSnapshot())['items'] as List).single['starts_at'], |
| 363 | start.toUtc().toIso8601String()); |
| 364 | expect( |
| 365 | (await SharedPreferences.getInstance()) |
| 366 | .containsKey('phase3.sync.queue'), |
| 367 | isFalse); |
| 368 | platform.failWrites = false; |
| 369 | await tester.tap(find.text('تلاش دوباره')); |
| 370 | await tester.pumpAndSettle(); |
| 371 | expect(find.text(_restartMessage), findsOneWidget); |
| 372 | await _expectRestartRequired(api.listPlanItems()); |
| 373 | |
| 374 | final restarted = await _restartProcessMock(); |
| 375 | expect((await restarted.listPlanItems()).single['starts_at'], |
| 376 | start.toUtc().toIso8601String()); |
| 377 | await _planner(tester, restarted); |
| 378 | await _itemMenu(tester, 'انتقال به فردا'); |
| 379 | final restored = (await restarted.listPlanItems()).single; |
| 380 | expect(restored['starts_at'], |
| 381 | start.add(const Duration(days: 1)).toUtc().toIso8601String()); |
| 382 | expect(restored['due_at'], |
| 383 | due.add(const Duration(days: 1)).toUtc().toIso8601String()); |
| 384 | }); |
| 385 | |
| 386 | _localWidgetTest( |
| 387 | 'local read error is visible and retries without cached server data', |
| 388 | (tester) async { |
| 389 | SharedPreferences.setMockInitialValues({ |
| 390 | 'phase3.planner.cache': jsonEncode([ |
| 391 | {'id': 'server-item', 'title': 'نسخه سرور', 'kind': 'task'}, |
| 392 | ]), |
| 393 | }); |
| 394 | await SharedPreferencesAsync().setString(LocalDataStore.key, '{invalid'); |
| 395 | await _planner(tester, _open()); |
| 396 | expect(find.textContaining('اطلاعات ذخیرهشده روی دستگاه خراب است'), |
| 397 | findsOneWidget); |
| 398 | expect(find.text('هنوز برنامهای نداری'), findsNothing); |
| 399 | expect(find.text('نسخه سرور'), findsNothing); |
| 400 | expect(find.text('جدید'), findsNothing); |
| 401 | |
| 402 | await SharedPreferencesAsync().remove(LocalDataStore.key); |
| 403 | await _open().createPlanItem({ |
| 404 | 'kind': 'task', |
| 405 | 'title': 'بعد از بازیابی', |
| 406 | 'dueAt': DateTime.now().toUtc().toIso8601String(), |
| 407 | }); |
| 408 | await tester.tap(find.text('تلاش دوباره')); |
| 409 | await tester.pumpAndSettle(); |
| 410 | expect(find.text('بعد از بازیابی'), findsOneWidget); |
| 411 | }); |
| 412 | |
| 413 | for (final category in ['girl_minor', 'boy_minor', 'adult']) { |
| 414 | _localWidgetTest('$category routes by profile category without a family', |
| 415 | (tester) async { |
| 416 | await tester.pumpWidget(MaterialApp( |
| 417 | home: HomeShell( |
| 418 | api: _open(category: category), |
| 419 | localOnly: true, |
| 420 | profileCategory: category), |
| 421 | )); |
| 422 | await tester.pumpAndSettle(); |
| 423 | expect(find.byType(NavigationDestination), findsNWidgets(3)); |
| 424 | expect(find.text('حالت محلی · فقط روی این دستگاه'), findsOneWidget); |
| 425 | expect(find.text('آرام مهرآیین'), findsOneWidget); |
| 426 | expect(find.byType(SchoolPage), findsNothing); |
| 427 | await tester |
| 428 | .tap(find.text(category == 'adult' ? 'برنامهریز' : 'برنامه')); |
| 429 | await tester.pumpAndSettle(); |
| 430 | expect(find.text(category == 'adult' ? 'برنامهریز' : 'برنامه هفتگی'), |
| 431 | findsWidgets); |
| 432 | expect(find.byType(PlannerPage), findsOneWidget); |
| 433 | }); |
| 434 | } |
| 435 | |
| 436 | _localWidgetTest('local profile exposes only name and theme editing', |
| 437 | (tester) async { |
| 438 | await tester.pumpWidget(MaterialApp( |
| 439 | home: HomeShell( |
| 440 | api: _open(), localOnly: true, profileCategory: 'girl_minor'), |
| 441 | )); |
| 442 | await tester.pumpAndSettle(); |
| 443 | await tester.tap(find.byTooltip('پروفایل')); |
| 444 | await tester.pumpAndSettle(); |
| 445 | |
| 446 | expect(find.text('آرام مهرآیین'), findsOneWidget); |
| 447 | expect(find.text('قابلیتهای غیرفعال در حالت محلی'), findsOneWidget); |
| 448 | expect(find.text('خانواده'), findsNothing); |
| 449 | expect(find.text('تغییر رمز عبور'), findsNothing); |
| 450 | }); |
| 451 | |
| 452 | _localWidgetTest( |
| 453 | 'local profile edit persists full name and theme after returning home', |
| 454 | (tester) async { |
| 455 | await tester.pumpWidget(MaterialApp( |
| 456 | home: HomeShell( |
| 457 | api: _open(), localOnly: true, profileCategory: 'girl_minor'), |
| 458 | )); |
| 459 | await tester.pumpAndSettle(); |
| 460 | await tester.tap(find.byTooltip('پروفایل')); |
| 461 | await tester.pumpAndSettle(); |
| 462 | await tester.tap(find.byIcon(Icons.edit_outlined)); |
| 463 | await tester.pumpAndSettle(); |
| 464 | await tester.enterText(find.byType(TextField), 'سارا مهرآیین'); |
| 465 | await tester.tap(find.byType(DropdownButtonFormField<String>)); |
| 466 | await tester.pumpAndSettle(); |
| 467 | await tester.tap(find.text('سفید / آبی نوجوان').last); |
| 468 | await tester.pumpAndSettle(); |
| 469 | await tester.tap(find.text('ذخیره')); |
| 470 | await tester.pumpAndSettle(); |
| 471 | await tester.pageBack(); |
| 472 | await tester.pumpAndSettle(); |
| 473 | |
| 474 | expect(find.text('سارا مهرآیین'), findsOneWidget); |
| 475 | expect(Theme.of(tester.element(find.byType(TodayPage))).colorScheme.primary, |
| 476 | ColorScheme.fromSeed(seedColor: const Color(0xFF4D86E8)).primary); |
| 477 | final restored = await _open().getProfile(); |
| 478 | expect(restored['display_name'], 'سارا مهرآیین'); |
| 479 | expect(restored['theme_preference'], 'boy_blue'); |
| 480 | }); |
| 481 | |
| 482 | _localWidgetTest( |
| 483 | 'uncertain profile save preserves old name until full process restart', |
| 484 | (tester) async { |
| 485 | final api = _open(); |
| 486 | final platform = await _controlWrites(tester, api); |
| 487 | await tester.pumpWidget(MaterialApp( |
| 488 | home: HomeShell(api: api, localOnly: true, profileCategory: 'girl_minor'), |
| 489 | )); |
| 490 | await tester.pumpAndSettle(); |
| 491 | await tester.tap(find.byTooltip('پروفایل')); |
| 492 | await tester.pumpAndSettle(); |
| 493 | await tester.tap(find.byIcon(Icons.edit_outlined)); |
| 494 | await tester.pumpAndSettle(); |
| 495 | await tester.enterText(find.byType(TextField), 'سارا مهرآیین'); |
| 496 | platform.failWrites = true; |
| 497 | await tester.tap(find.text('ذخیره')); |
| 498 | await tester.pumpAndSettle(); |
| 499 | |
| 500 | expect(tester.takeException(), isNull); |
| 501 | expect(find.text(_restartMessage), findsOneWidget); |
| 502 | expect( |
| 503 | (await _nativeSnapshot())['profile']['display_name'], 'آرام مهرآیین'); |
| 504 | await _expectRestartRequired(_open().getProfile()); |
| 505 | platform.failWrites = false; |
| 506 | await tester.tap(find.text('ذخیره')); |
| 507 | await tester.pumpAndSettle(); |
| 508 | expect(find.text(_restartMessage), findsOneWidget); |
| 509 | expect( |
| 510 | (await _nativeSnapshot())['profile']['display_name'], 'آرام مهرآیین'); |
| 511 | |
| 512 | final restarted = await _restartProcessMock(); |
| 513 | expect((await restarted.getProfile())['display_name'], 'آرام مهرآیین'); |
| 514 | }); |
| 515 | |
| 516 | _localWidgetTest('local profile cannot submit again during a durable write', |
| 517 | (tester) async { |
| 518 | final api = _open(); |
| 519 | final platform = await _controlWrites(tester, api); |
| 520 | await tester.pumpWidget(MaterialApp( |
| 521 | home: HomeShell(api: api, localOnly: true, profileCategory: 'girl_minor'), |
| 522 | )); |
| 523 | await tester.pumpAndSettle(); |
| 524 | await tester.tap(find.byTooltip('پروفایل')); |
| 525 | await tester.pumpAndSettle(); |
| 526 | await tester.tap(find.byIcon(Icons.edit_outlined)); |
| 527 | await tester.pumpAndSettle(); |
| 528 | await tester.enterText(find.byType(TextField), 'سارا مهرآیین'); |
| 529 | platform.pendingWrite = Completer<void>(); |
| 530 | await tester.tap(find.text('ذخیره')); |
| 531 | await tester.pump(); |
| 532 | |
| 533 | final button = tester.widget<FilledButton>( |
| 534 | find.widgetWithText(FilledButton, 'در حال ذخیره...'), |
| 535 | ); |
| 536 | expect(button.onPressed, isNull); |
| 537 | platform.pendingWrite!.complete(); |
| 538 | platform.pendingWrite = null; |
| 539 | await tester.pumpAndSettle(); |
| 540 | expect((await _open().getProfile())['display_name'], 'سارا مهرآیین'); |
| 541 | }); |
| 542 | |
| 543 | _localWidgetTest( |
| 544 | 'production shell keeps a valid page when family role changes', |
| 545 | (tester) async { |
| 546 | final api = _RoleChangingApi(); |
| 547 | await tester.pumpWidget(MaterialApp(home: HomeShell(api: api))); |
| 548 | await tester.pumpAndSettle(); |
| 549 | tester.firstState<ScaffoldState>(find.byType(Scaffold)).openDrawer(); |
| 550 | await tester.pumpAndSettle(); |
| 551 | await tester.tap(find.text('همراه هوشمند')); |
| 552 | await tester.pumpAndSettle(); |
| 553 | await tester.tap(find.byTooltip('پروفایل')); |
| 554 | await tester.pumpAndSettle(); |
| 555 | api.currentRole = 'parent_guardian'; |
| 556 | await tester.pageBack(); |
| 557 | await tester.pumpAndSettle(); |
| 558 | |
| 559 | expect(tester.takeException(), isNull); |
| 560 | expect(find.text('من'), findsWidgets); |
| 561 | }); |
| 562 | |
| 563 | _localWidgetTest('production planner keeps local archive action unavailable', |
| 564 | (tester) async { |
| 565 | await tester.pumpWidget(MaterialApp( |
| 566 | home: Scaffold(body: PlannerPage(api: _ProductionItemApi())), |
| 567 | )); |
| 568 | await tester.pumpAndSettle(); |
| 569 | await tester.tap(find.byType(PopupMenuButton<String>)); |
| 570 | await tester.pumpAndSettle(); |
| 571 | |
| 572 | expect(find.text('بایگانی'), findsNothing); |
| 573 | }); |
| 574 | } |