LifeMate — Personal, Family & Learning Companion
feat/child-identity-schema
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/services.dart'; |
| 6 | import 'package:flutter_test/flutter_test.dart'; |
| 7 | import 'package:http/http.dart' as http; |
| 8 | import 'package:http/testing.dart'; |
| 9 | import 'package:lifemate/api.dart'; |
| 10 | import 'package:lifemate/main.dart'; |
| 11 | import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; |
| 12 | import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; |
| 13 | |
| 14 | // Explicit HTTP fixtures exercise navigation; they do not certify server grants. |
| 15 | void main() { |
| 16 | TestWidgetsFlutterBinding.ensureInitialized(); |
| 17 | setUp(() { |
| 18 | SharedPreferencesAsyncPlatform.instance = |
| 19 | InMemorySharedPreferencesAsync.withData({}); |
| 20 | String? token; |
| 21 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 22 | .setMockMethodCallHandler( |
| 23 | const MethodChannel('lifeguide/local_write_guard'), (call) async { |
| 24 | if (call.method == 'getBlocked') return token != null; |
| 25 | if (call.method == 'beginWrite') return token = 'navigation-fixture'; |
| 26 | if (call.method == 'completeWrite' && call.arguments == token) { |
| 27 | token = null; |
| 28 | return true; |
| 29 | } |
| 30 | throw PlatformException(code: 'local_storage_restart_required'); |
| 31 | }); |
| 32 | }); |
| 33 | http.Response json(Object data, [int status = 200]) => |
| 34 | http.Response(jsonEncode(data), status, |
| 35 | headers: {'content-type': 'application/json; charset=utf-8'}); |
| 36 | |
| 37 | HttpIdentityApi client(Future<http.Response> Function() permissions) => |
| 38 | HttpIdentityApi( |
| 39 | baseUrl: 'https://navigation.example.test/api', |
| 40 | client: MockClient((request) async { |
| 41 | if (request.url.path.endsWith('/content-capabilities')) { |
| 42 | return permissions(); |
| 43 | } |
| 44 | if (request.url.path.endsWith('/profile')) { |
| 45 | return json({ |
| 46 | 'user_id': 'synthetic-parent', |
| 47 | 'display_name': 'والد آزمایشی', |
| 48 | 'profile_category': 'adult', |
| 49 | 'theme_preference': 'adult_blue', |
| 50 | }); |
| 51 | } |
| 52 | return json({'items': [], 'families': []}); |
| 53 | })) |
| 54 | ..accessToken = 'synthetic-token' |
| 55 | ..currentUserId = 'synthetic-parent'; |
| 56 | |
| 57 | Future<void> openDrawer(WidgetTester tester) async { |
| 58 | tester.firstState<ScaffoldState>(find.byType(Scaffold)).openDrawer(); |
| 59 | await tester.pumpAndSettle(); |
| 60 | } |
| 61 | |
| 62 | testWidgets('parent category grants no content operations menu', |
| 63 | (tester) async { |
| 64 | final api = client(() async => json({'permissions': []})); |
| 65 | await tester.pumpWidget(MaterialApp(home: HomeShell(api: api))); |
| 66 | await tester.pumpAndSettle(); |
| 67 | await openDrawer(tester); |
| 68 | expect(find.text('بررسی محتوای آموزشی'), findsNothing); |
| 69 | await tester.pumpWidget(const SizedBox()); |
| 70 | api.close(); |
| 71 | }); |
| 72 | |
| 73 | testWidgets('explicit read capability is shown and failed refresh removes it', |
| 74 | (tester) async { |
| 75 | var failed = false; |
| 76 | final api = client(() async => failed |
| 77 | ? json({'error': 'synthetic_failure'}, 503) |
| 78 | : json({ |
| 79 | 'permissions': ['feedback.read'] |
| 80 | })); |
| 81 | await tester.pumpWidget(MaterialApp(home: HomeShell(api: api))); |
| 82 | await tester.pumpAndSettle(); |
| 83 | await openDrawer(tester); |
| 84 | await tester.scrollUntilVisible(find.text('بررسی محتوای آموزشی'), 100, |
| 85 | scrollable: find |
| 86 | .descendant( |
| 87 | of: find.byType(Drawer), matching: find.byType(Scrollable)) |
| 88 | .first); |
| 89 | expect(find.text('بررسی محتوای آموزشی'), findsOneWidget); |
| 90 | failed = true; |
| 91 | await tester.pump(const Duration(seconds: 31)); |
| 92 | await tester.pumpAndSettle(); |
| 93 | expect(find.text('بررسی محتوای آموزشی'), findsNothing); |
| 94 | await tester.pumpWidget(const SizedBox()); |
| 95 | api.close(); |
| 96 | }); |
| 97 | |
| 98 | testWidgets('late grant response from a previous account is discarded', |
| 99 | (tester) async { |
| 100 | final delayed = Completer<http.Response>(); |
| 101 | final api = client(() => delayed.future); |
| 102 | await tester.pumpWidget(MaterialApp(home: HomeShell(api: api))); |
| 103 | await tester.pump(); |
| 104 | api.currentUserId = 'another-synthetic-account'; |
| 105 | delayed.complete(json({ |
| 106 | 'permissions': ['feedback.read'] |
| 107 | })); |
| 108 | await tester.pumpAndSettle(); |
| 109 | await openDrawer(tester); |
| 110 | expect(find.text('بررسی محتوای آموزشی'), findsNothing); |
| 111 | await tester.pumpWidget(const SizedBox()); |
| 112 | api.close(); |
| 113 | }); |
| 114 | } |