@davoodmehraban89 / LifeMate / commits / ce184a5
Fork 0

LifeMate — Personal, Family & Learning Companion

feat(planner): add private recurring weekly editor

Quinn White committed Oct 18, 2026 at 17:32 UTC ce184a5688a10273507f5b304fef056d984aa492
2 files changed +680
apps/lifemate/lib/planner_series_ui.dart new
+428
@@ -0,0 +1,428 @@
1 +import 'dart:convert';
2 +
3 +import 'package:flutter/material.dart';
4 +
5 +import 'api.dart';
6 +import 'phase3_ui.dart' show faKind, uiErrorText;
7 +import 'plan_sync.dart' show newMutationId;
8 +import 'planner_series.dart';
9 +import 'sync_changes_ui.dart';
10 +
11 +typedef CreatePlannerSeries = Future<PlannerSeriesOutcome>
12 + Function(Map<String, dynamic> payload, {String? id});
13 +
14 +/// Creates private occurrences. Editing one occurrence is handled separately by
15 +/// PlanItemDialog; this form never changes family visibility or permissions.
16 +class PlannerSeriesDialog extends StatefulWidget {
17 + const PlannerSeriesDialog({
18 + super.key,
19 + required this.api,
20 + this.initialDate,
21 + this.onCreate,
22 + });
23 +
24 + final HttpIdentityApi api;
25 + final DateTime? initialDate;
26 + final CreatePlannerSeries? onCreate;
27 +
28 + @override
29 + State<PlannerSeriesDialog> createState() => _PlannerSeriesDialogState();
30 +}
31 +
32 +class _TimeSlot {
33 + const _TimeSlot({
34 + this.start = const TimeOfDay(hour: 8, minute: 0),
35 + this.end = const TimeOfDay(hour: 9, minute: 0),
36 + });
37 + final TimeOfDay start, end;
38 +
39 + bool get valid => end.hour * 60 + end.minute > start.hour * 60 + start.minute;
40 + Map<String, dynamic> get payload =>
41 + {'start': _clock(start), 'end': _clock(end)};
42 +}
43 +
44 +String _clock(TimeOfDay time) =>
45 + '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
46 +String _calendarDate(DateTime date) =>
47 + '${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
48 +
49 +class _PlannerSeriesDialogState extends State<PlannerSeriesDialog> {
50 + static const weekdays = <int, String>{
51 + 6: 'شنبه',
52 + 7: 'یکشنبه',
53 + 1: 'دوشنبه',
54 + 2: 'سه‌شنبه',
55 + 3: 'چهارشنبه',
56 + 4: 'پنجشنبه',
57 + 5: 'جمعه',
58 + };
59 + final title = TextEditingController();
60 + final id = newMutationId();
61 + final selected = <int>{};
62 + final slots = <int, _TimeSlot>{};
63 + _TimeSlot dailySlot = const _TimeSlot();
64 + late DateTime startsOn, untilOn;
65 + String kind = 'routine', frequency = 'weekly';
66 + int intervalDays = 1, reminderMinutes = -1;
67 + bool hasEnd = false, busy = false, terminal = false;
68 + String? error;
69 + Map<String, dynamic>? frozenPayload;
70 +
71 + bool get editable => !busy && frozenPayload == null;
72 +
73 + @override
74 + void initState() {
75 + super.initState();
76 + final date = widget.initialDate ?? DateTime.now();
77 + startsOn = DateTime(date.year, date.month, date.day);
78 + untilOn = startsOn.add(const Duration(days: 90));
79 + selected.add(startsOn.weekday);
80 + slots[startsOn.weekday] = const _TimeSlot();
81 + }
82 +
83 + @override
84 + void dispose() {
85 + title.dispose();
86 + super.dispose();
87 + }
88 +
89 + Future<void> pickDate({required bool end}) async {
90 + if (!editable) return;
91 + final date = await showDatePicker(
92 + context: context,
93 + initialDate: end ? untilOn : startsOn,
94 + firstDate: DateTime(2020),
95 + lastDate: DateTime(2100, 12, 31),
96 + );
97 + if (date != null && mounted && editable) {
98 + setState(() => end ? untilOn = date : startsOn = date);
99 + }
100 + }
101 +
102 + Future<void> pickTime(int? weekday, {required bool end}) async {
103 + if (!editable) return;
104 + final slot = weekday == null ? dailySlot : slots[weekday]!;
105 + final time = await showTimePicker(
106 + context: context,
107 + initialTime: end ? slot.end : slot.start,
108 + initialEntryMode: TimePickerEntryMode.input,
109 + builder: (context, child) => MediaQuery(
110 + data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
111 + child: child!,
112 + ),
113 + );
114 + if (time == null || !mounted || !editable) return;
115 + final changed = _TimeSlot(
116 + start: end ? slot.start : time,
117 + end: end ? time : slot.end,
118 + );
119 + setState(
120 + () => weekday == null ? dailySlot = changed : slots[weekday] = changed);
121 + }
122 +
123 + Map<String, dynamic>? payload() {
124 + if (title.text.trim().isEmpty) {
125 + error = 'عنوان را وارد کن.';
126 + return null;
127 + }
128 + if (hasEnd && untilOn.isBefore(startsOn)) {
129 + error = 'تاریخ پایان نباید پیش از تاریخ شروع باشد.';
130 + return null;
131 + }
132 + if (frequency == 'weekly' && selected.isEmpty) {
133 + error = 'دست‌کم یک روز هفته را انتخاب کن.';
134 + return null;
135 + }
136 + final activeSlots =
137 + frequency == 'daily' ? [dailySlot] : selected.map((day) => slots[day]!);
138 + if (activeSlots.any((slot) => !slot.valid)) {
139 + error = 'پایان هر نوبت باید پس از شروع و در همان روز باشد.';
140 + return null;
141 + }
142 + final sortedDays = selected.toList()..sort();
143 + return <String, dynamic>{
144 + 'title': title.text.trim(),
145 + 'kind': kind,
146 + 'timezone': 'Asia/Tehran',
147 + 'startsOn': _calendarDate(startsOn),
148 + if (hasEnd) 'untilOn': _calendarDate(untilOn),
149 + 'frequency': frequency,
150 + 'intervalDays': frequency == 'daily' ? intervalDays : 1,
151 + 'slots': frequency == 'daily'
152 + ? [dailySlot.payload]
153 + : [
154 + for (final day in sortedDays)
155 + {'weekday': day, ...slots[day]!.payload}
156 + ],
157 + 'reminderMinutes': reminderMinutes < 0 ? <int>[] : [reminderMinutes],
158 + };
159 + }
160 +
161 + Future<void> save() async {
162 + if (busy || terminal) return;
163 + final draft = frozenPayload ?? payload();
164 + if (draft == null) {
165 + setState(() {});
166 + return;
167 + }
168 + // Freeze both identity and exact body before awaiting durable enqueue/HTTP.
169 + // An unknown response can mean that the original request already committed.
170 + frozenPayload ??= jsonDecode(jsonEncode(draft)) as Map<String, dynamic>;
171 + setState(() {
172 + busy = true;
173 + error = null;
174 + });
175 + try {
176 + final create = widget.onCreate ?? PlannerSeriesSync(widget.api).create;
177 + final result = await create(
178 + jsonDecode(jsonEncode(frozenPayload)) as Map<String, dynamic>,
179 + id: id);
180 + if (mounted) Navigator.of(context).pop(result);
181 + } catch (failure) {
182 + if (mounted) {
183 + setState(() {
184 + terminal = failure is ApiException &&
185 + [400, 409, 422].contains(failure.statusCode);
186 + error = uiErrorText(failure);
187 + });
188 + }
189 + } finally {
190 + if (mounted) setState(() => busy = false);
191 + }
192 + }
193 +
194 + void openRecovery() {
195 + final navigator = Navigator.of(context);
196 + navigator.pop();
197 + navigator.push(MaterialPageRoute<void>(
198 + builder: (_) => SyncChangesPage(api: widget.api),
199 + ));
200 + }
201 +
202 + Widget timeSlot(int? weekday) {
203 + final slot = weekday == null ? dailySlot : slots[weekday]!;
204 + final prefix = weekday == null ? 'daily' : '$weekday';
205 + return Card(
206 + child: Padding(
207 + padding: const EdgeInsets.all(12),
208 + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
209 + Text(weekday == null ? 'ساعت هر نوبت' : weekdays[weekday]!,
210 + style:
211 + const TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
212 + const SizedBox(height: 8),
213 + Wrap(spacing: 8, runSpacing: 8, children: [
214 + for (final end in [false, true])
215 + OutlinedButton(
216 + key: ValueKey('series-day-$prefix-${end ? 'end' : 'start'}'),
217 + style:
218 + OutlinedButton.styleFrom(minimumSize: const Size(100, 48)),
219 + onPressed: editable ? () => pickTime(weekday, end: end) : null,
220 + child: Text(
221 + '${end ? 'پایان' : 'شروع'}: ${_clock(end ? slot.end : slot.start)}'),
222 + ),
223 + ]),
224 + ]),
225 + ),
226 + );
227 + }
228 +
229 + @override
230 + Widget build(BuildContext context) => PopScope(
231 + canPop: !busy,
232 + child: AlertDialog(
233 + title: const Text('برنامهٔ تکرارشونده',
234 + style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600)),
235 + content: SizedBox(
236 + width: 440,
237 + child: SingleChildScrollView(
238 + child: DefaultTextStyle.merge(
239 + style: const TextStyle(fontSize: 14, height: 1.6),
240 + child: Column(
241 + mainAxisSize: MainAxisSize.min,
242 + crossAxisAlignment: CrossAxisAlignment.stretch,
243 + children: [
244 + const Text(
245 + 'این برنامه خصوصی است. هر نوبت تیک و ساعت مستقل دارد؛ تغییر یک نوبت، روزهای دیگر را عوض نمی‌کند.'),
246 + const SizedBox(height: 12),
247 + TextField(
248 + key: const ValueKey('series-title'),
249 + controller: title,
250 + enabled: editable,
251 + maxLength: 200,
252 + style: const TextStyle(fontSize: 16),
253 + decoration: const InputDecoration(labelText: 'عنوان'),
254 + ),
255 + DropdownButtonFormField<String>(
256 + key: const ValueKey('series-kind'),
257 + initialValue: kind,
258 + decoration: const InputDecoration(labelText: 'نوع'),
259 + items: [
260 + for (final value in ['task', 'event', 'routine'])
261 + DropdownMenuItem(
262 + value: value, child: Text(faKind(value))),
263 + ],
264 + onChanged: editable
265 + ? (value) => setState(() => kind = value ?? kind)
266 + : null,
267 + ),
268 + const SizedBox(height: 12),
269 + const Text('زمان‌ها به وقت تهران (Asia/Tehran) هستند.'),
270 + const SizedBox(height: 8),
271 + OutlinedButton.icon(
272 + key: const ValueKey('series-start-date'),
273 + style: OutlinedButton.styleFrom(
274 + minimumSize: const Size(48, 48)),
275 + onPressed: editable ? () => pickDate(end: false) : null,
276 + icon: const Icon(Icons.calendar_today_outlined),
277 + label: Text('شروع: ${_calendarDate(startsOn)}'),
278 + ),
279 + CheckboxListTile(
280 + key: const ValueKey('series-has-end'),
281 + value: hasEnd,
282 + contentPadding: EdgeInsets.zero,
283 + title: const Text('تاریخ پایان دارد'),
284 + onChanged: editable
285 + ? (value) => setState(() => hasEnd = value ?? false)
286 + : null,
287 + ),
288 + if (hasEnd)
289 + OutlinedButton.icon(
290 + key: const ValueKey('series-end-date'),
291 + style: OutlinedButton.styleFrom(
292 + minimumSize: const Size(48, 48)),
293 + onPressed: editable ? () => pickDate(end: true) : null,
294 + icon: const Icon(Icons.event_outlined),
295 + label: Text('پایان: ${_calendarDate(untilOn)}'),
296 + ),
297 + DropdownButtonFormField<String>(
298 + key: const ValueKey('series-frequency'),
299 + initialValue: frequency,
300 + decoration: const InputDecoration(labelText: 'تکرار'),
301 + items: const [
302 + DropdownMenuItem(value: 'weekly', child: Text('هفتگی')),
303 + DropdownMenuItem(value: 'daily', child: Text('روزانه')),
304 + ],
305 + onChanged: editable
306 + ? (value) =>
307 + setState(() => frequency = value ?? frequency)
308 + : null,
309 + ),
310 + const SizedBox(height: 12),
311 + if (frequency == 'daily') ...[
312 + DropdownButtonFormField<int>(
313 + key: const ValueKey('series-interval'),
314 + initialValue: intervalDays,
315 + decoration:
316 + const InputDecoration(labelText: 'فاصلهٔ روزها'),
317 + items: const [
318 + DropdownMenuItem(value: 1, child: Text('هر روز')),
319 + DropdownMenuItem(
320 + value: 2, child: Text('یک روز در میان')),
321 + ],
322 + onChanged: editable
323 + ? (value) =>
324 + setState(() => intervalDays = value ?? 1)
325 + : null,
326 + ),
327 + const SizedBox(height: 8),
328 + timeSlot(null),
329 + ] else ...[
330 + const Text('روزهای برنامه را انتخاب کن:'),
331 + const SizedBox(height: 8),
332 + Wrap(spacing: 8, runSpacing: 8, children: [
333 + for (final day in weekdays.keys)
334 + ConstrainedBox(
335 + constraints: const BoxConstraints(
336 + minWidth: 48, minHeight: 48),
337 + child: FilterChip(
338 + key: ValueKey('series-weekday-$day'),
339 + label: Text(weekdays[day]!),
340 + selected: selected.contains(day),
341 + materialTapTargetSize:
342 + MaterialTapTargetSize.padded,
343 + onSelected: editable
344 + ? (value) => setState(() {
345 + if (value) {
346 + selected.add(day);
347 + slots.putIfAbsent(
348 + day, () => const _TimeSlot());
349 + } else {
350 + selected.remove(day);
351 + }
352 + })
353 + : null,
354 + ),
355 + ),
356 + ]),
357 + const SizedBox(height: 8),
358 + for (final day in weekdays.keys)
359 + if (selected.contains(day)) timeSlot(day),
360 + ],
361 + const SizedBox(height: 12),
362 + DropdownButtonFormField<int>(
363 + key: const ValueKey('series-reminder'),
364 + initialValue: reminderMinutes,
365 + decoration:
366 + const InputDecoration(labelText: 'یادآوری هر نوبت'),
367 + isExpanded: true,
368 + items: const [
369 + DropdownMenuItem(
370 + value: -1, child: Text('بدون یادآوری')),
371 + DropdownMenuItem(value: 0, child: Text('هنگام شروع')),
372 + DropdownMenuItem(
373 + value: 5, child: Text('۵ دقیقه پیش از شروع')),
374 + DropdownMenuItem(
375 + value: 10, child: Text('۱۰ دقیقه پیش از شروع')),
376 + DropdownMenuItem(
377 + value: 15, child: Text('۱۵ دقیقه پیش از شروع')),
378 + ],
379 + onChanged: editable
380 + ? (value) => setState(() => reminderMinutes = value!)
381 + : null,
382 + ),
383 + const SizedBox(height: 8),
384 + const Text(
385 + 'برای اعلان روی گوشی، اجازهٔ اعلان و تنظیمات یادآوری دستگاه هم باید فعال باشند. انتخاب ساعت، تضمین نمایش اعلان نیست.'),
386 + if (frozenPayload != null) ...[
387 + const SizedBox(height: 12),
388 + const Text(
389 + 'درخواست با همان شناسه نگه داشته شد. تا روشن‌شدن نتیجه، جزئیات قابل تغییر نیست؛ شناسهٔ تازه نساز.'),
390 + ],
391 + if (error != null) ...[
392 + const SizedBox(height: 12),
393 + Text(error!,
394 + style: TextStyle(
395 + color: Theme.of(context).colorScheme.error)),
396 + ],
397 + if (terminal)
398 + TextButton(
399 + style: TextButton.styleFrom(
400 + minimumSize: const Size(48, 48)),
401 + onPressed: busy ? null : openRecovery,
402 + child: const Text('بررسی تغییرات در انتظار'),
403 + ),
404 + ],
405 + ),
406 + ),
407 + ),
408 + ),
409 + actions: [
410 + TextButton(
411 + style: TextButton.styleFrom(minimumSize: const Size(48, 48)),
412 + onPressed: busy ? null : () => Navigator.of(context).pop(),
413 + child: Text(frozenPayload == null ? 'انصراف' : 'بستن'),
414 + ),
415 + FilledButton(
416 + key: const ValueKey('series-save'),
417 + style: FilledButton.styleFrom(minimumSize: const Size(96, 48)),
418 + onPressed: busy || terminal ? null : save,
419 + child: Text(busy
420 + ? 'در حال بررسی…'
421 + : frozenPayload == null
422 + ? 'ثبت برنامه'
423 + : 'تلاش دوباره'),
424 + ),
425 + ],
426 + ),
427 + );
428 +}
apps/lifemate/test/planner_series_ui_test.dart new
+252
@@ -0,0 +1,252 @@
1 +import 'dart:convert';
2 +
3 +import 'package:flutter/material.dart';
4 +import 'package:flutter/services.dart';
5 +import 'package:flutter_test/flutter_test.dart';
6 +import 'package:lifemate/api.dart';
7 +import 'package:lifemate/planner_series.dart';
8 +import 'package:lifemate/planner_series_ui.dart';
9 +
10 +void main() {
11 + setUpAll(() async {
12 + await (FontLoader('LifeGuidePersian')
13 + ..addFont(rootBundle.load('assets/fonts/LifeGuidePersian.ttf')))
14 + .load();
15 + });
16 +
17 + Future<void> open(
18 + WidgetTester tester,
19 + Future<PlannerSeriesOutcome> Function(Map<String, dynamic>, {String? id})
20 + create, {
21 + ValueChanged<PlannerSeriesOutcome?>? onClosed,
22 + Size size = const Size(390, 844),
23 + double textScale = 1,
24 + }) async {
25 + tester.view.physicalSize = size;
26 + tester.view.devicePixelRatio = 1;
27 + addTearDown(tester.view.resetPhysicalSize);
28 + addTearDown(tester.view.resetDevicePixelRatio);
29 + await tester.pumpWidget(MaterialApp(
30 + theme: ThemeData(fontFamily: 'LifeGuidePersian'),
31 + builder: (context, child) => MediaQuery(
32 + data: MediaQuery.of(context)
33 + .copyWith(textScaler: TextScaler.linear(textScale)),
34 + child: child!,
35 + ),
36 + home: Builder(builder: (context) {
37 + return Scaffold(
38 + body: TextButton(
39 + child: const Text('افزودن'),
40 + onPressed: () async {
41 + final result = await showDialog<PlannerSeriesOutcome>(
42 + context: context,
43 + builder: (_) => Directionality(
44 + textDirection: TextDirection.rtl,
45 + child: PlannerSeriesDialog(
46 + api: HttpIdentityApi(baseUrl: 'https://example.invalid'),
47 + initialDate: DateTime(2026, 10, 19),
48 + onCreate: create,
49 + ),
50 + ),
51 + );
52 + onClosed?.call(result);
53 + },
54 + ),
55 + );
56 + }),
57 + ));
58 + await tester.tap(find.text('افزودن'));
59 + await tester.pumpAndSettle();
60 + }
61 +
62 + Future<void> tapVisible(WidgetTester tester, Finder target) async {
63 + FocusManager.instance.primaryFocus?.unfocus();
64 + await tester.pumpAndSettle();
65 + await tester.ensureVisible(target);
66 + await tester.pumpAndSettle();
67 + await tester.tap(target);
68 + await tester.pumpAndSettle();
69 + }
70 +
71 + testWidgets('empty title never submits a recurring plan', (tester) async {
72 + var submitted = 0;
73 + await open(tester, (payload, {id}) async {
74 + submitted++;
75 + return PlannerSeriesOutcome(queued: false, id: id!);
76 + });
77 + await tester.tap(find.byKey(const ValueKey('series-save')));
78 + await tester.pumpAndSettle();
79 + expect(find.text('عنوان را وارد کن.'), findsOneWidget);
80 + expect(submitted, 0);
81 + });
82 +
83 + testWidgets('weekly selected days retain independent time slots and privacy',
84 + (tester) async {
85 + Map<String, dynamic>? submitted;
86 + PlannerSeriesOutcome? result;
87 + await open(tester, (payload, {id}) async {
88 + submitted = jsonDecode(jsonEncode(payload)) as Map<String, dynamic>;
89 + return PlannerSeriesOutcome(queued: false, id: id!);
90 + }, onClosed: (value) => result = value);
91 + await tester.enterText(
92 + find.byKey(const ValueKey('series-title')), 'برنامهٔ تمرینی ساختگی');
93 + await tapVisible(tester, find.byKey(const ValueKey('series-weekday-6')));
94 + await tapVisible(tester, find.byKey(const ValueKey('series-day-6-end')));
95 + final timeFields = find.descendant(
96 + of: find.byType(TimePickerDialog), matching: find.byType(TextField));
97 + await tester.enterText(timeFields.at(0), '10');
98 + await tester.enterText(timeFields.at(1), '30');
99 + await tester.tap(find.text('OK'));
100 + await tester.pumpAndSettle();
101 + await tester.tap(find.byKey(const ValueKey('series-save')));
102 + await tester.pumpAndSettle();
103 + expect(submitted!['timezone'], 'Asia/Tehran');
104 + expect(submitted!['startsOn'], '2026-10-19');
105 + expect(submitted!['frequency'], 'weekly');
106 + expect(submitted!['intervalDays'], 1);
107 + expect(submitted!['slots'], [
108 + {'weekday': 1, 'start': '08:00', 'end': '09:00'},
109 + {'weekday': 6, 'start': '08:00', 'end': '10:30'},
110 + ]);
111 + expect(submitted!.containsKey('visibility'), isFalse);
112 + expect(submitted!.containsKey('familyId'), isFalse);
113 + expect(result?.queued, isFalse);
114 + expect(result?.id, matches(RegExp(r'^[a-f0-9-]{36}$')));
115 + expect(tester.takeException(), isNull);
116 + });
117 +
118 + testWidgets('daily alternate schedule omits weekdays and accepts reminders',
119 + (tester) async {
120 + Map<String, dynamic>? submitted;
121 + await open(tester, (payload, {id}) async {
122 + submitted = payload;
123 + return PlannerSeriesOutcome(queued: true, id: id!);
124 + });
125 + await tester.enterText(
126 + find.byKey(const ValueKey('series-title')), 'کار روزدرمیان ساختگی');
127 + await tapVisible(tester, find.byKey(const ValueKey('series-frequency')));
128 + await tester.tap(find.text('روزانه').last);
129 + await tester.pumpAndSettle();
130 + await tapVisible(tester, find.byKey(const ValueKey('series-interval')));
131 + await tester.tap(find.text('یک روز در میان').last);
132 + await tester.pumpAndSettle();
133 + await tapVisible(tester, find.byKey(const ValueKey('series-reminder')));
134 + await tester.tap(find.text('۱۰ دقیقه پیش از شروع').last);
135 + await tester.pumpAndSettle();
136 + await tester.tap(find.byKey(const ValueKey('series-save')));
137 + await tester.pumpAndSettle();
138 + expect(submitted!['frequency'], 'daily');
139 + expect(submitted!['intervalDays'], 2);
140 + expect(submitted!['slots'], [
141 + {'start': '08:00', 'end': '09:00'}
142 + ]);
143 + expect(submitted!['reminderMinutes'], [10]);
144 + expect(find.byType(PlannerSeriesDialog), findsNothing);
145 + });
146 +
147 + testWidgets(
148 + 'unknown response freezes every control and retries exact request',
149 + (tester) async {
150 + final payloads = <String>[];
151 + final ids = <String?>[];
152 + await open(tester, (payload, {id}) async {
153 + payloads.add(jsonEncode(payload));
154 + ids.add(id);
155 + if (ids.length == 1) throw const ApiException(500, 'unknown_response');
156 + return PlannerSeriesOutcome(queued: false, id: id!);
157 + });
158 + await tester.enterText(
159 + find.byKey(const ValueKey('series-title')), 'درخواست با پاسخ نامعلوم');
160 + await tester.tap(find.byKey(const ValueKey('series-save')));
161 + await tester.pumpAndSettle();
162 + expect(
163 + tester
164 + .widget<TextField>(find.byKey(const ValueKey('series-title')))
165 + .enabled,
166 + isFalse);
167 + expect(
168 + tester
169 + .widget<DropdownButtonFormField<String>>(
170 + find.byKey(const ValueKey('series-frequency')))
171 + .onChanged,
172 + isNull);
173 + expect(
174 + tester
175 + .widget<OutlinedButton>(
176 + find.byKey(const ValueKey('series-start-date')))
177 + .onPressed,
178 + isNull);
179 + expect(
180 + tester
181 + .widget<CheckboxListTile>(
182 + find.byKey(const ValueKey('series-has-end')))
183 + .onChanged,
184 + isNull);
185 + await tester.tap(find.byKey(const ValueKey('series-save')));
186 + await tester.pumpAndSettle();
187 + expect(ids, hasLength(2));
188 + expect(ids[0], ids[1]);
189 + expect(payloads[0], payloads[1]);
190 + });
191 +
192 + testWidgets('same-day end must follow start and no day means no submission',
193 + (tester) async {
194 + var submitted = 0;
195 + await open(tester, (payload, {id}) async {
196 + submitted++;
197 + return PlannerSeriesOutcome(queued: false, id: id!);
198 + });
199 + await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه');
200 + await tapVisible(tester, find.byKey(const ValueKey('series-day-1-end')));
201 + final timeFields = find.descendant(
202 + of: find.byType(TimePickerDialog), matching: find.byType(TextField));
203 + await tester.enterText(timeFields.at(0), '08');
204 + await tester.enterText(timeFields.at(1), '00');
205 + await tester.tap(find.text('OK'));
206 + await tester.pumpAndSettle();
207 + await tester.tap(find.byKey(const ValueKey('series-save')));
208 + await tester.pumpAndSettle();
209 + expect(find.text('پایان هر نوبت باید پس از شروع و در همان روز باشد.'),
210 + findsOneWidget);
211 + await tapVisible(tester, find.byKey(const ValueKey('series-weekday-1')));
212 + await tester.tap(find.byKey(const ValueKey('series-save')));
213 + await tester.pumpAndSettle();
214 + expect(find.text('دست‌کم یک روز هفته را انتخاب کن.'), findsOneWidget);
215 + expect(submitted, 0);
216 + });
217 +
218 + testWidgets('terminal rejection keeps identity and offers queue recovery',
219 + (tester) async {
220 + await open(tester, (payload, {id}) async {
221 + throw const ApiException(409, 'version_conflict');
222 + });
223 + await tester.enterText(find.byKey(const ValueKey('series-title')), 'نمونه');
224 + await tester.tap(find.byKey(const ValueKey('series-save')));
225 + await tester.pumpAndSettle();
226 + expect(find.text('بررسی تغییرات در انتظار'), findsOneWidget);
227 + expect(
228 + tester
229 + .widget<FilledButton>(find.byKey(const ValueKey('series-save')))
230 + .onPressed,
231 + isNull);
232 + expect(find.textContaining('شناسهٔ تازه نساز'), findsOneWidget);
233 + });
234 +
235 + testWidgets(
236 + 'form scrolls at 320 pixels and 200 percent text without overflow',
237 + (tester) async {
238 + await open(tester, (payload, {id}) async {
239 + return PlannerSeriesOutcome(queued: true, id: id!);
240 + }, size: const Size(320, 740), textScale: 2);
241 + await tapVisible(tester, find.byKey(const ValueKey('series-has-end')));
242 + expect(find.byKey(const ValueKey('series-end-date')), findsOneWidget);
243 + await tapVisible(tester, find.byKey(const ValueKey('series-weekday-6')));
244 + await tester.ensureVisible(find.byKey(const ValueKey('series-reminder')));
245 + await tester.pumpAndSettle();
246 + expect(tester.takeException(), isNull);
247 + expect(find.byKey(const ValueKey('series-save')).hitTestable(),
248 + findsOneWidget);
249 + expect(tester.getSize(find.byKey(const ValueKey('series-save'))).height,
250 + greaterThanOrEqualTo(48));
251 + });
252 +}