LifeMate — Personal, Family & Learning Companion

fix/study-duration-display
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 93 lines 4.2 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter_test/flutter_test.dart';
3 import 'package:lifemate/endpoint_settings.dart';
4 import 'package:lifemate/runtime_config.dart';
5
6 void main() {
7 testWidgets('fresh install explains setup and cannot save an empty endpoint',
8 (tester) async {
9 var saved = false;
10 await tester.pumpWidget(MaterialApp(
11 home: EndpointSettingsPage(
12 initialConfig: RuntimeConfig(),
13 onSaved: (_) async => saved = true)));
14 expect(find.text('راه‌اندازی نسخه آزمایشی'), findsOneWidget);
15 expect(find.textContaining('نشانی کامل API'), findsOneWidget);
16 expect(find.textContaining('رمز عبور، کلید یا توکن وارد نکنید'),
17 findsOneWidget);
18 expect(find.textContaining('به معنی برقرارشدن اتصال نیست'), findsOneWidget);
19 final save = tester.widget<FilledButton>(find.byType(FilledButton));
20 expect(save.onPressed, isNull);
21 expect(saved, isFalse);
22 expect(
23 tester.widget<TextField>(find.byType(TextField).first).controller!.text,
24 isEmpty);
25 });
26 testWidgets('an operator endpoint is normalized and saved only on submission',
27 (tester) async {
28 final saved = <RuntimeConfig>[];
29 await tester.pumpWidget(MaterialApp(
30 home: EndpointSettingsPage(
31 initialConfig: RuntimeConfig(),
32 onSaved: (config) async => saved.add(config))));
33 await tester.enterText(
34 find.byType(TextField).first, ' https://operator.example.test/api/ ');
35 await tester.pump();
36 expect(saved, isEmpty);
37 await tester.ensureVisible(find.text('ذخیره و ادامه'));
38 await tester.tap(find.text('ذخیره و ادامه'));
39 await tester.pumpAndSettle();
40 expect(saved.single.apiBaseUrl, 'https://operator.example.test/api');
41 expect(saved.single.apiFallbackUrls, isEmpty);
42 });
43 testWidgets('editing a saved server warns about unsent changes',
44 (tester) async {
45 await tester.pumpWidget(MaterialApp(
46 home: EndpointSettingsPage(
47 initialConfig:
48 RuntimeConfig(apiBaseUrl: 'https://operator.example.test/api'),
49 onSaved: (_) async {})));
50 expect(find.text('تنظیم اتصال'), findsOneWidget);
51 expect(find.textContaining('تغییر سرویس شما را از حساب قبلی خارج می‌کند'),
52 findsOneWidget);
53 expect(find.textContaining('داده‌های ارسال‌نشده'), findsOneWidget);
54 });
55 testWidgets('fallback selection requires save and preserves the old primary',
56 (tester) async {
57 RuntimeConfig? saved;
58 await tester.pumpWidget(MaterialApp(
59 home: EndpointSettingsPage(
60 initialConfig: RuntimeConfig(
61 apiBaseUrl: 'https://primary.example.test/api',
62 apiFallbackUrls: ['https://backup.example.test/api']),
63 onSaved: (config) async => saved = config)));
64 await tester.ensureVisible(find.byType(OutlinedButton));
65 await tester.tap(find.byType(OutlinedButton));
66 await tester.pump();
67 expect(saved, isNull);
68 expect(
69 tester.widget<TextField>(find.byType(TextField).first).controller!.text,
70 'https://backup.example.test/api');
71 await tester.ensureVisible(find.text('ذخیره و ادامه'));
72 await tester.tap(find.text('ذخیره و ادامه'));
73 await tester.pumpAndSettle();
74 expect(saved!.apiBaseUrl, 'https://backup.example.test/api');
75 expect(saved!.apiFallbackUrls, ['https://primary.example.test/api']);
76 });
77 testWidgets('invalid HTTPS address never reaches the saved callback',
78 (tester) async {
79 var saved = false;
80 await tester.pumpWidget(MaterialApp(
81 home: EndpointSettingsPage(
82 initialConfig: RuntimeConfig(),
83 onSaved: (_) async => saved = true)));
84 await tester.enterText(
85 find.byType(TextField).first, 'https://user:password@api.example.test');
86 await tester.pump();
87 await tester.ensureVisible(find.text('ذخیره و ادامه'));
88 await tester.tap(find.text('ذخیره و ادامه'));
89 await tester.pumpAndSettle();
90 expect(saved, isFalse);
91 expect(find.textContaining('نشانی HTTPS معتبر'), findsOneWidget);
92 });
93 }