Skip to content

Commit 62b0b08

Browse files
authored
Merge pull request #78 from hyldmo/claude/fix-rest-timer-logic-JH4bR
2 parents 46158dc + 24873a8 commit 62b0b08

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/features/workouts/store/useWorkoutSessionStore.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ describe('startRest() [checklist mode]', () => {
226226
expect(store().rest!.endAt).toBe(5000 + 60 * 1000)
227227
})
228228

229+
it('T12b: solo exercise — set time NOT subtracted from rest', () => {
230+
const sets = [makeSet({ setNumber: 1 }), makeSet({ setNumber: 2 })]
231+
store().init('wks_1', 1000, sets)
232+
233+
vi.setSystemTime(1000)
234+
store().startSet() // start doing the set
235+
vi.setSystemTime(31000) // 30 seconds doing the set
236+
store().confirmSet()
237+
vi.setSystemTime(32000)
238+
store().startRest(60, 'working')
239+
240+
// Full 60 seconds of rest — time spent doing the set should not be subtracted
241+
expect(store().rest!.total).toBe(60)
242+
})
243+
229244
it('T13: has _roundStartedAt → subtracts elapsed time', () => {
230245
store().init('wks_1', 1000, [makeSet()])
231246
vi.setSystemTime(1000)
@@ -239,6 +254,30 @@ describe('startRest() [checklist mode]', () => {
239254
})
240255
})
241256

257+
describe('superset rest timing', () => {
258+
it('T13b: superset — transition time subtracted from rest, but NOT first set time', () => {
259+
const sets = [...makeSupersetPair({ group: 1, itemIndex: 0 }), ...makeSupersetPair({ group: 1, itemIndex: 0 })]
260+
store().init('wks_1', 1000, sets)
261+
262+
// Spend 30 seconds doing the first set (A1) — should NOT count
263+
vi.setSystemTime(1000)
264+
store().startSet()
265+
vi.setSystemTime(31000)
266+
267+
// Confirm A1 (transition=true) → _roundStartedAt set NOW (at 31000)
268+
store().confirmSet()
269+
expect(store()._roundStartedAt).toBe(31000)
270+
271+
// Spend 10 seconds transitioning + doing B1
272+
vi.setSystemTime(41000)
273+
store().confirmSet() // Confirm B1 (transition=false, last in round)
274+
275+
// Start rest — 10 seconds of transition time should be subtracted
276+
store().startRest(60, 'working')
277+
expect(store().rest!.total).toBe(50) // 60 - 10 = 50
278+
})
279+
})
280+
242281
describe('undo()', () => {
243282
it('T14: no confirmed sets → no-op', () => {
244283
store().init('wks_1', 1000, [makeSet()])
@@ -279,12 +318,14 @@ describe('setLogId', () => {
279318
})
280319

281320
describe('set timer control', () => {
282-
it('T18: startSet → sets setTimer.startedAt', () => {
321+
it('T18: startSet → sets setTimer.startedAt, does NOT set _roundStartedAt', () => {
283322
store().init('wks_1', 1000, [makeSet()])
284323
vi.setSystemTime(5000)
285324
store().startSet()
286325
expect(store().active?.setTimer?.startedAt).toBe(5000)
287326
expect(store().active?.setTimer?.isPaused).toBe(false)
327+
// Starting a set should not begin tracking round time — only superset transitions should
328+
expect(store()._roundStartedAt).toBeNull()
288329
})
289330

290331
it('T19: pauseSet → sets isPaused', () => {

src/features/workouts/store/useWorkoutSessionStore.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ export const useWorkoutSessionStore = create<WorkoutSessionStore>((set, get) =>
267267
set(s => {
268268
if (!s.active) return {}
269269
return {
270-
active: { ...s.active, setTimer: { startedAt: Date.now(), isPaused: false } },
271-
_roundStartedAt: s._roundStartedAt ?? Date.now()
270+
active: { ...s.active, setTimer: { startedAt: Date.now(), isPaused: false } }
272271
}
273272
})
274273
},

0 commit comments

Comments
 (0)