LifeMate — Personal, Family & Learning Companion

feat/flutter-mobile-navigation
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
dart 179 lines 7.26 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter/services.dart';
3 import 'package:flutter_test/flutter_test.dart';
4 import 'package:lifemate/main.dart';
5 import 'package:lifemate/api.dart';
6 import 'package:lifemate/phase3_ui.dart';
7 import 'package:lifemate/education_ui.dart';
8 import 'package:lifemate/study_ui.dart';
9 import 'package:lifemate/dashboard_ui.dart';
10 import 'package:shared_preferences/shared_preferences.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 import 'app_test.dart' show FakeApi;
15
16 class MenuApi extends FakeApi {
17 MenuApi({this.category = 'girl_minor'});
18 final String category;
19 bool failProfile = false;
20 bool offlineProfile = false;
21 @override
22 Future<Map<String, dynamic>> getProfile() async {
23 if (offlineProfile) throw const ApiException(0, 'network_unavailable');
24 if (failProfile) throw const ApiException(503, 'profile_unavailable');
25 return {
26 'user_id': 'synthetic-menu-user',
27 'display_name': 'کاربر نمونه',
28 'profile_category': category,
29 'theme_preference': 'adult_blue',
30 };
31 }
32
33 @override
34 Future<List<Map<String, dynamic>>> listFamilies() async => [];
35 }
36
37 void main() {
38 TestWidgetsFlutterBinding.ensureInitialized();
39 setUpAll(() async {
40 final fonts = FontLoader('LifeGuidePersian')
41 ..addFont(rootBundle.load('assets/fonts/LifeGuidePersian.ttf'));
42 await fonts.load();
43 WidgetController.hitTestWarningShouldBeFatal = true;
44 });
45
46 setUp(() {
47 String? token;
48 TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
49 .setMockMethodCallHandler(
50 const MethodChannel('lifeguide/local_write_guard'), (call) async {
51 if (call.method == 'getBlocked') return token != null;
52 if (call.method == 'beginWrite') return token = 'synthetic-menu-write';
53 if (call.method == 'completeWrite' && call.arguments == token) {
54 token = null;
55 return true;
56 }
57 throw PlatformException(code: 'local_storage_restart_required');
58 });
59 SharedPreferences.setMockInitialValues({});
60 SharedPreferencesAsyncPlatform.instance =
61 InMemorySharedPreferencesAsync.withData({});
62 });
63 Future<void> shell(WidgetTester tester, MenuApi api) async {
64 await tester.pumpWidget(MaterialApp(
65 theme: ThemeData(fontFamily: 'LifeGuidePersian'),
66 home: Directionality(
67 textDirection: TextDirection.rtl, child: HomeShell(api: api))));
68 await tester.pumpAndSettle();
69 }
70
71 for (final size in [const Size(390, 844), const Size(320, 740)]) {
72 testWidgets(
73 'compact home menus open separate destinations and back at $size',
74 (tester) async {
75 tester.view.physicalSize = size;
76 tester.view.devicePixelRatio = 1;
77 addTearDown(tester.view.resetPhysicalSize);
78 addTearDown(tester.view.resetDevicePixelRatio);
79 await shell(tester, MenuApi());
80 expect(find.textContaining('کاربر نمونه'), findsOneWidget);
81 for (final entry in {
82 'plan': PlannerPage,
83 'courses': EducationLibraryPage,
84 'focus': StudyHub,
85 'family': ProfileFamilyPage
86 }.entries) {
87 final menu = find.byKey(ValueKey('home-${entry.key}'));
88 expect(menu.hitTestable(), findsOneWidget);
89 expect(tester.getRect(menu).bottom, lessThan(size.height - 50));
90 await tester.tap(menu);
91 await tester.pumpAndSettle();
92 expect(find.byType(entry.value), findsOneWidget);
93 expect(find.byKey(const ValueKey('home-plan')), findsNothing);
94 await tester.tap(find.byTooltip('برگشت به خانه'));
95 await tester.pumpAndSettle();
96 expect(find.byKey(const ValueKey('home-plan')), findsOneWidget);
97 }
98 for (final key in ['report', 'reminders']) {
99 expect(find.byKey(ValueKey('home-$key')).hitTestable(), findsOneWidget);
100 await tester.tap(find.byKey(ValueKey('home-$key')));
101 await tester.pumpAndSettle();
102 expect(find.byKey(const ValueKey('home-plan')), findsNothing);
103 await tester.tap(find.byTooltip('برگشت به خانه'));
104 await tester.pumpAndSettle();
105 }
106 expect(tester.takeException(), isNull);
107 await tester.pumpWidget(const SizedBox());
108 });
109 }
110 testWidgets('large text remains reachable without layout overflow',
111 (tester) async {
112 tester.view.physicalSize = const Size(320, 740);
113 tester.view.devicePixelRatio = 1;
114 addTearDown(tester.view.resetPhysicalSize);
115 addTearDown(tester.view.resetDevicePixelRatio);
116 await tester.pumpWidget(MaterialApp(
117 theme: ThemeData(fontFamily: 'LifeGuidePersian'),
118 home: MediaQuery(
119 data: const MediaQueryData(
120 size: Size(320, 740), textScaler: TextScaler.linear(1.6)),
121 child: Directionality(
122 textDirection: TextDirection.rtl,
123 child: HomeShell(api: MenuApi())))));
124 await tester.pumpAndSettle();
125 await tester.scrollUntilVisible(
126 find.byKey(const ValueKey('home-reminders')), 150,
127 scrollable: find
128 .descendant(
129 of: find.byKey(const ValueKey('home-scroll')),
130 matching: find.byType(Scrollable))
131 .first);
132 expect(find.byKey(const ValueKey('home-reminders')).hitTestable(),
133 findsOneWidget);
134 expect(tester.takeException(), isNull);
135 await tester.pumpWidget(const SizedBox());
136 });
137 testWidgets(
138 'adult home does not depend on family membership or grant parent access',
139 (tester) async {
140 await shell(tester, MenuApi(category: 'adult'));
141 expect(find.byKey(const ValueKey('home-family')), findsOneWidget);
142 expect(find.byKey(const ValueKey('home-report')), findsOneWidget);
143 expect(find.byKey(const ValueKey('home-courses')), findsNothing);
144 await tester.tap(find.byKey(const ValueKey('home-report')));
145 await tester.pumpAndSettle();
146 expect(find.byType(ParentFamilyDashboard), findsOneWidget);
147 expect(find.byType(LearningReportPage), findsNothing);
148 await tester.pumpWidget(const SizedBox());
149 });
150 testWidgets(
151 'same-account offline profile refresh preserves cached planner access',
152 (tester) async {
153 final api = MenuApi();
154 await shell(tester, api);
155 await tester.tap(find.byKey(const ValueKey('home-family')));
156 await tester.pumpAndSettle();
157 api.offlineProfile = true;
158 await tester.tap(find.byTooltip('برگشت به خانه'));
159 await tester.pumpAndSettle();
160 expect(
161 find.byKey(const ValueKey('home-plan')).hitTestable(), findsOneWidget);
162 await tester.tap(find.byKey(const ValueKey('home-plan')));
163 await tester.pumpAndSettle();
164 expect(find.byType(PlannerPage), findsOneWidget);
165 await tester.pumpWidget(const SizedBox());
166 });
167 testWidgets(
168 'profile failure does not guess a child or parent home and can retry',
169 (tester) async {
170 final api = MenuApi()..failProfile = true;
171 await shell(tester, api);
172 expect(find.byKey(const ValueKey('home-plan')), findsNothing);
173 api.failProfile = false;
174 await tester.tap(find.text('تلاش دوباره').first);
175 await tester.pumpAndSettle();
176 expect(find.byKey(const ValueKey('home-plan')), findsOneWidget);
177 await tester.pumpWidget(const SizedBox());
178 });
179 }