@@ -5,6 +5,7 @@ import 'package:on_time_front/domain/entities/preparation_entity.dart';
55import 'package:on_time_front/domain/entities/preparation_step_entity.dart' ;
66import 'package:on_time_front/domain/entities/product_usage_event.dart' ;
77import 'package:on_time_front/domain/entities/schedule_entity.dart' ;
8+ import 'package:on_time_front/domain/entities/schedule_preparation_mode.dart' ;
89import 'package:on_time_front/domain/entities/user_entity.dart' ;
910import 'package:on_time_front/domain/use-cases/track_product_usage_event_use_case.dart' ;
1011import 'package:on_time_front/domain/use-cases/create_custom_preparation_use_case.dart' ;
@@ -477,6 +478,121 @@ void main() {
477478 expect (preparationUpdateCount, 0 );
478479 });
479480
481+ test (
482+ 'ScheduleFormUpdated copies default preparation with fresh step IDs' ,
483+ () async {
484+ getScheduleByIdUseCase = StubGetScheduleByIdUseCase (
485+ (_) async => schedule.copyWith (
486+ preparationMode: SchedulePreparationMode .defaultPreparation,
487+ ),
488+ );
489+
490+ PreparationEntity ? updatedPreparation;
491+ updatePreparationByScheduleIdUseCase =
492+ StubUpdatePreparationByScheduleIdUseCase ((preparation, _) async {
493+ updatedPreparation = preparation;
494+ });
495+
496+ final bloc = buildBloc ();
497+ addTearDown (bloc.close);
498+
499+ final editReady = bloc.stream.firstWhere (
500+ (state) => state.status == ScheduleFormStatus .success,
501+ );
502+ bloc.add (const ScheduleFormEditRequested (scheduleId: 'schedule-1' ));
503+ await editReady;
504+
505+ const editedPreparation = PreparationEntity (
506+ preparationStepList: [
507+ PreparationStepEntity (
508+ id: 'default-step-1' ,
509+ preparationName: 'Makeup' ,
510+ preparationTime: Duration (minutes: 20 ),
511+ nextPreparationId: 'default-step-2' ,
512+ ),
513+ PreparationStepEntity (
514+ id: 'default-step-2' ,
515+ preparationName: 'Bathroom' ,
516+ preparationTime: Duration (minutes: 5 ),
517+ ),
518+ ],
519+ );
520+ bloc.add (
521+ const ScheduleFormPreparationChanged (preparation: editedPreparation),
522+ );
523+
524+ final submitDone = bloc.stream.firstWhere (
525+ (state) =>
526+ state.submissionStatus == ScheduleFormSubmissionStatus .success,
527+ );
528+ bloc.add (const ScheduleFormUpdated ());
529+ await submitDone;
530+
531+ final steps = updatedPreparation! .preparationStepList;
532+ expect (steps, hasLength (2 ));
533+ expect (steps[0 ].preparationName, 'Makeup' );
534+ expect (steps[0 ].preparationTime, const Duration (minutes: 20 ));
535+ expect (steps[1 ].preparationName, 'Bathroom' );
536+ expect (steps[1 ].preparationTime, const Duration (minutes: 5 ));
537+ expect (steps[0 ].id, isNot ('default-step-1' ));
538+ expect (steps[1 ].id, isNot ('default-step-2' ));
539+ expect (steps[0 ].nextPreparationId, steps[1 ].id);
540+ expect (steps[1 ].nextPreparationId, isNull);
541+ },
542+ );
543+
544+ test ('ScheduleFormUpdated preserves custom preparation step IDs' , () async {
545+ getScheduleByIdUseCase = StubGetScheduleByIdUseCase (
546+ (_) async =>
547+ schedule.copyWith (preparationMode: SchedulePreparationMode .custom),
548+ );
549+
550+ PreparationEntity ? updatedPreparation;
551+ updatePreparationByScheduleIdUseCase =
552+ StubUpdatePreparationByScheduleIdUseCase ((preparation, _) async {
553+ updatedPreparation = preparation;
554+ });
555+
556+ final bloc = buildBloc ();
557+ addTearDown (bloc.close);
558+
559+ final editReady = bloc.stream.firstWhere (
560+ (state) => state.status == ScheduleFormStatus .success,
561+ );
562+ bloc.add (const ScheduleFormEditRequested (scheduleId: 'schedule-1' ));
563+ await editReady;
564+
565+ const editedPreparation = PreparationEntity (
566+ preparationStepList: [
567+ PreparationStepEntity (
568+ id: 'custom-step-1' ,
569+ preparationName: 'Makeup' ,
570+ preparationTime: Duration (minutes: 20 ),
571+ nextPreparationId: 'custom-step-2' ,
572+ ),
573+ PreparationStepEntity (
574+ id: 'custom-step-2' ,
575+ preparationName: 'Bathroom' ,
576+ preparationTime: Duration (minutes: 5 ),
577+ ),
578+ ],
579+ );
580+ bloc.add (
581+ const ScheduleFormPreparationChanged (preparation: editedPreparation),
582+ );
583+
584+ final submitDone = bloc.stream.firstWhere (
585+ (state) => state.submissionStatus == ScheduleFormSubmissionStatus .success,
586+ );
587+ bloc.add (const ScheduleFormUpdated ());
588+ await submitDone;
589+
590+ final steps = updatedPreparation! .preparationStepList;
591+ expect (steps.map ((step) => step.id), ['custom-step-1' , 'custom-step-2' ]);
592+ expect (steps[0 ].nextPreparationId, 'custom-step-2' );
593+ expect (steps[1 ].nextPreparationId, isNull);
594+ });
595+
480596 test (
481597 'ScheduleFormCreated persists custom preparation when changed' ,
482598 () async {
0 commit comments