diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 39a8765..2cc5db2 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -582,7 +582,6 @@ function ActiveWorkout() { // stopRest() first so a rest that belongs after this set replaces the one that was running. if (freshUnitDone) stopRest() if (!freshUnit || freshUnit.length <= 1) { - if (freshUnitDone && nextUnit?.length) update(s => { if (s.active) s.active.cur = nextUnit[0] }) if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx) return } @@ -590,10 +589,7 @@ function ActiveWorkout() { const step = supersetFlowStep(fresh.entries, freshUnit, idx) if (!step) return if (step.unitDone) { - if (nextUnit?.length) { - update(s => { if (s.active) s.active.cur = nextUnit[0] }) - if (!restBeforeWarmup) startRest(restSec, idx) - } + if (nextUnit?.length && !restBeforeWarmup) startRest(restSec, idx) } else { if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx }) if (step.roundDone) startRest(restSec, idx) diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index 9092791..325d113 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -137,6 +137,13 @@ async function toggleSet(index) { await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) }) } +async function pressNext() { + const button = [...container.querySelectorAll('button')] + .find(button => button.textContent.trim() === 'Next') + expect(button).toBeTruthy() + await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) }) +} + async function pressProgression(index = 0) { const button = container.querySelectorAll('.progline')[index] expect(button).toBeTruthy() @@ -205,7 +212,7 @@ describe('Workout set completion flow', () => { expect(mocks.startRest).not.toHaveBeenCalled() }) - it('auto-captures a completed weighted exercise without prompting and keeps navigation/rest', async () => { + it('auto-captures a completed weighted exercise without prompting, leaving navigation to Next', async () => { await mount([exercise('plain-bench', [false]), exercise('next', [false])]) await toggleSet(0) @@ -213,11 +220,15 @@ describe('Workout set completion flow', () => { expect(mocks.S.active.entries[0].topW).toBe(60) expect(mocks.S.exWeights['plain-bench'].w).toBe(60) expect(mocks.topWeightSheet).not.toHaveBeenCalled() - expect(mocks.S.active.cur).toBe(1) + expect(mocks.S.active.cur).toBe(0) expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) + + await pressNext() + + expect(mocks.S.active.cur).toBe(1) }) - it('auto-captures a completed superset exercise without prompting and preserves superset flow', async () => { + it('auto-captures superset members without prompting, then leaves the completed unit for Next', async () => { const group = 'superset-1' await mount([ exercise('superset-a', [false], { sg: group }), @@ -235,12 +246,16 @@ describe('Workout set completion flow', () => { await toggleSet(1) expect(mocks.topWeightSheet).not.toHaveBeenCalled() - expect(mocks.S.active.cur).toBe(2) + expect(mocks.S.active.cur).toBe(1) expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) + + await pressNext() + + expect(mocks.S.active.cur).toBe(2) }) it.each(['warmup', 'warm-up', 'warm_up'])( - 'does not start transition rest before an incomplete %s row in the next ordinary exercise', + 'does not navigate or start transition rest before an incomplete %s row in the next ordinary exercise', async phase => { await mount([ exercise('current', [false], { asked: true }), @@ -255,12 +270,12 @@ describe('Workout set completion flow', () => { await toggleSet(0) - expect(mocks.S.active.cur).toBe(1) + expect(mocks.S.active.cur).toBe(0) expect(mocks.startRest).not.toHaveBeenCalled() }, ) - it('does not start transition rest when a completed superset advances to an incomplete warm-up', async () => { + it('does not navigate or start transition rest when a completed superset meets an incomplete warm-up', async () => { await mount([ exercise('superset-a', [true], { sg: 'group', asked: true }), exercise('superset-b', [false], { sg: 'group', asked: true }), @@ -275,11 +290,11 @@ describe('Workout set completion flow', () => { await toggleSet(1) - expect(mocks.S.active.cur).toBe(2) + expect(mocks.S.active.cur).toBe(1) expect(mocks.startRest).not.toHaveBeenCalled() }) - it('advances without transition rest before an incomplete warm-up', async () => { + it('leaves the completed ordinary exercise selected without transition rest before an incomplete warm-up', async () => { await mount([ exercise('current-loaded', [false]), exercise('next', [false, false], { @@ -294,7 +309,7 @@ describe('Workout set completion flow', () => { await toggleSet(0) expect(mocks.topWeightSheet).not.toHaveBeenCalled() - expect(mocks.S.active.cur).toBe(1) + expect(mocks.S.active.cur).toBe(0) expect(mocks.startRest).not.toHaveBeenCalled() }) @@ -318,7 +333,7 @@ describe('Workout set completion flow', () => { expect(mocks.startRest).not.toHaveBeenCalled() }) - it('advances after a completed superset without opening a top-weight sheet', async () => { + it('leaves a completed superset selected without opening a top-weight sheet', async () => { const group = 'superset-1' await mount([ exercise('superset-a', [true, true, true], { sg: group, asked: true }), @@ -328,11 +343,11 @@ describe('Workout set completion flow', () => { await toggleSet(5) expect(mocks.topWeightSheet).not.toHaveBeenCalled() - expect(mocks.S.active.cur).toBe(2) + expect(mocks.S.active.cur).toBe(1) expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) }) - it('skips completed intervening units and selects the next unfinished superset as one unit', async () => { + it('does not auto-select an unfinished superset after completing an ordinary exercise', async () => { await mount([ exercise('current-hold', [false], { asked: true, target: { mode: 'time', sec: 30, weight: 0 } }), exercise('already-done', [true], { asked: true }), @@ -342,13 +357,13 @@ describe('Workout set completion flow', () => { await toggleSet(0) - expect(mocks.S.active.cur).toBe(2) + expect(mocks.S.active.cur).toBe(0) expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled() expect(mocks.toast).toHaveBeenCalledWith('Hold logged') expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) }) - it('wraps to earlier unfinished work instead of showing a false completion prompt', async () => { + it('does not auto-select earlier unfinished work after completing an ordinary exercise', async () => { await mount([ exercise('pending-earlier', [false], { asked: true }), exercise('current-hold', [false], { asked: true, target: { mode: 'time', sec: 30, weight: 0 } }), @@ -356,12 +371,12 @@ describe('Workout set completion flow', () => { await toggleSet(0) - expect(mocks.S.active.cur).toBe(0) + expect(mocks.S.active.cur).toBe(1) expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled() expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) }) - it('advances a completed ordinary exercise without declaring completion while work remains', async () => { + it('leaves a completed ordinary exercise selected without declaring completion while work remains', async () => { await mount([ exercise('current-loaded', [false]), exercise('pending', [false], { asked: true }), @@ -371,7 +386,7 @@ describe('Workout set completion flow', () => { expect(mocks.topWeightSheet).not.toHaveBeenCalled() expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled() - expect(mocks.S.active.cur).toBe(1) + expect(mocks.S.active.cur).toBe(0) expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number)) }) @@ -384,6 +399,7 @@ describe('Workout set completion flow', () => { await toggleSet(0) expect(mocks.workoutCompleteSheet).toHaveBeenCalledOnce() + expect(mocks.S.active.cur).toBe(1) expect(mocks.startRest).not.toHaveBeenCalled() }) }) @@ -395,7 +411,7 @@ describe('Workout add exercise flow', () => { active: { routineId: 'routine-1' }, routines: [{ id: 'routine-1', ex: [] }], }], - ])('inserts after the current unit and continues to pending work in a %s session', async (_label, overrides) => { + ])('inserts after the current unit and leaves the inserted exercise selected after completion in a %s session', async (_label, overrides) => { await mount([ exercise('current', [true], { asked: true }), exercise('pending', [false], { asked: true }), @@ -413,7 +429,7 @@ describe('Workout add exercise flow', () => { await toggleSet(0) expect(mocks.S.active.entries[1].sets[0].done).toBe(true) - expect(mocks.S.active.cur).toBe(2) + expect(mocks.S.active.cur).toBe(1) expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled() })