LifeMate — Personal, Family & Learning Companion

phase-5/hardening-observability-release
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 445 lines 11.8 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 @override
242 Future<Map<String, dynamic>> createLearningGoal({
243 required String title,
244 String? target,
245 String? subjectId,
246 }) async =>
247 {'id': 'goal-1', 'title': title, 'target': target};
248
249 @override
250 Future<List<Map<String, dynamic>>> listLearningGoals() async => [
251 {'id': 'goal-1', 'title': 'مرور ریاضی', 'target': 'فصل اول'}
252 ];
253
254 @override
255 Future<Map<String, dynamic>> createLearningCheckin({
256 String? learningGoalId,
257 required int confidence,
258 required int difficulty,
259 String? note,
260 }) async =>
261 {
262 'id': 'checkin-1',
263 'confidence': confidence,
264 'difficulty': difficulty,
265 };
266
267 @override
268 Future<Map<String, dynamic>> createWellbeingCheckin({
269 required int mood,
270 required int energy,
271 required int stress,
272 String? note,
273 String visibility = 'private',
274 }) async =>
275 {
276 'id': 'wellbeing-1',
277 'mood': mood,
278 'energy': energy,
279 'stress': stress,
280 'visibility': visibility,
281 };
282
283 @override
284 Future<List<Map<String, dynamic>>> listWellbeingCheckins() async => [];
285
286 @override
287 Future<Map<String, dynamic>> createAiSession(String kind) async =>
288 {'id': 'session-1', 'guide_kind': kind};
289
290 @override
291 Future<Map<String, dynamic>> sendAiMessage(
292 String sessionId,
293 String message,
294 ) async =>
295 {
296 'id': 'message-1',
297 'body': 'پاسخ آزمایشی همراه هوشمند',
298 'safety_class': 'ordinary',
299 'advisory': true,
300 };
301
302 @override
303 Future<Map<String, dynamic>> getGuardianWellbeingSummary(
304 String familyId,
305 String minorUserId,
306 ) async =>
307 {
308 'summary': {
309 'checkin_count': 3,
310 'mood_average': 4,
311 'energy_average': 3,
312 'stress_average': 2,
313 },
314 'safety': {'open_urgent_count': 0},
315 'rawNotesIncluded': false,
316 'rawConversationIncluded': false,
317 };
318
319 @override
320 Future<Map<String, dynamic>> requestFamilyGuidance(
321 String familyId,
322 String minorUserId,
323 String question,
324 ) async =>
325 {
326 'advice': 'پیشنهاد آزمایشی برای گفت‌وگوی حمایتی با فرزند',
327 'advisory': true,
328 'medicalDiagnosis': false,
329 };
330 }
331
332 void main() {
333 setUp(() {
334 SharedPreferences.setMockInitialValues({});
335 });
336
337 testWidgets('starts in Persian RTL with identity actions', (tester) async {
338 await tester.pumpWidget(LifeMateApp(api: FakeApi()));
339
340 expect(find.text('LifeMate'), findsOneWidget);
341 expect(find.text('ورود'), findsOneWidget);
342 expect(find.text('رمز عبور را فراموش کرده‌ام'), findsOneWidget);
343
344 final directionality =
345 tester.widget<Directionality>(find.byType(Directionality).last);
346 expect(directionality.textDirection, TextDirection.rtl);
347 });
348
349 testWidgets('opens recovery flow', (tester) async {
350 await tester.pumpWidget(LifeMateApp(api: FakeApi()));
351
352 await tester.tap(find.text('رمز عبور را فراموش کرده‌ام'));
353 await tester.pumpAndSettle();
354
355 expect(find.text('بازیابی رمز عبور'), findsOneWidget);
356 expect(find.text('ارسال لینک بازیابی'), findsOneWidget);
357 });
358
359 testWidgets('teen login opens MyStudyLife-inspired student shell',
360 (tester) async {
361 await tester.pumpWidget(
362 LifeMateApp(
363 api: FakeApi(role: 'teen_minor', themePreference: 'girl_pink'),
364 ),
365 );
366
367 await tester.enterText(
368 find.widgetWithText(TextField, 'ایمیل'),
369 'parent@example.test',
370 );
371 await tester.enterText(
372 find.widgetWithText(TextField, 'رمز عبور'),
373 'StrongPass!123',
374 );
375 await tester.tap(find.text('ورود'));
376 await tester.pumpAndSettle();
377
378 expect(find.text('امروز'), findsWidgets);
379 expect(find.text('برنامه'), findsOneWidget);
380 expect(find.text('تقویم'), findsOneWidget);
381 expect(find.text('کارها'), findsOneWidget);
382 expect(find.text('امتحان‌ها'), findsOneWidget);
383 });
384
385 testWidgets('parent login opens parent-focused family shell', (tester) async {
386 await tester.pumpWidget(
387 LifeMateApp(
388 api: FakeApi(
389 role: 'parent_guardian',
390 themePreference: 'adult_blue',
391 ),
392 ),
393 );
394
395 await tester.enterText(
396 find.widgetWithText(TextField, 'ایمیل'),
397 'parent@example.test',
398 );
399 await tester.enterText(
400 find.widgetWithText(TextField, 'رمز عبور'),
401 'StrongPass!123',
402 );
403 await tester.tap(find.text('ورود'));
404 await tester.pumpAndSettle();
405
406 expect(find.text('امروز'), findsWidgets);
407 expect(find.text('برنامه‌ریز'), findsOneWidget);
408 expect(find.text('خانواده'), findsOneWidget);
409 expect(find.text('راهنما'), findsOneWidget);
410 expect(find.text('من'), findsOneWidget);
411 expect(find.text('امتحان‌ها'), findsNothing);
412 });
413
414 testWidgets('phase 4 guide opens and returns advisory reply', (tester) async {
415 await tester.pumpWidget(
416 LifeMateApp(
417 api: FakeApi(role: 'parent_guardian', themePreference: 'adult_blue'),
418 ),
419 );
420 await tester.enterText(
421 find.widgetWithText(TextField, 'ایمیل'),
422 'parent@example.test',
423 );
424 await tester.enterText(
425 find.widgetWithText(TextField, 'رمز عبور'),
426 'StrongPass!123',
427 );
428 await tester.tap(find.text('ورود'));
429 await tester.pumpAndSettle();
430 await tester.tap(find.text('راهنما'));
431 await tester.pumpAndSettle();
432
433 expect(find.text('راهنمای هوشمند'), findsOneWidget);
434 expect(find.text('همراه حال خوب'), findsOneWidget);
435
436 await tester.tap(find.text('راهنمای مطالعه'));
437 await tester.pumpAndSettle();
438 await tester.enterText(find.byType(TextField).last, 'برای امتحان ریاضی چه کنم؟');
439 await tester.tap(find.byIcon(Icons.send_rounded));
440 await tester.pumpAndSettle();
441
442 expect(find.text('پاسخ آزمایشی همراه هوشمند'), findsOneWidget);
443 });
444
445 }