This commit is contained in:
Duarte Santos committed 2026-08-30 13:36:31 +02:00
commit 0e3b8fa74b
18 files changed
+366 -2

No files matched your search

+6 -1
View File
@@ -10,7 +10,7 @@ import { t, exerciseNameFor } from '../lib/i18n.js'
import { api } from '../lib/api.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet } from '../sheets.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js'
@@ -645,6 +645,11 @@ function ActiveWorkout() {
disabled={!!work || !canMoveActiveWorkoutUnit(A, cur, 1)} onClick={() => moveCurrentUnit(1)}>{t('Move down')}</Button>
</div>
<div style={{ height: 6 }} />
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button size="sm" icon="shuffle" aria-label={t('Swap exercise')} disabled={!!work}
onClick={() => swapActiveWorkoutExercise(cur)}>{t('Swap exercise')}</Button>
</div>
<div style={{ height: 6 }} />
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button size="sm" icon="minus" style={{ color: 'var(--red)' }} disabled={!!work} onClick={removeExerciseSheet}>{t('Remove exercise')}</Button>
</div>
+16 -1
View File
@@ -19,6 +19,7 @@ const mocks = vi.hoisted(() => {
exConfigSheet: vi.fn(),
toast: vi.fn(),
scrollCalls: [],
swapActiveWorkoutExercise: vi.fn(),
}
state.stopRest = vi.fn(() => { state.timer = null })
state.stopWork = vi.fn(() => { state.work = null })
@@ -64,6 +65,7 @@ vi.mock('../sheets.jsx', () => ({
finishWorkout: vi.fn(),
workoutCompleteSheet: mocks.workoutCompleteSheet,
confirmSheet: mocks.confirmSheet,
swapActiveWorkoutExercise: mocks.swapActiveWorkoutExercise,
// Both note sheets belong here even though the tests never open one: Workout.jsx reads
// sessionNoteSheet during render, so a missing export is a render crash, not a no-op.
exerciseNoteSheet: vi.fn(),
@@ -543,7 +545,7 @@ describe('active workout whole-unit move controls', () => {
expect(mocks.S.active.entries[1].sets).toEqual([{ w: 77.5, r: 6, done: true, rir: 2 }])
expect(mocks.S.active.cur).toBe(1)
expect(mocks.stopWork).toHaveBeenCalledOnce()
expect(mocks.stopRest).toHaveBeenCalledOnce()
expect(mocks.stopRest).not.toHaveBeenCalled()
})
it('moves the selected contiguous group as one unit without changing its metadata', async () => {
@@ -575,3 +577,16 @@ describe('active workout whole-unit move controls', () => {
expect(action('Move down')?.disabled).toBe(true)
})
})
describe('active exercise swap control', () => {
it('opens the swap flow for the selected duplicate occurrence', async () => {
await mount([exercise('bench', [false]), exercise('bench', [false]), exercise('row', [false])], 1)
const swap = container.querySelector('button[aria-label="Swap exercise"]')
expect(swap).toBeTruthy()
await act(async () => { swap.dispatchEvent(new dom.Event('click', { bubbles: true })) })
expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledOnce()
expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledWith(1)
})
})