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:convert'; |
| 2 | |
| 3 | import 'package:flutter/foundation.dart'; |
| 4 | import 'package:flutter_test/flutter_test.dart'; |
| 5 | import 'package:integration_test/integration_test.dart'; |
| 6 | import 'package:lifemate/local_data_store.dart'; |
| 7 | import 'package:lifemate/local_only_api.dart'; |
| 8 | import 'package:shared_preferences/shared_preferences.dart'; |
| 9 | |
| 10 | const _phase = String.fromEnvironment('PERSISTENCE_PHASE'); |
| 11 | const _originalTitle = 'آزمون پایداری تکلیف روی دستگاه'; |
| 12 | const _editedTitle = 'آزمون پایداری تکلیف روی دستگاه - ویرایش'; |
| 13 | const _dueAt = '2030-10-15T12:00:00.000Z'; |
| 14 | const _editedNotes = 'این تغییر باید پس از توقف اجباری باقی بماند.'; |
| 15 | |
| 16 | Map<String, dynamic> _record( |
| 17 | Iterable<Map<String, dynamic>> items, |
| 18 | String title, |
| 19 | ) { |
| 20 | final matches = items.where((item) => item['title'] == title).toList(); |
| 21 | expect(matches, hasLength(1), |
| 22 | reason: 'Expected one durable test assignment.'); |
| 23 | expect(matches.single['id'], isA<String>()); |
| 24 | expect(matches.single['id'], isNotEmpty); |
| 25 | return matches.single; |
| 26 | } |
| 27 | |
| 28 | Future<Map<String, dynamic>> _readDisk() async { |
| 29 | final preferences = SharedPreferencesAsync(); |
| 30 | final raw = await preferences.getString(LocalDataStore.key); |
| 31 | expect(raw, isNotNull, |
| 32 | reason: 'The Android preference must survive restart.'); |
| 33 | final data = jsonDecode(raw!) as Map<String, dynamic>; |
| 34 | expect(data['version'], 1); |
| 35 | expect(data['items'], hasLength(1)); |
| 36 | return data; |
| 37 | } |
| 38 | |
| 39 | Iterable<Map<String, dynamic>> _savedItems(Map<String, dynamic> data) => |
| 40 | (data['items'] as List).map( |
| 41 | (item) => Map<String, dynamic>.from(item as Map), |
| 42 | ); |
| 43 | |
| 44 | Future<void> _expectEditedProfile(LocalOnlyApi api) async { |
| 45 | final profile = await api.getProfile(); |
| 46 | expect(profile['display_name'], 'سارا'); |
| 47 | expect(profile['theme_preference'], 'boy_blue'); |
| 48 | expect(profile['profile_category'], 'girl_minor'); |
| 49 | expect(api.accessToken, isNull); |
| 50 | } |
| 51 | |
| 52 | void main() { |
| 53 | IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 54 | |
| 55 | testWidgets('Android persistence phase: $_phase', (tester) async { |
| 56 | expect(defaultTargetPlatform, TargetPlatform.android); |
| 57 | expect(_phase, isIn(['create', 'update', 'archive', 'verify'])); |
| 58 | final api = LocalOnlyApi(category: 'girl_minor', displayName: 'آرام'); |
| 59 | expect(api.accessToken, isNull, |
| 60 | reason: 'Local entry has no server session.'); |
| 61 | |
| 62 | switch (_phase) { |
| 63 | case 'create': |
| 64 | final preferences = SharedPreferencesAsync(); |
| 65 | expect( |
| 66 | await preferences.containsKey(LocalDataStore.key), |
| 67 | isFalse, |
| 68 | reason: |
| 69 | 'Create must start on a fresh emulator, without clearing data.', |
| 70 | ); |
| 71 | expect(await api.listPlanItems(), isEmpty); |
| 72 | final created = await api.createPlanItem({ |
| 73 | 'kind': 'assignment', |
| 74 | 'title': _originalTitle, |
| 75 | 'dueAt': _dueAt, |
| 76 | 'visibility': 'private', |
| 77 | }); |
| 78 | final visible = _record(await api.listPlanItems(), _originalTitle); |
| 79 | final saved = _record(_savedItems(await _readDisk()), _originalTitle); |
| 80 | expect(visible['id'], created['id']); |
| 81 | expect(saved['id'], created['id']); |
| 82 | expect(saved['kind'], 'assignment'); |
| 83 | expect(saved['due_at'], _dueAt); |
| 84 | expect(saved['visibility'], 'private'); |
| 85 | expect(saved['status'], 'planned'); |
| 86 | expect((await api.getProfile())['display_name'], 'آرام'); |
| 87 | |
| 88 | case 'update': |
| 89 | final restored = _record(await api.listPlanItems(), _originalTitle); |
| 90 | final id = restored['id'] as String; |
| 91 | expect(restored['due_at'], _dueAt); |
| 92 | expect(restored['status'], 'planned'); |
| 93 | await api.updatePlanItem(id, { |
| 94 | 'title': _editedTitle, |
| 95 | 'notes': _editedNotes, |
| 96 | 'status': 'in_progress', |
| 97 | }); |
| 98 | await api.updateProfile( |
| 99 | displayName: 'سارا', themePreference: 'boy_blue'); |
| 100 | final updated = _record(await api.listPlanItems(), _editedTitle); |
| 101 | expect(updated['id'], id); |
| 102 | expect(updated['notes'], _editedNotes); |
| 103 | expect(updated['status'], 'in_progress'); |
| 104 | expect(updated['due_at'], _dueAt); |
| 105 | await _expectEditedProfile(api); |
| 106 | |
| 107 | case 'archive': |
| 108 | await _expectEditedProfile(api); |
| 109 | final restored = _record(await api.listPlanItems(), _editedTitle); |
| 110 | final id = restored['id'] as String; |
| 111 | expect(restored['notes'], _editedNotes); |
| 112 | expect(restored['status'], 'in_progress'); |
| 113 | await api.updatePlanItem(id, {'status': 'cancelled'}); |
| 114 | expect(await api.listPlanItems(), isEmpty); |
| 115 | final archived = _record(_savedItems(await _readDisk()), _editedTitle); |
| 116 | expect(archived['id'], id); |
| 117 | expect(archived['status'], 'cancelled'); |
| 118 | |
| 119 | case 'verify': |
| 120 | await _expectEditedProfile(api); |
| 121 | expect(await api.listPlanItems(), isEmpty); |
| 122 | final data = await _readDisk(); |
| 123 | final archived = _record(_savedItems(data), _editedTitle); |
| 124 | expect(archived['status'], 'cancelled'); |
| 125 | expect(archived['kind'], 'assignment'); |
| 126 | expect(archived['notes'], _editedNotes); |
| 127 | expect(archived['due_at'], _dueAt); |
| 128 | expect(archived['visibility'], 'private'); |
| 129 | final profile = data['profile'] as Map; |
| 130 | expect(profile['display_name'], 'سارا'); |
| 131 | expect(profile['theme_preference'], 'boy_blue'); |
| 132 | expect(archived['owner_user_id'], profile['user_id']); |
| 133 | } |
| 134 | |
| 135 | expect(api.accessToken, isNull); |
| 136 | }); |
| 137 | } |