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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
test: mount the note sheet for real
Duarte Santosbbf46e2aa2bf
diff --git a/frontend/src/lib/notes-render.test.jsx b/frontend/src/lib/notes-render.test.jsxnew file mode 100644index 000000000..153f829f7--- /dev/null+++ b/frontend/src/lib/notes-render.test.jsx@@ -0,0 +1,80 @@+// @vitest-environment happy-dom+// The note sheet is new JSX and nothing else mounts it, so a bad hook order, a missing import or+// a wrong store path would only surface on a real device. Render it through the real sheet stack+// and drive a save, so the wiring is checked and not just the shape of the module.+import { describe, expect, it, beforeEach } from 'vitest'+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'++// React only enables act() when it is told it is in a test environment.+globalThis.IS_REACT_ACT_ENVIRONMENT = true+import { useStore } from '../store/useStore.js'+import { useUI } from '../store/useUI.js'+import { exerciseNoteSheet } from '../sheets.jsx'++const activeWith = entry => ({ id: 'w1', d: '2026-08-25', start: 1, routineId: 'r1', name: 'Push', entries: [entry] })++function renderSheet() {+ exerciseNoteSheet(0)+ const sheet = useUI.getState().sheets.at(-1)+ const host = document.createElement('div')+ document.body.appendChild(host)+ const root = createRoot(host)+ act(() => root.render(sheet.render(sheet_close(sheet))))+ return host+}+const sheet_close = sheet => () => useUI.getState().closeSheet(sheet.id)++const type = (el, value) => {+ const setter = Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set+ setter.call(el, value)+ el.dispatchEvent(new Event('input', { bubbles: true }))+}++describe('exercise note sheet', () => {+ beforeEach(() => {+ useUI.setState({ sheets: [] })+ useStore.setState(s => ({+ S: { ...s.S, exNotes: {}, active: activeWith({ id: 'bench', sets: [] }) },+ }))+ document.body.innerHTML = ''+ })++ it('renders the session note, the pin and the standing note', () => {+ const host = renderSheet()+ const areas = host.querySelectorAll('textarea')+ expect(areas).toHaveLength(2)+ // The pin cannot be set on an empty note — it would pin nothing.+ expect(host.querySelector('[role="switch"]').disabled).toBe(true)+ })++ it('saves the session note with its pin and the standing note separately', () => {+ const host = renderSheet()+ const [today, always] = host.querySelectorAll('textarea')+ act(() => { type(today, 'shoulder twinged'); type(always, 'seat at 4') })+ act(() => { host.querySelector('[role="switch"]').click() })+ const save = [...host.querySelectorAll('button')].find(b => /save/i.test(b.textContent))+ act(() => { save.click() })++ const S = useStore.getState().S+ expect(S.active.entries[0].note).toBe('shoulder twinged')+ expect(S.active.entries[0].notePin).toBe(true)+ // The standing note belongs to the exercise, not to today's entry.+ expect(S.exNotes.bench).toBe('seat at 4')+ expect(useUI.getState().sheets).toHaveLength(0)+ })++ it('clearing the session note drops the pin with it', () => {+ useStore.setState(s => ({+ S: { ...s.S, active: activeWith({ id: 'bench', sets: [], note: 'old', notePin: true }) },+ }))+ const host = renderSheet()+ const [today] = host.querySelectorAll('textarea')+ act(() => { type(today, '') })+ const save = [...host.querySelectorAll('button')].find(b => /save/i.test(b.textContent))+ act(() => { save.click() })+ const e = useStore.getState().S.active.entries[0]+ expect(e.note).toBeUndefined()+ expect(e.notePin).toBeUndefined()+ })+})