Files
kuentagym/frontend/src/sheets.backfill.test.jsx
T
Duarte Santos a0a44cb6c0 Phone-width layout: a list row's title asks only for its own longest word, a date or time field drops a line rather than the screen edge, and the page title steps down instead of shredding
Three pieces of collateral from d7bb67a, which fixed C8/C23 and C25 with two blunter
rules than those findings needed. Both of its fixes stay fixed; what they cost the
rows and titles around them does not.

.lrow-m, the title column. The 104px floor was the width of one long word, but every
row pays it, and a row whose only flexible part is the title has nothing else to give.
In the backfill sheet's Date and Start-time rows the floor came straight out of the
<input type=date>: at 320px it ended 23px off the right of the screen with its calendar
picker entirely off-screen, so on a small phone there was no way to open the picker at
all. The floor also took space from values that used to fit — "Freies Training" became
"Freies …", and the Rule row's value dropped from 141px to 113px. min-width:auto, the
flex default this rule had switched off, is the floor the Progression row was actually
asking for: its own longest word, which for "Routine" is 63px and for "Progression"
96px. Every row now asks for exactly what its title needs and no more. It also closes a
row the floor never reached: German "Intensivierungstechnik" ran 18px over the value
beside it on v1.3.7 and on the branch, and now it does not.

The two rows with a date or time field. Even at its own longest word a title can leave
that field nothing: Polish "Godzina rozpoczęcia" plus the clock is 17px more than a
320px row holds, and the same is true of the Settings reminder row, whose field hung
3px off the screen in every language. Those rows now wrap the field onto a line of its
own under the title, still flush right — the same shape a row with an inline segmented
control already uses when its control and title cannot share a line.

.hdr h1, the page title. min-width:0 on the title block and flex:none on the button are
what keep the header button reachable, and they stay. What came apart was the title left
in the 95 to 125px the Library's "By muscle" button leaves it: hyphens:auto spends a
character's worth of width on the hyphen itself, and in a box that tight that was the
difference between two lines and three — "Упражнения" rendered as "Упра / жнен / ия" in
a 170px header, "Ćwiczenia" and "Gyakorlatok" the same. Below 420px, every phone width
we test, the title now drops a step to 30px, at which all 14 packs take two lines at
most with a character of slack; hyphens:auto is gone, and a word that still does not fit
is broken with overflow-wrap:break-word rather than :anywhere, which moves the whole word
to the next line before breaking it — :anywhere broke "Bartholomew_Jones" mid-word even
at 412px, where a line of its own was waiting for it.

Measured on the QA rig (scripts/opengym-qa/run/r3-layout-collateral/, en/de/ru at
320/368/412 plus all 14 packs at 320/368, the header set also with Roboto injected):
  backfill  <input type=date> / <input type=time> right edge at 320px, de: 343 / 325
            (23px and 5px off a 320px screen) -> 288 / 288, both inside the card, both
            picker icons visible. pl "Godzina rozpoczęcia" 325 (5px off) -> wraps, 288.
            en and ru 288 / 288 on one line. 360, 368 and 412 clean in every pack.
  Routine   value box at 320px, de: 72px ("Freies …") -> 113px ("Freies Train…"). The
            German string wants 119px and the row has 176px for title plus value, so
            v1.3.7's 119px was bought by letting "Routine" spill 6px into the value's
            box. en 72px (clipped) -> 75px, not clipped, as on v1.3.7.
  Rule      value box at 320 / 368 / 412: 113 / 161 / 191 -> 141 / 167 / 191, which is
            v1.3.7's 141 / 167 / 191 exactly.
  C8/C23    "Progression" title box / how far the title runs onto the value, 320px:
            v1.3.7 37px / +47, branch 104 / -20, now 96 / -12 (ru 102 / -12). 368px:
            v1.3.7 65-74 / +10..+19, now 96 / -12. ru 412: v1.3.7 80 / +10, now 102 / -12.
  C25       Library button right edge, ru at 320 / 368: v1.3.7 388 / 388 (off both
            screens) -> 304 / 352, button reachable. Title lines at 320: branch
            Упра/жнен/ия, header 170px -> Упраж/нения, 126px; hu Gyak/orlat/ok, 151px ->
            two lines; pl Ćwic/zeni/a -> Ćwicz/enia. ru at 412 is back to one line.
  headers   15 packs x /library /settings /home x 320/368/412 with Roboto: 135 headers,
            none over two lines, every button on screen. The one title that still takes
            three lines is "Hi Bartholomew_Jones" at 320 and 368 — a 17-character token
            with no break in it; at 412 it is two lines, where the branch had three.
  sweep     Every .lrow of Settings, the routine editor, the exercise config sheet and
            the backfill sheet in all 14 packs at 320 and 368: 1170 rows, 30 of them
            poking out of their row on the branch, 0 now.
Known trade: German "Intensivierungstechnik" and "Keine" cannot both fit a 320px row.
The title now has its word and the value ellipsises to "K…" (46px -> 28px) where before
the title ran 18px over it. Thai wraps "การเพิ่มระดับ" onto two lines at 320 rather than
holding a 104px column open for it.
Vitest: 117 files, 1535 tests green (1533 plus the two added here); locales in sync; the
source-string baseline stays at 33. No new user-facing strings.
2026-09-20 17:46:09 +02:00

90 lines
4.3 KiB
React

// @vitest-environment happy-dom
import React, { act } from 'react'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createRoot } from 'react-dom/client'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
import { logPastWorkoutSheet } from './sheets.jsx'
import { todayISO } from './lib/format.js'
const mounted = []
function type(el, value) {
Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value)
el.dispatchEvent(new Event('input', { bubbles: true }))
}
function mountTopSheet() {
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 button = (host, text) => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)
const cssSource = readFileSync(resolve(process.cwd(), 'src/index.css'), 'utf8')
describe('log a past workout', () => {
beforeEach(() => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true
useUI.setState({ sheets: [], toasts: [] })
useStore.setState(s => ({ S: { ...s.S, active: null, routines: [], workouts: [{ id: 'old', d: todayISO(), start: 1, end: 2, name: 'Old', entries: [], prs: [] }] } }))
document.body.innerHTML = ''
})
afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })
it('refuses while a workout is running', () => {
const toast = vi.fn()
useUI.setState({ toast })
useStore.setState(s => ({ S: { ...s.S, active: { id: 'a', entries: [] } } }))
logPastWorkoutSheet()
expect(useUI.getState().sheets).toHaveLength(0)
expect(toast).toHaveBeenCalledWith('Finish the current workout first.')
})
it('asks what to do when the day already has a workout', () => {
logPastWorkoutSheet()
const host = mountTopSheet()
expect(host.querySelector('h3').textContent).toBe('Log a past workout')
act(() => { type(host.querySelector('input[type=date]'), todayISO()) })
act(() => { button(host, 'Continue').click() })
const prompt = mountTopSheet()
expect(prompt.textContent).toContain('There is already a workout on that day.')
expect(['Replace', 'Add as second workout', 'Cancel'].map(t => !!button(prompt, t))).toEqual([true, true, true])
expect(useStore.getState().S.active).toBeNull()
})
// The Date and Start-time rows are the only .lrow rows in the app that pair a title with a
// fixed-width field and nothing that can give way. A pixel floor under the title column therefore
// comes straight out of the field: 104px pushed the date input 23px off a 320px screen, calendar
// picker and all, so there was no way to open the picker on a small phone. The floor has to be the
// row's own longest word (min-width:auto), which these short titles barely ask for.
it('gives the date and time fields a title column that can shrink', () => {
logPastWorkoutSheet()
const host = mountTopSheet()
const fields = [...host.querySelectorAll('.lrow input.timef')]
expect(fields.map(i => i.type)).toEqual(['date', 'time'])
for (const field of fields) expect(field.closest('.lrow').querySelectorAll('.lrow-v')).toHaveLength(0)
const rule = cssSource.match(/^\.lrow-m\{([^}]*)\}/m)
expect(rule?.[1]).toContain('min-width:auto')
expect(rule[1]).not.toMatch(/min-width:\s*[\d.]/)
// and where even the longest word leaves no room for the field (Polish "Godzina rozpoczęcia"
// at 320px), the field drops onto its own line rather than over the edge of the card.
expect(cssSource).toContain('.lrow:has(.timef){flex-wrap:wrap}')
expect(cssSource).toContain('.lrow>.timef{margin-left:auto}')
})
it('starts a backfilled session straight away on a free day', () => {
logPastWorkoutSheet()
const host = mountTopSheet()
act(() => { type(host.querySelector('input[type=date]'), '2020-01-02') })
act(() => { button(host, 'Continue').click() })
const A = useStore.getState().S.active
expect(A.d).toBe('2020-01-02')
expect(new Date(A.start).getHours()).toBe(18)
expect(A.backfill).toEqual({ durationMin: 60, replaceId: null })
})
})