LifeMate — Personal, Family & Learning Companion

docs/offline-data-rescue-options
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 81 lines 3.22 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter_test/flutter_test.dart';
3 import 'package:http/testing.dart';
4 import 'package:lifemate/api.dart';
5 import 'package:lifemate/device_reminder_coordinator.dart';
6 import 'package:lifemate/device_reminder_preferences.dart';
7 import 'package:lifemate/device_reminder_settings.dart';
8 import 'package:lifemate/local_reminders.dart';
9 import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
10 import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
11
12 class _Port implements LocalReminderPort {
13 _Port({this.supported = true});
14 final bool supported;
15 int exactRequests = 0;
16 @override
17 Future<LocalReminderStatus> status() async => LocalReminderStatus(
18 supported: supported,
19 permissionGranted: supported,
20 active: false,
21 scheduledCount: 0,
22 exactAlarmSupported: supported);
23 @override
24 Future<LocalReminderStatus> requestExactAlarmAccess() async {
25 exactRequests++;
26 return status();
27 }
28
29 @override
30 dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
31 }
32
33 void main() {
34 TestWidgetsFlutterBinding.ensureInitialized();
35 setUp(() {
36 SharedPreferencesAsyncPlatform.instance =
37 InMemorySharedPreferencesAsync.withData({});
38 });
39 HttpIdentityApi api() => HttpIdentityApi(
40 baseUrl: 'https://fixture.invalid/api',
41 client: MockClient((_) async => throw StateError('Unexpected network')))
42 ..accessToken = 'synthetic-access'
43 ..currentUserId = '11111111-1111-4111-8111-111111111111';
44 testWidgets(
45 'unsupported device shows honest background state and disabled opt-in',
46 (tester) async {
47 final client = api(), port = _Port(supported: false);
48 await tester.pumpWidget(MaterialApp(
49 home: DeviceReminderSettingsPage(
50 api: client,
51 coordinator: DeviceReminderCoordinator(client, port: port))));
52 await tester.pumpAndSettle();
53 expect(find.text('اعلان پس‌زمینه در این دستگاه پشتیبانی نمی‌شود.'),
54 findsOneWidget);
55 expect(tester.widget<Switch>(find.byType(Switch)).onChanged, isNull);
56 });
57 testWidgets(
58 'nickname save remains scoped and exact permission is user initiated',
59 (tester) async {
60 final client = api(), port = _Port();
61 await tester.pumpWidget(MaterialApp(
62 home: DeviceReminderSettingsPage(
63 api: client,
64 coordinator: DeviceReminderCoordinator(client, port: port))));
65 await tester.pumpAndSettle();
66 expect(port.exactRequests, 0);
67 await tester.enterText(
68 find.byKey(const ValueKey('companion-nickname')), 'همراه من');
69 await tester.tap(find.text('ذخیرهٔ نام همراه'));
70 await tester.pumpAndSettle();
71 expect(await DeviceReminderPreferences().read(client.cacheNamespace!),
72 'همراه من');
73 expect(
74 await DeviceReminderPreferences().read('https://other.invalid|other'),
75 'LifeGuide');
76 await tester.ensureVisible(find.text('اجازهٔ زمان‌بندی دقیق'));
77 await tester.tap(find.text('اجازهٔ زمان‌بندی دقیق'));
78 await tester.pumpAndSettle();
79 expect(port.exactRequests, 1);
80 });
81 }