LifeMate — Personal, Family & Learning Companion

phase-3/planner-school-family-core
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 323 lines 8.39 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter_test/flutter_test.dart';
3 import 'package:lifemate/api.dart';
4 import 'package:lifemate/main.dart';
5 import 'package:shared_preferences/shared_preferences.dart';
6
7 class FakeApi implements IdentityApi {
8 FakeApi({
9 this.role = 'teen_minor',
10 this.themePreference = 'girl_pink',
11 });
12
13 final String role;
14 final String themePreference;
15
16 @override
17 String? accessToken;
18
19 @override
20 Future<void> login(String email, String password) async {
21 accessToken = 'test-token';
22 }
23
24 @override
25 Future<void> register({
26 required String displayName,
27 required String email,
28 required String password,
29 }) async {}
30
31 @override
32 Future<void> verifyEmail(String token) async {}
33
34 @override
35 Future<void> forgotPassword(String email) async {}
36
37 @override
38 Future<void> resetPassword(String token, String newPassword) async {}
39
40 @override
41 Future<void> changePassword(
42 String currentPassword,
43 String newPassword,
44 ) async {}
45
46 @override
47 Future<Map<String, dynamic>> getProfile() async => {
48 'display_name': role == 'teen_minor' ? 'آرام' : 'والد',
49 'email_normalized': 'user@example.test',
50 'user_id': role == 'teen_minor' ? 'teen-1' : 'parent-1',
51 'theme_preference': themePreference,
52 };
53
54 @override
55 Future<Map<String, dynamic>> updateProfile({
56 String? displayName,
57 String? birthDate,
58 String? themePreference,
59 }) async =>
60 {
61 'display_name': displayName ?? 'والد',
62 'theme_preference': themePreference ?? 'adult_blue',
63 };
64
65 @override
66 Future<List<Map<String, dynamic>>> listFamilies() async => [
67 {
68 'id': 'family-1',
69 'name': 'خانواده',
70 'role': role,
71 'is_admin': role == 'parent_guardian',
72 }
73 ];
74
75 @override
76 Future<List<Map<String, dynamic>>> listFamilyMembers(String familyId) async =>
77 [];
78
79 @override
80 Future<Map<String, dynamic>> createFamily(
81 String name, {
82 String? role,
83 }) async =>
84 {'id': 'family-1', 'name': name};
85
86 @override
87 Future<void> inviteMember({
88 required String familyId,
89 required String email,
90 required String role,
91 String? themePreference,
92 }) async {}
93
94 @override
95 Future<void> acceptInvitation(String token) async {}
96
97 @override
98 Future<void> setGuardian({
99 required String familyId,
100 required String guardianUserId,
101 required String minorUserId,
102 }) async {}
103
104 @override
105 Future<List<Map<String, dynamic>>> getToday({
106 required DateTime from,
107 required DateTime to,
108 }) async => [
109 {
110 'id': 'today-1',
111 'kind': 'task',
112 'title': 'مرور برنامه امروز',
113 'status': 'planned',
114 'due_at': DateTime.now().add(const Duration(hours: 1)).toUtc().toIso8601String(),
115 }
116 ];
117
118 @override
119 Future<List<Map<String, dynamic>>> listPlanItems({
120 DateTime? from,
121 DateTime? to,
122 String? kind,
123 }) async => [
124 {
125 'id': 'plan-1',
126 'kind': 'task',
127 'title': 'تکمیل تمرین',
128 'status': 'planned',
129 'due_at': DateTime.now().add(const Duration(days: 1)).toUtc().toIso8601String(),
130 }
131 ];
132
133 @override
134 Future<Map<String, dynamic>> createPlanItem(Map<String, dynamic> data) async =>
135 {'id': 'new-plan', ...data};
136
137 @override
138 Future<Map<String, dynamic>> updatePlanItem(
139 String itemId,
140 Map<String, dynamic> data,
141 ) async =>
142 {'id': itemId, ...data};
143
144 @override
145 Future<List<Map<String, dynamic>>> listLifeContexts() async => [];
146
147 @override
148 Future<Map<String, dynamic>> createLifeContext({
149 required String kind,
150 required String title,
151 }) async =>
152 {'id': 'ctx-1', 'kind': kind, 'title': title};
153
154 @override
155 Future<Map<String, dynamic>> createAcademicYear(
156 Map<String, dynamic> data,
157 ) async =>
158 {'id': 'year-1', ...data};
159
160 @override
161 Future<Map<String, dynamic>> createAcademicTerm(
162 String yearId,
163 Map<String, dynamic> data,
164 ) async =>
165 {'id': 'term-1', ...data};
166
167 @override
168 Future<Map<String, dynamic>> createSubject(
169 String termId,
170 Map<String, dynamic> data,
171 ) async =>
172 {'id': 'subject-1', ...data};
173
174 @override
175 Future<Map<String, dynamic>> createClassSession(
176 String subjectId,
177 Map<String, dynamic> data,
178 ) async =>
179 {'id': 'class-1', ...data};
180
181 @override
182 Future<Map<String, dynamic>> setGrade(
183 String itemId, {
184 required num points,
185 required num outOf,
186 }) async =>
187 {
188 'id': itemId,
189 'grade_points': points,
190 'grade_out_of': outOf,
191 };
192
193 @override
194 Future<List<Map<String, dynamic>>> claimDueReminders() async => [];
195
196 @override
197 Future<Map<String, dynamic>> getSchoolOverview(String studentUserId) async => {
198 'years': [
199 {'id': 'year-1', 'title': 'سال تحصیلی'}
200 ],
201 'subjects': [
202 {'id': 'subject-1', 'name': 'ریاضی', 'term_title': 'نیمسال اول'}
203 ],
204 'workload': const [],
205 'grades': const [],
206 };
207
208 @override
209 Future<List<Map<String, dynamic>>> getTimetable(String studentUserId) async =>
210 [];
211
212 @override
213 Future<List<Map<String, dynamic>>> getFamilyCalendar(String familyId) async =>
214 [];
215
216 @override
217 Future<Map<String, dynamic>> getChildSupportSummary(
218 String familyId,
219 String studentUserId,
220 ) async =>
221 {
222 'upcoming': const [],
223 'metrics': {
224 'completedLast7Days': 3,
225 'overdue': 1,
226 'studyMinutesLast7Days': 90,
227 'gradePercent': 85,
228 }
229 };
230
231 @override
232 Future<Map<String, dynamic>> submitSyncMutations(
233 List<Map<String, dynamic>> mutations,
234 ) async =>
235 {
236 'results': mutations
237 .map((m) => {'id': m['id'], 'status': 'accepted'})
238 .toList(),
239 };
240 }
241
242 void main() {
243 setUp(() {
244 SharedPreferences.setMockInitialValues({});
245 });
246
247 testWidgets('starts in Persian RTL with identity actions', (tester) async {
248 await tester.pumpWidget(LifeMateApp(api: FakeApi()));
249
250 expect(find.text('LifeMate'), findsOneWidget);
251 expect(find.text('ورود'), findsOneWidget);
252 expect(find.text('رمز عبور را فراموش کرده‌ام'), findsOneWidget);
253
254 final directionality =
255 tester.widget<Directionality>(find.byType(Directionality).last);
256 expect(directionality.textDirection, TextDirection.rtl);
257 });
258
259 testWidgets('opens recovery flow', (tester) async {
260 await tester.pumpWidget(LifeMateApp(api: FakeApi()));
261
262 await tester.tap(find.text('رمز عبور را فراموش کرده‌ام'));
263 await tester.pumpAndSettle();
264
265 expect(find.text('بازیابی رمز عبور'), findsOneWidget);
266 expect(find.text('ارسال لینک بازیابی'), findsOneWidget);
267 });
268
269 testWidgets('teen login opens MyStudyLife-inspired student shell',
270 (tester) async {
271 await tester.pumpWidget(
272 LifeMateApp(
273 api: FakeApi(role: 'teen_minor', themePreference: 'girl_pink'),
274 ),
275 );
276
277 await tester.enterText(
278 find.widgetWithText(TextField, 'ایمیل'),
279 'parent@example.test',
280 );
281 await tester.enterText(
282 find.widgetWithText(TextField, 'رمز عبور'),
283 'StrongPass!123',
284 );
285 await tester.tap(find.text('ورود'));
286 await tester.pumpAndSettle();
287
288 expect(find.text('امروز'), findsWidgets);
289 expect(find.text('برنامه'), findsOneWidget);
290 expect(find.text('تقویم'), findsOneWidget);
291 expect(find.text('کارها'), findsOneWidget);
292 expect(find.text('امتحان‌ها'), findsOneWidget);
293 });
294
295 testWidgets('parent login opens parent-focused family shell', (tester) async {
296 await tester.pumpWidget(
297 LifeMateApp(
298 api: FakeApi(
299 role: 'parent_guardian',
300 themePreference: 'adult_blue',
301 ),
302 ),
303 );
304
305 await tester.enterText(
306 find.widgetWithText(TextField, 'ایمیل'),
307 'parent@example.test',
308 );
309 await tester.enterText(
310 find.widgetWithText(TextField, 'رمز عبور'),
311 'StrongPass!123',
312 );
313 await tester.tap(find.text('ورود'));
314 await tester.pumpAndSettle();
315
316 expect(find.text('امروز'), findsWidgets);
317 expect(find.text('برنامه‌ریز'), findsOneWidget);
318 expect(find.text('خانواده'), findsOneWidget);
319 expect(find.text('راهنما'), findsOneWidget);
320 expect(find.text('من'), findsOneWidget);
321 expect(find.text('امتحان‌ها'), findsNothing);
322 });
323 }