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
| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/services.dart'; |
| 3 | import 'package:flutter_test/flutter_test.dart'; |
| 4 | import 'package:lifemate/phase3_ui.dart'; |
| 5 | import 'package:lifemate/plan_sync.dart'; |
| 6 | import 'package:lifemate/planner_series.dart'; |
| 7 | import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; |
| 8 | import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; |
| 9 | import 'app_test.dart' show FakeApi; |
| 10 | |
| 11 | class PlannerFixture extends FakeApi { |
| 12 | final writes = <Map<String, dynamic>>[]; |
| 13 | final rows = <Map<String, dynamic>>[]; |
| 14 | @override |
| 15 | Future<List<Map<String, dynamic>>> listFamilies() async => []; |
| 16 | @override |
| 17 | Future<List<Map<String, dynamic>>> listPlanItems( |
| 18 | {DateTime? from, DateTime? to, String? kind}) async => |
| 19 | rows; |
| 20 | @override |
| 21 | Future<List<Map<String, dynamic>>> getToday( |
| 22 | {DateTime? from, DateTime? to}) async => |
| 23 | rows |
| 24 | .where((row) => |
| 25 | row['status'] != 'completed' && row['status'] != 'cancelled') |
| 26 | .toList(); |
| 27 | @override |
| 28 | Future<Map<String, dynamic>> submitSyncMutations( |
| 29 | List<Map<String, dynamic>> changes) async { |
| 30 | writes.addAll(changes); |
| 31 | final m = changes.single; |
| 32 | final payload = m['payload'] as Map<String, dynamic>; |
| 33 | final old = rows.where((row) => row['id'] == m['entityId']).firstOrNull; |
| 34 | final row = <String, dynamic>{ |
| 35 | ...?(old), |
| 36 | 'id': m['entityId'], |
| 37 | 'version': (m['expectedVersion'] as int) + 1, |
| 38 | 'title': payload['title'] ?? old?['title'], |
| 39 | 'status': payload['status'] ?? 'planned', |
| 40 | 'starts_at': payload['startsAt'] ?? old?['starts_at'], |
| 41 | 'ends_at': payload['endsAt'] ?? old?['ends_at'] |
| 42 | }; |
| 43 | rows.removeWhere((item) => item['id'] == row['id']); |
| 44 | rows.add(row); |
| 45 | return { |
| 46 | 'results': [ |
| 47 | { |
| 48 | 'id': m['id'], |
| 49 | 'status': 'accepted', |
| 50 | 'item': row, |
| 51 | 'acceptedAt': DateTime.now().toUtc().toIso8601String() |
| 52 | } |
| 53 | ] |
| 54 | }; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void main() { |
| 59 | TestWidgetsFlutterBinding.ensureInitialized(); |
| 60 | test('visible range includes end clock in the local planner label', () { |
| 61 | final start = DateTime(2026, 10, 19, 8), end = DateTime(2026, 10, 19, 12); |
| 62 | expect( |
| 63 | planTimeLabel({ |
| 64 | 'starts_at': start.toUtc().toIso8601String(), |
| 65 | 'ends_at': end.toUtc().toIso8601String() |
| 66 | }), |
| 67 | contains('تا 12:00')); |
| 68 | }); |
| 69 | setUp(() { |
| 70 | SharedPreferencesAsyncPlatform.instance = |
| 71 | InMemorySharedPreferencesAsync.withData({}); |
| 72 | String? token; |
| 73 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 74 | .setMockMethodCallHandler( |
| 75 | const MethodChannel('lifeguide/local_write_guard'), (call) async { |
| 76 | if (call.method == 'getBlocked') return token != null; |
| 77 | if (call.method == 'beginWrite') return token = 'weekly-widget-write'; |
| 78 | if (call.method == 'completeWrite' && call.arguments == token) { |
| 79 | token = null; |
| 80 | return true; |
| 81 | } |
| 82 | throw PlatformException(code: 'local_storage_restart_required'); |
| 83 | }); |
| 84 | }); |
| 85 | Future<void> dialog(WidgetTester tester, PlannerFixture api, |
| 86 | {Map<String, dynamic>? item, DateTime? date}) async { |
| 87 | await tester.pumpWidget(MaterialApp( |
| 88 | home: Scaffold( |
| 89 | body: Builder( |
| 90 | builder: (context) => TextButton( |
| 91 | onPressed: () => showDialog<MutationOutcome>( |
| 92 | context: context, |
| 93 | builder: (_) => PlanItemDialog( |
| 94 | api: api, item: item, initialDate: date)), |
| 95 | child: const Text('open')))))); |
| 96 | await tester.tap(find.text('open')); |
| 97 | await tester.pumpAndSettle(); |
| 98 | } |
| 99 | |
| 100 | testWidgets('selected calendar day creates explicit start and end', |
| 101 | (tester) async { |
| 102 | final api = PlannerFixture(); |
| 103 | final date = DateTime.now().add(const Duration(days: 3)); |
| 104 | await dialog(tester, api, date: date); |
| 105 | await tester.enterText( |
| 106 | find.widgetWithText(TextField, 'عنوان'), 'برنامه ساختگی'); |
| 107 | await tester.tap(find.text('ذخیره')); |
| 108 | await tester.pumpAndSettle(); |
| 109 | final body = api.writes.single['payload'] as Map; |
| 110 | expect(plannerDate(DateTime.parse(body['startsAt']).toLocal()), |
| 111 | plannerDate(date)); |
| 112 | expect( |
| 113 | DateTime.parse(body['endsAt']) |
| 114 | .difference(DateTime.parse(body['startsAt'])) |
| 115 | .inMinutes, |
| 116 | 30); |
| 117 | expect(body['visibility'], 'private'); |
| 118 | await tester.pumpWidget(const SizedBox()); |
| 119 | }); |
| 120 | testWidgets('home retains completed count after a fresh read', |
| 121 | (tester) async { |
| 122 | final api = PlannerFixture(); |
| 123 | api.rows.add({ |
| 124 | 'id': '40000000-0000-4000-8000-000000000001', |
| 125 | 'title': 'کار ساختگی', |
| 126 | 'kind': 'task', |
| 127 | 'status': 'planned', |
| 128 | 'version': 1, |
| 129 | 'starts_at': DateTime.now().toUtc().toIso8601String() |
| 130 | }); |
| 131 | await tester.pumpWidget(MaterialApp( |
| 132 | home: Scaffold( |
| 133 | body: |
| 134 | TodayPage(api: api, home: true, displayName: 'کاربر ساختگی')))); |
| 135 | await tester.pumpAndSettle(); |
| 136 | expect(find.text('0 از 1 کار امروز انجام شده'), findsOneWidget); |
| 137 | final tick = |
| 138 | find.byKey(const ValueKey('tick-40000000-0000-4000-8000-000000000001')); |
| 139 | await tester.ensureVisible(tick); |
| 140 | await tester.tap(tick); |
| 141 | await tester.pumpAndSettle(); |
| 142 | expect(find.text('1 از 1 کار امروز انجام شده'), findsOneWidget); |
| 143 | await tester.pumpWidget(const SizedBox()); |
| 144 | }); |
| 145 | testWidgets('removing time range clears both endpoints, not just end', |
| 146 | (tester) async { |
| 147 | final api = PlannerFixture(); |
| 148 | final start = DateTime.now().add(const Duration(hours: 1)); |
| 149 | await dialog(tester, api, item: { |
| 150 | 'id': 'synthetic-plan', |
| 151 | 'title': 'برنامه ساختگی', |
| 152 | 'kind': 'task', |
| 153 | 'status': 'planned', |
| 154 | 'visibility': 'private', |
| 155 | 'version': 1, |
| 156 | 'starts_at': start.toUtc().toIso8601String(), |
| 157 | 'ends_at': start.add(const Duration(hours: 1)).toUtc().toIso8601String() |
| 158 | }); |
| 159 | final range = find.byKey(const ValueKey('plan-time-range')); |
| 160 | await tester.ensureVisible(range); |
| 161 | await tester.tap(range); |
| 162 | await tester.pumpAndSettle(); |
| 163 | await tester.tap(find.text('ذخیره')); |
| 164 | await tester.pumpAndSettle(); |
| 165 | final body = api.writes.single['payload'] as Map; |
| 166 | expect(body.containsKey('startsAt'), true); |
| 167 | expect(body['startsAt'], isNull); |
| 168 | expect(body.containsKey('endsAt'), true); |
| 169 | expect(body['endsAt'], isNull); |
| 170 | await tester.pumpWidget(const SizedBox()); |
| 171 | }); |
| 172 | testWidgets('tick changes one occurrence only and week day switches', |
| 173 | (tester) async { |
| 174 | final api = PlannerFixture(); |
| 175 | final now = DateTime.now(); |
| 176 | final tomorrow = now.add(const Duration(days: 1)); |
| 177 | api.rows.addAll([ |
| 178 | { |
| 179 | 'id': 'occurrence-a', |
| 180 | 'series_id': 'synthetic-series', |
| 181 | 'title': 'امروز ساختگی', |
| 182 | 'status': 'planned', |
| 183 | 'version': 1, |
| 184 | 'starts_at': now.toUtc().toIso8601String() |
| 185 | }, |
| 186 | { |
| 187 | 'id': 'occurrence-b', |
| 188 | 'series_id': 'synthetic-series', |
| 189 | 'title': 'فردا ساختگی', |
| 190 | 'status': 'planned', |
| 191 | 'version': 1, |
| 192 | 'starts_at': tomorrow.toUtc().toIso8601String() |
| 193 | }, |
| 194 | ]); |
| 195 | await tester |
| 196 | .pumpWidget(MaterialApp(home: Scaffold(body: PlannerPage(api: api)))); |
| 197 | await tester.pumpAndSettle(); |
| 198 | expect(find.text('امروز ساختگی'), findsOneWidget); |
| 199 | expect(find.text('فردا ساختگی'), findsNothing); |
| 200 | await tester.ensureVisible(find.byKey(const ValueKey('tick-occurrence-a'))); |
| 201 | await tester.tap(find.byKey(const ValueKey('tick-occurrence-a'))); |
| 202 | await tester.pumpAndSettle(); |
| 203 | expect(api.rows.firstWhere((row) => row['id'] == 'occurrence-a')['status'], |
| 204 | 'completed'); |
| 205 | expect(api.rows.firstWhere((row) => row['id'] == 'occurrence-b')['status'], |
| 206 | 'planned'); |
| 207 | if (tomorrow.weekday == DateTime.saturday) { |
| 208 | await tester.tap(find.byTooltip('هفتهٔ بعد')); |
| 209 | await tester.pumpAndSettle(); |
| 210 | } |
| 211 | final day = find.byKey(ValueKey('planner-day-${tomorrow.weekday}')); |
| 212 | await tester.ensureVisible(day); |
| 213 | await tester.tap(day); |
| 214 | await tester.pumpAndSettle(); |
| 215 | expect(find.text('فردا ساختگی'), findsOneWidget); |
| 216 | await tester.pumpWidget(const SizedBox()); |
| 217 | }); |
| 218 | } |