notes: make the session note real, and stop losing it

v1.2.10 shipped the session note as one of three kinds of note, and the release
notes say so. Only two of them existed.

buildCompletedWorkout read `active.note` and carried it onto the finished
workout — with a test covering it — but nothing anywhere in the app ever wrote
that field. The only way to get a session note was to open a past workout in
history and type one there, which is a different and much smaller feature than
"notes you can write during a workout". So the workout screen now has one, next
to the finish button: wrapping up is when you know how the session went. It
writes `active.note`, which makes the path that was already there and already
tested actually reachable.

The history one then threw the text away. It saved on blur only, and Escape, the
Android back gesture and swipe-to-dismiss all close a sheet without ever moving
focus out of the textarea — type a note, press Escape, gone. It now flushes on
unmount as well, through a ref, because a cleanup closes over the note from its
own render, which is the empty string it started with. Writing only happens when
the text actually changed, and deleting the workout from that same sheet leaves
nothing to write to, which the guard covers.

The new sheet has a Save button rather than repeating the blur trick.

Also adds both note sheets to Workout.test.jsx's module mock. Workout.jsx reads
sessionNoteSheet during render, so a missing export there is a render crash
rather than a quiet no-op — which is exactly how this was caught.
This commit is contained in:
Duarte Santos committed 2026-08-25 21:55:22 +02:00
1 parent 287550df6c
commit 3d30edddad
16 files changed
+155 -3

No files matched your search

+2 -2
View File
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(291)
expect(inherited).toHaveLength(447)
expect(inherited).toHaveLength(449)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('5eca6d8b564c208b41f1be1890e3eaa0313e0ab901ed40a03b5d3071a65bd9f1')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('09c4fa5e04c8d3ea21916a6c07f074a35013b33d5d945ecfc13cd54cc8b7d41d')
})
test('does not leak European Portuguese UI terms', () => {
+73
View File
@@ -0,0 +1,73 @@
// @vitest-environment happy-dom
// The session note shipped with a hole in it: buildCompletedWorkout read `active.note` and
// nothing in the app ever wrote it, so the only way to get one was after the fact — and that
// path threw the text away unless you happened to tab out of the field first.
import { describe, expect, it, beforeEach, afterEach } from 'vitest'
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { useStore } from '../store/useStore.js'
import { useUI } from '../store/useUI.js'
import { sessionNoteSheet, workoutDetailSheet } from '../sheets.jsx'
import { buildCompletedWorkout } from './finish-workout.js'
const mounted = []
function render(open) {
open()
const sheet = useUI.getState().sheets.at(-1)
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
mounted.push(root)
act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
return host
}
const type = (el, value) => {
Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value)
el.dispatchEvent(new Event('input', { bubbles: true }))
}
const unmountAll = () => act(() => { mounted.splice(0).forEach(r => r.unmount()) })
const workout = () => ({
id: 'w1', d: '2026-08-25', start: 1, end: 2, name: 'Push', vol: 100,
entries: [{ id: 'bench', sets: [{ w: 100, r: 5, done: true }] }], prs: [],
})
describe('session note', () => {
beforeEach(() => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true
useUI.setState({ sheets: [] })
document.body.innerHTML = ''
})
afterEach(unmountAll)
it('can be written during the workout and survives finishing', () => {
useStore.setState(s => ({
S: { ...s.S, active: { id: 'w1', d: '2026-08-25', start: 1, name: 'Push', entries: [{ id: 'bench', sets: [] }] } },
}))
const host = render(() => sessionNoteSheet())
act(() => { type(host.querySelector('textarea'), 'slept badly, still hit it') })
act(() => { [...host.querySelectorAll('button')].find(b => /save/i.test(b.textContent)).click() })
const A = useStore.getState().S.active
expect(A.note).toBe('slept badly, still hit it')
// The path buildCompletedWorkout already had a test for is now actually reachable.
expect(buildCompletedWorkout(A, { end: 2 }).note).toBe('slept badly, still hit it')
})
it('is kept when the history sheet is dismissed without blurring the field', () => {
useStore.setState(s => ({ S: { ...s.S, workouts: [workout()] } }))
const host = render(() => workoutDetailSheet(useStore.getState().S.workouts[0]))
act(() => { type(host.querySelector('textarea'), 'good session') })
// Escape / Android back / swipe all unmount without a blur.
unmountAll()
expect(useStore.getState().S.workouts[0].note).toBe('good session')
})
it('clearing it removes the note rather than storing an empty string', () => {
useStore.setState(s => ({ S: { ...s.S, workouts: [{ ...workout(), note: 'old' }] } }))
const host = render(() => workoutDetailSheet(useStore.getState().S.workouts[0]))
act(() => { type(host.querySelector('textarea'), ' ') })
unmountAll()
expect(useStore.getState().S.workouts[0].note).toBeUndefined()
})
})