Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Tests: a hold's end hands its owner the chime and a displaced hold's hand-back as options, and the rest-timer tests know the chime

Duarte Santos81e3c00c9cda
diff --git a/frontend/src/components/RestTimer.ready.test.jsx b/frontend/src/components/RestTimer.ready.test.jsx
index 240c04ed4..e5c746b77 100644
--- a/frontend/src/components/RestTimer.ready.test.jsx
+++ b/frontend/src/components/RestTimer.ready.test.jsx
@@ -8,7 +8,7 @@ import { useStore } from '../store/useStore.js'
globalThis.IS_REACT_ACT_ENVIRONMENT = true
-vi.mock('../lib/sound.js', () => ({ beep: vi.fn(), vibrate: vi.fn() }))
+vi.mock('../lib/sound.js', () => ({ beep: vi.fn(), chime: vi.fn(), vibrate: vi.fn() }))
let host, root, originalS
diff --git a/frontend/src/store/useUI.pause.test.js b/frontend/src/store/useUI.pause.test.js
index d3ed72bf7..3ce1d3a17 100644
--- a/frontend/src/store/useUI.pause.test.js
+++ b/frontend/src/store/useUI.pause.test.js
@@ -4,8 +4,8 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'
vi.mock('../lib/api.js', () => ({ api: vi.fn(() => Promise.resolve({ ok: true })) }))
-const { beep } = vi.hoisted(() => ({ beep: vi.fn() }))
-vi.mock('../lib/sound.js', () => ({ beep, vibrate: vi.fn() }))
+const { beep, chime } = vi.hoisted(() => ({ beep: vi.fn(), chime: vi.fn() }))
+vi.mock('../lib/sound.js', () => ({ beep, chime, vibrate: vi.fn() }))
import { api } from '../lib/api.js'
import { useUI } from './useUI.js'
@@ -22,6 +22,7 @@ describe('pausing the rest timer', () => {
useUI.setState({ timer: null, work: null, timerFlashId: 0, toastMsg: '' })
api.mockClear()
beep.mockClear()
+ chime.mockClear()
})
afterEach(() => {
useUI.getState().stopRest()
@@ -40,6 +41,7 @@ describe('pausing the rest timer', () => {
expect(useUI.getState().timer).toMatchObject({ left: 60, paused: true })
expect(useUI.getState().timer.ready).toBeUndefined()
expect(beep).not.toHaveBeenCalled()
+ expect(chime).not.toHaveBeenCalled()
expect(useUI.getState().toastMsg).toBe('')
useUI.getState().resumeRest()
@@ -49,6 +51,7 @@ describe('pausing the rest timer', () => {
vi.advanceTimersByTime(1000)
expect(useUI.getState().timer).toMatchObject({ left: 0, ready: true, forIdx: 1 })
expect(useUI.getState().timerFlashId).toBe(1) // ended on screen: the usual alert
+ expect(chime).toHaveBeenCalledTimes(1)
})
it('cancels the push booked for the old end and books it again on resume', () => {
@@ -110,6 +113,6 @@ describe('pausing the rest timer', () => {
useUI.getState().startWork(30, 'Plank', done)
expect(useUI.getState().timer).toBeNull()
vi.advanceTimersByTime(30000)
- expect(done).toHaveBeenCalledExactlyOnceWith(30)
+ expect(done).toHaveBeenCalledExactlyOnceWith(30, { chimed: true })
})
})
diff --git a/frontend/src/store/useUI.test.js b/frontend/src/store/useUI.test.js
index 7f81b763b..cf9faee01 100644
--- a/frontend/src/store/useUI.test.js
+++ b/frontend/src/store/useUI.test.js
@@ -157,7 +157,7 @@ describe('a rest and a hold never run together', () => {
// finish. The count alone would not say which: a hold left running reaches its own zero and
// calls back too, with the full 30 s target for a set that stopped being held at 12.
expect(holdDone).toHaveBeenCalledTimes(1)
- expect(holdDone).toHaveBeenCalledWith(12, true)
+ expect(holdDone).toHaveBeenCalledWith(12, { abandoned: true })
})
// The hold cannot survive the rest, but the time it held is real: it is handed back on the way
@@ -170,7 +170,7 @@ describe('a rest and a hold never run together', () => {
useUI.getState().startRest(90, 1)
expect(useUI.getState().work).toBe(null)
expect(holdDone).toHaveBeenCalledTimes(1)
- expect(holdDone).toHaveBeenCalledWith(18, true) // the seconds held, and: abandoned
+ expect(holdDone).toHaveBeenCalledWith(18, { abandoned: true }) // the seconds held, and: abandoned
})
it('under two seconds there is nothing to hand back — that was a play button by accident', () => {
@@ -187,7 +187,7 @@ describe('a rest and a hold never run together', () => {
useUI.getState().startWork(45, 'Plank', first)
vi.advanceTimersByTime(18_000)
useUI.getState().startWork(60, 'Side plank', vi.fn())
- expect(first).toHaveBeenCalledWith(18, true)
+ expect(first).toHaveBeenCalledWith(18, { abandoned: true })
expect(useUI.getState().work.total).toBe(60)
})
@@ -249,7 +249,7 @@ describe('rest readiness and optional timed-set overtime', () => {
const done = vi.fn()
useUI.getState().startWork(1, 'Hold', done)
vi.advanceTimersByTime(901000)
- expect(done).toHaveBeenCalledExactlyOnceWith(901)
+ expect(done).toHaveBeenCalledExactlyOnceWith(901, { chimed: false })
expect(useUI.getState().work).toBeNull()
})
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index 3e621bb51..9d10dce91 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -667,7 +667,7 @@ describe('a hold a rest displaced', () => {
}
// What useUI.abandonWork hands the owner: the seconds held, and "this was not a finish".
const handBack = async (elapsed, call = 0) => {
- await act(async () => { mocks.startWork.mock.calls[call][2](elapsed, true) })
+ await act(async () => { mocks.startWork.mock.calls[call][2](elapsed, { abandoned: true }) })
await rerender()
}