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
Combine routines (ENG-9) phase 4: UI surfaces
Henryc63ec2ca6c84
diff --git a/frontend/src/sheets.combine-ui.test.jsx b/frontend/src/sheets.combine-ui.test.jsxnew file mode 100644index 000000000..fba38e0de--- /dev/null+++ b/frontend/src/sheets.combine-ui.test.jsx@@ -0,0 +1,111 @@+// @vitest-environment happy-dom+import React, { act } from 'react'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { createRoot } from 'react-dom/client'+import { useStore } from './store/useStore.js'+import { useUI } from './store/useUI.js'+import { addRoutineToSessionSheet, workoutDetailSheet } from './sheets.jsx'+import { EXDB } from './lib/exercises.js'++const clone = v => JSON.parse(JSON.stringify(v))+const ids = EXDB.filter(e => e.bp !== 'cardio').slice(0, 4).map(e => e.id)+const mounted = []++function renderTop() {+ 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 rowFor = (host, name) => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)++beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ useUI.setState({ sheets: [], toastMsg: '' })+ document.body.innerHTML = ''+})+afterEach(() => { act(() => { mounted.splice(0).forEach(r => r.unmount()) }) })++describe('Add routine mid-session sheet', () => {+ const setup = () => {+ const S = clone(useStore.getState().S)+ S.routines = [+ { id: 'strength', name: 'Strength', emoji: '🏋️', prog: 'off', ex: [{ id: ids[0], sets: 3, reps: 5, weight: 60 }] },+ { id: 'core', name: 'Core', emoji: '🧘', prog: 'off', ex: [{ id: ids[1], sets: 3, reps: 12, weight: 0 }, { id: ids[2], sets: 3, reps: 10, weight: 0 }] },+ { id: 'empty', name: 'Empty', emoji: '📝', ex: [] },+ ]+ S.workouts = []+ S.active = {+ id: 'a', d: '2026-09-06', start: 1, routineIds: ['strength'], name: 'Strength', cur: 0,+ entries: [{ id: ids[0], rid: 'strength', target: {}, sets: [{ w: 60, r: 5, done: true }] }],+ workoutView: 'cards',+ }+ useStore.setState({ S, user: null })+ }++ it('appends the picked routine’s entries with rid, updates routineIds + name, toasts', () => {+ setup()+ addRoutineToSessionSheet()+ const host = renderTop()+ act(() => { rowFor(host, 'Core').click() })++ const a = useStore.getState().S.active+ expect(a.routineIds).toEqual(['strength', 'core'])+ expect(a.name).toBe('Strength + Core')+ expect(a.entries.map(e => e.rid)).toEqual(['strength', 'core', 'core'])+ expect(a.cur).toBe(0) // current unit is left where it was+ expect(useUI.getState().toastMsg).toContain('Core added')+ })++ it('disables a routine already in the session and one with no exercises', () => {+ setup()+ addRoutineToSessionSheet()+ const host = renderTop()+ expect(rowFor(host, 'Strength').className).toContain('disabled')+ expect(rowFor(host, 'Strength').textContent).toContain('already added')+ expect(rowFor(host, 'Empty').className).toContain('disabled')+ expect(rowFor(host, 'Empty').textContent).toContain('no exercises')+ })+})++describe('WorkoutDetail — per-routine grouping', () => {+ const combined = {+ id: 'w', d: '2026-09-06', start: 1, end: 2, name: 'Strength + Core', vol: 500,+ routineIds: ['strength', 'core'], prs: [],+ entries: [+ { id: ids[0], rid: 'strength', target: { reps: 5 }, sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }] },+ { id: ids[1], rid: 'core', target: { reps: 12 }, sets: [{ w: 0, r: 12, done: true }] },+ ],+ }+ const legacy = {+ id: 'w2', d: '2026-09-06', start: 1, end: 2, name: 'Push', vol: 100, routineIds: ['strength'], prs: [],+ entries: [{ id: ids[0], target: { reps: 5 }, sets: [{ w: 100, r: 5, done: true }] }],+ }++ beforeEach(() => {+ const S = clone(useStore.getState().S)+ S.routines = [+ { id: 'strength', name: 'Strength', emoji: '🏋️', ex: [] },+ { id: 'core', name: 'Core', emoji: '🧘', ex: [] },+ ]+ useStore.setState({ S, user: null })+ })++ it('groups a combined workout into per-routine sections with a sets/volume subheader', () => {+ const host = (workoutDetailSheet(combined), renderTop())+ expect(host.textContent).toContain('Strength')+ expect(host.textContent).toContain('Core')+ expect(host.textContent).toMatch(/2 sets/)+ expect(host.textContent).toMatch(/1 sets|1 set/)+ })++ it('renders a legacy single-routine workout flat — no routine subheader', () => {+ const host = (workoutDetailSheet(legacy), renderTop())+ // the only routine name that could appear is the header <h3> (w.name = "Push"); there is+ // no "Strength" subheader row+ expect(host.querySelectorAll('.row.between').length).toBe(0)+ })+})diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 8af095fd6..a04e587ff 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -1539,8 +1539,9 @@ export const dayOverrideSheet = iso => ui().openSheet(close => <DayOverride iso=function DayAssign({ day, close }) {const st = useStore(s => s.S)- // A weekday holds a routine-id list; this single-pick sheet sets the day to exactly one- // routine (or rest). The inline per-day management on the Plan screen is what appends.+ // A weekday holds a routine-id list; this single-pick sheet sets an empty day to exactly one+ // routine (or rest). The inline + Add routine on the Plan screen is what appends to a+ // populated day.const cur = [].concat(st.week[day] || [])const set = v => { update(s => { if (v) s.week[day] = [v]; else delete s.week[day] }); close() }return <>@@ -1556,6 +1557,29 @@ function DayAssign({ day, close }) {}export const dayAssignSheet = day => ui().openSheet(close => <DayAssign day={day} close={close} />)+// + Add routine on a populated weekday: single-pick, appends to the day's list. A routine+// already on that day is disabled; picking one closes the sheet.+function DayAddRoutine({ day, close }) {+ const st = useStore(s => s.S)+ const on = new Set([].concat(st.week[day] || []))+ const add = id => { update(s => { s.week[day] = [...[].concat(s.week[day] || []), id] }); close() }+ return <>+ <h3>{t('Add routine')}</h3>+ <div className="list">+ {st.routines.map(r => {+ const already = on.has(r.id)+ return <div key={r.id} className={'item' + (already ? ' disabled' : '')} aria-disabled={already || undefined}+ {...tappable(already ? null : () => add(r.id))}>+ <span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>+ <div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>+ {already ? <span className="tag">{t('already added')}</span> : <Icon name="chevronRight" className="chev" />}+ </div>+ })}+ </div>+ </>+}+export const dayAddRoutineSheet = day => ui().openSheet(close => <DayAddRoutine day={day} close={close} />)+/* ============================ workout detail ============================ */function WorkoutDetail({ w, close }) {const noteRef = useRef(null)@@ -1587,20 +1611,44 @@ function WorkoutDetail({ w, close }) {if (text) rec.note = text; else delete rec.note})}, [])+ // A combined session's entries carry a `rid`; group them into per-routine sections in merge+ // order. A legacy single-routine workout (one routineIds, or no rid anywhere) renders flat.+ const entryRow = (e, i) => {+ const ex = EXIDX[e.id]+ return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>+ {ex && <Thumb ex={ex} />}+ <div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>+ <div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div>+ {e.note && <div className="small dim" style={{ marginTop: 3 }}>+ {e.notePin && <Icon name="flag" style={{ fontSize: 12, marginRight: 4, verticalAlign: '-1px', color: 'var(--yellow)' }} />}{e.note}+ </div>}</div>+ </div>+ }+ const groups = []+ w.entries.forEach((e, i) => {+ const key = e.rid || '__none'+ let g = groups.find(x => x.key === key)+ if (!g) { g = { key, rid: e.rid || null, items: [] }; groups.push(g) }+ g.items.push([e, i])+ })+ const grouped = groups.length > 1 || (groups[0] && groups[0].rid && (w.routineIds || []).length > 1)return <><h3>{w.name}</h3><div className="muted small" style={{ marginBottom: 12 }}>{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}</div>- {w.entries.map((e, i) => {- const ex = EXIDX[e.id]- return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>- {ex && <Thumb ex={ex} />}- <div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>- <div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div>- {e.note && <div className="small dim" style={{ marginTop: 3 }}>- {e.notePin && <Icon name="flag" style={{ fontSize: 12, marginRight: 4, verticalAlign: '-1px', color: 'var(--yellow)' }} />}{e.note}- </div>}</div>+ {grouped ? groups.map(g => {+ const r = g.rid ? st.routines.find(x => x.id === g.rid) : null+ const setN = g.items.reduce((n, [e]) => n + e.sets.filter(s => s.done && !isWarmupRow(s)).length, 0)+ const vol = workoutVolume({ entries: g.items.map(([e]) => e) })+ return <div key={g.key}>+ <div className="row between" style={{ margin: '2px 0 8px', paddingBottom: 6, borderBottom: '1px solid var(--sep)' }}>+ <div className="row" style={{ gap: 7, fontWeight: 600 }}>+ {r && <Icon name={glyphOf(r.emoji)} />}{r ? r.name : t('Freestyle')}+ </div>+ <div className="small dim">{t('{0} sets', setN)} · {fmtVol(vol, st.unit)}</div>+ </div>+ {g.items.map(([e, i]) => entryRow(e, i))}</div>- })}+ }) : w.entries.map((e, i) => entryRow(e, i))}<div className="small muted" style={{ margin: '4px 0 6px' }}>{t('Session note')}</div><textarea ref={noteRef} className="input" rows={2} maxLength={NOTE_MAX} value={note}placeholder={t('How the session went as a whole.')}@@ -1771,6 +1819,50 @@ function beginBackfill({ iso, time, durationMin, routineId, replaceId }) {useUI.getState().stopRest()nav('/workout')}++/* ============================ add a routine mid-session ============================ */+// The workout header ⋮ → Add routine. Single-pick: a routine already in the session, or one+// with no exercises, is shown disabled and tagged. Picking one appends its entries (each+// stamped with its `rid`), extends `s.active.routineIds`, and re-derives the session name.+// `s.active.cur` is left where it is — the appended block is reached by scrolling / Next.+function AddRoutineToSession({ close }) {+ const st = useStore(s => s.S)+ const active = st.active+ if (!active) return null+ const inSession = new Set([].concat(active.routineIds || []))+ const add = r => {+ const entries = buildSessionEntries(st, r).map(e => ({ ...e, rid: r.id }))+ update(s => {+ if (!s.active) return+ s.active.entries.push(...entries)+ s.active.routineIds = [...[].concat(s.active.routineIds || []), r.id]+ s.active.name = deriveSessionName(s.active.routineIds.map(id => s.routines.find(x => x.id === id)?.name).filter(Boolean))+ })+ close()+ toast(t('{0} added — {1}', r.name, exCount(r.ex.length)))+ }+ return <>+ <h3>{t('Add routine')}</h3>+ <div className="list">+ {st.routines.map(r => {+ const already = inSession.has(r.id)+ const empty = !(r.ex || []).length+ const disabled = already || empty+ return <div key={r.id} className={'item' + (disabled ? ' disabled' : '')} aria-disabled={disabled || undefined}+ {...tappable(disabled ? null : () => add(r))}>+ <span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>+ <div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>+ {already ? <span className="tag">{t('already added')}</span> : empty ? <span className="tag">{t('no exercises')}</span> : <Icon name="chevronRight" className="chev" />}+ </div>+ })}+ </div>+ </>+}+export function addRoutineToSessionSheet() {+ if (!S().active) return+ ui().openSheet(close => <AddRoutineToSession close={close} />)+}+function TopWeight({ entryIdx, close }) {const st = useStore(s => s.S)const A = st.activediff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsxindex 77e69c15e..bd933e386 100644--- a/frontend/src/views/Plan.jsx+++ b/frontend/src/views/Plan.jsx@@ -2,7 +2,7 @@ import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'import { DAYN, weekOrder, weekStartOf, uid, exCount } from '../lib/format.js'import { t } from '../lib/i18n.js'-import { dayAssignSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'+import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'import { Button } from '../components/ui.jsx'import { tappable } from '../lib/use-sheet-keyboard.js'@@ -31,6 +31,12 @@ export default function Plan() {nav('/plan/r/' + r.id)}+ // Pull one routine off a weekday; drop the key when the day empties (never store []).+ const removeFromDay = (d, rid) => update(s => {+ const next = [].concat(s.week[d] || []).filter(id => id !== rid)+ if (next.length) s.week[d] = next; else delete s.week[d]+ })+return <><div className="hdr"><div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>@@ -49,11 +55,27 @@ export default function Plan() {<h4 className="sec">{t('Week schedule')}</h4><div className="list" style={{ display: 'flex', flexDirection: 'column' }}>{weekOrder(weekStartOf(S)).map(d => {- const r = S.routines.find(x => x.id === S.week[d])- return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>+ const dayRoutines = [].concat(S.week[d] || []).map(id => S.routines.find(x => x.id === id)).filter(Boolean)+ // An empty day stays one tappable row → pick its first routine (today's behaviour).+ if (!dayRoutines.length) return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}><div className="grow"><div className="tt">{t(DAYN[d])}</div></div>- {r ? <span className="tag acc"><Icon name={glyphOf(r.emoji)} />{r.name}</span> : <span className="tag">{t('Rest')}</span>}+ <span className="tag">{t('Rest')}</span><Icon name="chevronRight" className="chev" /></div>+ // A populated day: always-visible routine sub-rows + inline ✕, then + Add routine.+ return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}>+ <div className="row between" style={{ marginBottom: 6 }}>+ <div className="tt">{t(DAYN[d])}</div>+ <div className="small dim">{t('{0} routines', dayRoutines.length)}</div>+ </div>+ {dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}>+ <span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span>+ <div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>+ <button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button>+ </div>)}+ <button className="btn ghost sm" style={{ marginTop: 4, marginLeft: 8 }} onClick={() => dayAddRoutineSheet(d)}>+ <Icon name="plus" /> {t('Add routine')}+ </button>+ </div>})}</div></div><div>diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex d865a8829..fae0dd851 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -12,7 +12,7 @@ import { t, exerciseNameFor } from '../lib/i18n.js'import { api } from '../lib/api.js'import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'import Media from '../components/Media.jsx'-import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet } from '../sheets.jsx'+import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'import { effortColor } from '../lib/effort.js'import Icon from '../components/Icon.jsx'import { Button, Check, NumberField } from '../components/ui.jsx'@@ -556,14 +556,23 @@ function ActiveWorkout() {// (Settings → During a workout → Workout view). It writes s.active.workoutView, which the// render above prefers over S.workoutView.const setWorkoutView = v => update(s => { if (s.active) s.active.workoutView = v })- const openViewMenu = () => menuSheet({- title: t('Workout view'),+ const LAYOUT_LABEL = { cards: t('Cards'), list: t('List'), compact: t('Compact') }+ const openLayoutMenu = () => menuSheet({+ title: t('Layout'),items: [{ icon: 'clipboard', label: t('Cards'), on: workoutView === 'cards', onClick: () => setWorkoutView('cards') },{ icon: 'list', label: t('List'), on: workoutView === 'list', onClick: () => setWorkoutView('list') },{ icon: 'minimize', label: t('Compact'), on: workoutView === 'compact', onClick: () => setWorkoutView('compact') },],})+ // The header ⋮: bring another routine into the session, then the layout switch nested a+ // level down (it used to be the whole menu).+ const openViewMenu = () => menuSheet({+ items: [+ { icon: 'plus', label: t('Add routine'), sub: t('Bring another routine into this session'), onClick: addRoutineToSessionSheet },+ { icon: 'list', label: t('Layout'), sub: LAYOUT_LABEL[workoutView] || LAYOUT_LABEL.cards, onClick: openLayoutMenu },+ ],+ })const onSwipePointerDown = event => {if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) returnif (event.target.closest?.(SWIPE_IGNORED_TARGETS)) returndiff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex fbd3bc6c5..9c218d716 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -78,6 +78,7 @@ vi.mock('../sheets.jsx', () => ({sessionNoteSheet: vi.fn(),effortPickerSheet: mocks.effortPickerSheet,exerciseHistorySheet: mocks.exerciseHistorySheet,+ addRoutineToSessionSheet: vi.fn(),}))vi.mock('../components/Media.jsx', () => ({ default: () => null }))// api.js reads navigator.userAgent at module scope. This file installs its own DOM inside the@@ -1157,21 +1158,30 @@ describe('workout view header menu', () => {}const item = (menu, label) => menu.items.filter(Boolean).find(it => it.label === label)- it('offers the three layouts and marks the running session current', async () => {- await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list' } })+ // The header ⋮ now leads with "Add routine"; the layouts moved to a nested "Layout" sheet.+ const openLayout = async menu => {+ await act(async () => { item(menu, 'Layout').onClick() })+ return mocks.menuSheet.mock.calls.at(-1)[0]+ }++ it('leads with Add routine, then a Layout sheet with the three layouts marked current', async () => {+ await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list', routineIds: [] } })const menu = await openMenu()- expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])- expect(item(menu, 'List').on).toBe(true)- expect(item(menu, 'Cards').on).toBe(false)- expect(item(menu, 'Compact').on).toBe(false)+ expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Add routine', 'Layout'])+ expect(item(menu, 'Layout').sub).toBe('List')++ const layout = await openLayout(menu)+ expect(layout.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])+ expect(item(layout, 'List').on).toBe(true)+ expect(item(layout, 'Cards').on).toBe(false)})- it('writes the pick onto s.active without touching the global default', async () => {- await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards' } })+ it('writes the layout pick onto s.active without touching the global default', async () => {+ await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards', routineIds: [] } })- const menu = await openMenu()- await act(async () => { item(menu, 'Compact').onClick() })+ const layout = await openLayout(await openMenu())+ await act(async () => { item(layout, 'Compact').onClick() })expect(mocks.S.active.workoutView).toBe('compact')expect(mocks.S.workoutView).toBe('cards')diff --git a/frontend/src/views/week-start.test.jsx b/frontend/src/views/week-start.test.jsxindex 84014e730..36a510fad 100644--- a/frontend/src/views/week-start.test.jsx+++ b/frontend/src/views/week-start.test.jsx@@ -46,7 +46,7 @@ vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))vi.mock('../sheets.jsx', () => ({starterPlanSheet: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),- dayAssignSheet: vi.fn(), planToolsSheet: vi.fn(),+ dayAssignSheet: vi.fn(), dayAddRoutineSheet: vi.fn(), planToolsSheet: vi.fn(),}))globalThis.__APP_VERSION__ ??= 'test'@@ -118,3 +118,43 @@ describe('Plan — the week schedule follows the setting', () => {expect(rows[1].textContent).not.toContain('Push')})})++describe('Plan — inline per-day routine management (combine routines)', () => {+ const mount = () => act(() => root.render(<Plan />))+ const dayContainer = name => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)++ beforeEach(() => {+ mocks.S.routines = [+ { id: 'r1', name: 'Push', emoji: null, ex: [{ id: 'a' }, { id: 'b' }] },+ { id: 'r2', name: 'Core', emoji: null, ex: [{ id: 'c' }] },+ ]+ })++ it('renders a sub-row per routine on a populated day, with the count hint', () => {+ mocks.S.week = { 1: ['r1', 'r2'] }+ mount()+ const mon = dayContainer('Monday')+ expect(mon.textContent).toContain('Push')+ expect(mon.textContent).toContain('Core')+ expect(mon.textContent).toContain('2 routines')+ })++ it('✕ removes a routine, and drops the day key on the last removal', () => {+ mocks.S.week = { 1: ['r1', 'r2'] }+ mount()+ const removeButtons = () => [...dayContainer('Monday').querySelectorAll('button[aria-label="Remove"]')]+ act(() => { removeButtons()[1].dispatchEvent(new Event('click', { bubbles: true })) })+ expect(mocks.S.week[1]).toEqual(['r1'])+ mount()+ act(() => { removeButtons()[0].dispatchEvent(new Event('click', { bubbles: true })) })+ expect(mocks.S.week).not.toHaveProperty('1')+ })++ it('an empty day stays one tappable row', () => {+ mocks.S.week = {}+ mount()+ const tue = dayContainer('Tuesday')+ expect(tue.textContent).toContain('Rest')+ expect(tue.querySelectorAll('button[aria-label="Remove"]').length).toBe(0)+ })+})