diff --git a/test/application/use_cases_test.dart b/test/application/use_cases_test.dart index c70cda7..c195c99 100644 --- a/test/application/use_cases_test.dart +++ b/test/application/use_cases_test.dart @@ -1281,6 +1281,76 @@ void main() { }, ); + test( + 'step chaining disabled stops at first elapsed timed boundary after kill', + () async { + final clock = _FakeClock(DateTime.utc(2026, 7, 17, 12)); + final session = _sessionWithSnapshot( + currentProgramIndex: 0, + currentExerciseIndex: 0, + currentSetIndex: 0, + setsCount: 1, + targetReps: 1, + autoStartNextTimedStepSnapshot: false, + exerciseSteps: [ + ..._twoTimedSteps(), + _step( + id: 'step-3', + position: 2, + name: 'Centre', + type: ExerciseStepType.time, + defaultTargetValue: 1, + ), + ], + ); + final repository = _FakeActiveSessionRepository()..session = session; + + await ActiveExerciseStepUseCases( + sessionRepository: repository, + clock: clock, + ids: _FakeIds(), + originDeviceId: 'device-1', + ).startOrResumeProgress( + sessionId: session.metadata.id, + programIndex: 0, + exerciseIndex: 0, + setIndex: 0, + ); + await ActiveExerciseStepUseCases( + sessionRepository: repository, + clock: clock, + ids: _FakeIds(), + originDeviceId: 'device-1', + ).startTimer( + sessionId: session.metadata.id, + programIndex: 0, + exerciseIndex: 0, + setIndex: 0, + ); + clock.value = clock.value.add(const Duration(milliseconds: 4500)); + + final reconstructed = ActiveExerciseStepUseCases( + sessionRepository: repository, + clock: clock, + ids: _FakeIds(), + originDeviceId: 'device-1', + ); + final view = await reconstructed.startOrResumeProgress( + sessionId: session.metadata.id, + programIndex: 0, + exerciseIndex: 0, + setIndex: 0, + ); + + expect(view.state.status, ActiveExerciseStepProgressStatus.stoppedTimer); + expect(view.state.currentStepIndex, 1); + expect(view.state.startedAt, isNull); + expect(view.state.accumulatedMs, 0); + expect(repository.stepResults, hasLength(1)); + expect(repository.stepResults.single.stepIndex, 0); + }, + ); + test( 'step chaining resolution uses program override before exercise snapshot', () async {