diff --git a/frontend/src/components/MuscleExplorer.jsx b/frontend/src/components/MuscleExplorer.jsx index d48eede..43b6531 100644 --- a/frontend/src/components/MuscleExplorer.jsx +++ b/frontend/src/components/MuscleExplorer.jsx @@ -84,7 +84,7 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) { const primary = musclesOf(e)[selected] === 1 return
choose(e))}> -
{isFav(S, e.id) && }{exerciseNameFor(e)}
{t(primary ? 'Primary target' : 'Also trains')} · {t(e.tg || e.bp)} · {t(e.eq)}
+
{isFav(S, e.id) && }{exerciseNameFor(e)}
{t(primary ? 'Primary target' : 'Also trains')} · {t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}
{onPick ? : <> {best > 0 && {fmtNum(best)}} diff --git a/frontend/src/sheets.custom-target.test.jsx b/frontend/src/sheets.custom-target.test.jsx new file mode 100644 index 0000000..2b87ee7 --- /dev/null +++ b/frontend/src/sheets.custom-target.test.jsx @@ -0,0 +1,113 @@ +// @vitest-environment happy-dom +// QA C10. Since the muscles of a custom exercise are stored in the map's order (83b2a14), the +// one-word target `tg` was silently taken from the sorted list: a hip thrust with Traps as an +// extra primary became a "Traps" exercise in the library, the picker and the Muscles view, and +// tap order no longer let the user correct it. The target is the primary picked first; an edit +// keeps the old target while it is still a primary. +import React, { act } from 'react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { createRoot } from 'react-dom/client' +import { EXIDX, registerCustom } from './lib/exercises.js' +import { DEF, useStore } from './store/useStore.js' +import { useUI } from './store/useUI.js' +import { _setLangState } from './lib/i18n-core.js' +import { bindUI } from './components/ui.jsx' +import { customExSheet } from './sheets.jsx' + +bindUI(useUI) // the multi-select rows open their sheet through the shared controls + +const mounted = [] +const S = () => useStore.getState().S + +// Renders whatever sheet is on top and returns its host element. +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 +} +function type(el, value) { + Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value) + el.dispatchEvent(new Event('input', { bubbles: true })) +} +const byText = (host, sel, text) => [...host.querySelectorAll(sel)].find(e => e.textContent.trim() === text) +const click = (host, sel, text) => { + const el = byText(host, sel, text) + if (!el) throw new Error(`nothing with text "${text}"`) + act(() => el.click()) +} +// The form's multi-select rows open a nested sheet; tap the given labels there, in order, then Done. +function pickMuscles(form, rowTitle, labels) { + const row = [...form.querySelectorAll('.lrow')].find(e => e.textContent.includes(rowTitle)) + act(() => row.click()) + const sub = renderTop() + for (const l of labels) click(sub, 'button', l) + click(sub, 'button', 'Done') +} +const custom = (over = {}) => ({ + id: 'cqa1', n: 'QA Custom Thrust', bp: 'upper legs', eq: 'barbell', custom: true, desc: '', + tg: 'gluteal', sm: ['forearm', 'hip-flexors'], primaries: ['gluteal'], secondaries: ['forearm', 'hip-flexors'], + muscleGroups: ['gluteal', 'forearm', 'hip-flexors'], ...over, +}) +function seed(ex) { + useStore.setState(s => ({ S: { ...s.S, customEx: [ex] } })) + registerCustom([ex]) +} + +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + useUI.setState({ sheets: [], toastMsg: '' }) + useStore.setState({ S: structuredClone(DEF), user: null }) + registerCustom([]) + _setLangState('en', null, null, null) + document.body.innerHTML = '' +}) + +afterEach(() => { + act(() => { mounted.splice(0).forEach(root => root.unmount()) }) + _setLangState('en', null, null, null) + registerCustom([]) +}) + +describe('custom exercise target (QA C10)', () => { + it('is the primary tapped first, while the stored list keeps the map order', () => { + customExSheet(null) + const form = renderTop() + act(() => type(form.querySelector('input.input'), 'QA Hip Thrust Pull')) + click(form, '.chip', 'upper legs') + click(form, '.chip', 'barbell') + pickMuscles(form, 'Primary muscle groups', ['Hamstrings', 'Glutes', 'Traps']) + click(form, 'button', 'Create exercise') + const c = S().customEx.find(x => x.n === 'QA Hip Thrust Pull') + expect(c.primaries).toEqual(['trapezius', 'gluteal', 'hamstring']) + expect(c.tg).toBe('hamstring') + expect(c.muscleGroups).toEqual(['trapezius', 'gluteal', 'hamstring']) + }) + + it('survives an edit that adds a primary higher up the body', () => { + const ex = custom({ tg: 'hamstring', primaries: ['gluteal', 'hamstring'], secondaries: [], sm: [], muscleGroups: ['gluteal', 'hamstring'] }) + seed(ex) + customExSheet(EXIDX[ex.id]) + const form = renderTop() + pickMuscles(form, 'Primary muscle groups', ['Traps']) + click(form, 'button', 'Save') + const c = S().customEx[0] + expect(c.primaries).toEqual(['trapezius', 'gluteal', 'hamstring']) + expect(c.tg).toBe('hamstring') + }) + + it('moves to another primary only when the old target is dropped', () => { + const ex = custom({ tg: 'hamstring', primaries: ['gluteal', 'hamstring'], secondaries: [], sm: [], muscleGroups: ['gluteal', 'hamstring'] }) + seed(ex) + customExSheet(EXIDX[ex.id]) + const form = renderTop() + pickMuscles(form, 'Primary muscle groups', ['Hamstrings']) // untick it + click(form, 'button', 'Save') + const c = S().customEx[0] + expect(c.primaries).toEqual(['gluteal']) + expect(c.tg).toBe('gluteal') + }) +}) diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 451e910..40acaf9 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -795,13 +795,17 @@ function CustomExForm({ existing, prefill, onDone, close }) { const prim = bp === 'cardio' ? ['cardiovascular system'] : inMuscleOrder(primaries) const sm = inMuscleOrder(secondaries.filter(m => !prim.includes(m))) const groups = [...prim, ...sm] + // The one-word target (the library row, the picker, the Muscles view) is not the sorted list's + // head — a hip thrust with Traps as an extra primary is not a Traps exercise. It is the primary + // tapped first, and an edit keeps the exercise's target as long as that muscle is still a primary. + const tg = (existing && prim.includes(existing.tg)) ? existing.tg : (primaries.find(m => prim.includes(m)) || prim[0] || '') let id = existing && existing.id if (existing) update(s => { const c = (s.customEx || []).find(x => x.id === id); if (c) { - c.n = name; c.bp = bp; c.desc = d; c.tg = prim[0] || ''; c.sm = sm; c.muscleGroups = groups; c.primaries = prim; c.secondaries = sm; c.eq = eq + c.n = name; c.bp = bp; c.desc = d; c.tg = tg; c.sm = sm; c.muscleGroups = groups; c.primaries = prim; c.secondaries = sm; c.eq = eq } }) else { id = 'c' + uid() - update(s => { (s.customEx = s.customEx || []).push({ id, n: name, bp, desc: d, tg: prim[0] || '', sm, muscleGroups: groups, primaries: prim, secondaries: sm, eq, custom: true }) }) + update(s => { (s.customEx = s.customEx || []).push({ id, n: name, bp, desc: d, tg, sm, muscleGroups: groups, primaries: prim, secondaries: sm, eq, custom: true }) }) } close() toast(existing ? t('Saved') : t('“{0}” created', name)) @@ -942,7 +946,7 @@ function ExercisePicker({ onPick, close }) {
{t('Create your own exercise')}
{t('name + body part, no animation')}
} {f.slice(0, shown).map(e =>
onPick(e))}> -
{isFav(st, e.id) && }{exerciseNameFor(e)}
{t(e.tg || e.bp)} · {t(e.eq)}
+
{isFav(st, e.id) && }{exerciseNameFor(e)}
{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}
{/* Accent tag = already in a routine/log ("Chosen"); the yellow star by the name = favourite. */} {usage[e.id] && } {/* A "+" glyph reads as "add this now" — it used to just open the same detail sheet as @@ -1221,12 +1225,14 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { {/* The same tags the exercise detail sheet shows, secondaries included: choosing what goes into a plan is exactly when "what else does this hit" matters, and until now that was - only visible from the Exercises tab, after the fact. */} + only visible from the Exercises tab, after the fact. Custom exercises and the newer + metadata name muscles by the map's ids ("forearm", "gluteal"), which only MUSCLE_NAME + turns into a translatable label. */}
{cardio && {t('Cardio')}} - {t(ex.tg || ex.bp)}{t(ex.eq)} + {t(MUSCLE_NAME[ex.tg] || ex.tg || ex.bp)}{t(ex.eq)} {!cardio && (ex.secondaries?.length ? ex.secondaries : smOf(ex)).slice(0, 3) - .map((s, i) => {t(s)})} + .map((s, i) => {t(MUSCLE_NAME[s] || s)})}
{ex.desc &&
{ex.desc}
} {!cardio &&
diff --git a/frontend/src/sheets.muscle-names.test.jsx b/frontend/src/sheets.muscle-names.test.jsx new file mode 100644 index 0000000..10a5537 --- /dev/null +++ b/frontend/src/sheets.muscle-names.test.jsx @@ -0,0 +1,121 @@ +// @vitest-environment happy-dom +// QA C9. Custom exercises and the newer exercise metadata name muscles by the map's ids. The +// picker row, the routine config sheet and the Muscles rows printed those ids ("gluteal", +// "forearm", "hip-flexors") where the detail sheet already said Glutes / Forearms / Hip flexors — +// and in German "forearm" stayed English, because only the display names have translations. +import React, { act } from 'react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { createRoot } from 'react-dom/client' +import { EXIDX, registerCustom } from './lib/exercises.js' +import { DEF, useStore } from './store/useStore.js' +import { useUI } from './store/useUI.js' +import { _setLangState } from './lib/i18n-core.js' +import de from './locales/de.js' +import { exercisePicker, exConfigSheet } from './sheets.jsx' +import MuscleExplorer from './components/MuscleExplorer.jsx' + +const mounted = [] +const S = () => useStore.getState().S + +// Renders whatever sheet is on top and returns its host element. +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 +} +function render(node) { + const host = document.createElement('div') + document.body.appendChild(host) + const root = createRoot(host) + mounted.push(root) + act(() => root.render(node)) + return host +} +function type(el, value) { + Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value) + el.dispatchEvent(new Event('input', { bubbles: true })) +} +const rowFor = (host, name) => [...host.querySelectorAll('.item')].find(e => e.textContent.includes(name)) +const custom = (over = {}) => ({ + id: 'cqa1', n: 'QA Custom Thrust', bp: 'upper legs', eq: 'barbell', custom: true, desc: '', + tg: 'gluteal', sm: ['forearm', 'hip-flexors'], primaries: ['gluteal'], secondaries: ['forearm', 'hip-flexors'], + muscleGroups: ['gluteal', 'forearm', 'hip-flexors'], ...over, +}) +function seed(ex) { + useStore.setState(s => ({ S: { ...s.S, customEx: [ex] } })) + registerCustom([ex]) +} + +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + useUI.setState({ sheets: [], toastMsg: '' }) + useStore.setState({ S: structuredClone(DEF), user: null }) + registerCustom([]) + _setLangState('en', null, null, null) + document.body.innerHTML = '' +}) + +afterEach(() => { + act(() => { mounted.splice(0).forEach(root => root.unmount()) }) + _setLangState('en', null, null, null) + registerCustom([]) +}) + +describe('muscle names in the rows and tags (QA C9)', () => { + it('picker row shows the display name, not the map id', () => { + seed(custom()) + exercisePicker(vi.fn()) + const host = renderTop() + act(() => type(host.querySelector('input.input'), 'QA Custom')) + expect(rowFor(host, 'QA Custom Thrust').querySelector('.ss').textContent).toBe('Glutes · barbell') + }) + + it('config sheet tags read like the detail sheet, for a custom exercise and for power clean', () => { + seed(custom()) + exConfigSheet(EXIDX.cqa1, null, vi.fn()) + const tags = h => [...h.querySelectorAll('.tag')].map(e => e.textContent.trim()) + expect(tags(renderTop())).toEqual(['Glutes', 'barbell', 'Forearms', 'Hip flexors']) + // #207 Olympic lifts list their secondaries as map ids ('forearm', 'deltoids'). + exConfigSheet(EXIDX['0648'], null, vi.fn()) + expect(tags(renderTop())).toEqual(['hamstrings', 'barbell', 'Calves', 'Forearms', 'Shoulders']) + }) + + it('translates them in German too — "forearm" was staying English', () => { + _setLangState('de', de, null, null) + seed(custom()) + exConfigSheet(EXIDX['0648'], null, vi.fn()) + const tags = [...renderTop().querySelectorAll('.tag')].map(e => e.textContent.trim()) + expect(tags).toEqual(['Beinbeuger', 'Langhantel', 'Waden', 'Unterarme', 'Schultern']) + exercisePicker(vi.fn()) + const host = renderTop() + act(() => type(host.querySelector('input.input'), 'QA Custom')) + expect(rowFor(host, 'QA Custom Thrust').querySelector('.ss').textContent).toBe('Gesäß · Langhantel') + }) + + // The dataset's cardio target "cardiovascular system" is both a map id and a translated key + // of its own. Routing it through MUSCLE_NAME must not cost it its translation: the 29 + // built-in cardio exercises read "Herz-Kreislauf" in German, never "Cardiovascular system". + it('keeps the cardio target translated (burpee, de)', () => { + _setLangState('de', de, null, null) + exercisePicker(vi.fn()) + const host = renderTop() + act(() => type(host.querySelector('input.input'), 'burpee')) + expect(rowFor(host, 'burpee').querySelector('.ss').textContent).toBe('Herz-Kreislauf · Körpergewicht') + exConfigSheet(EXIDX['1160'], null, vi.fn()) + const tags = [...renderTop().querySelectorAll('.tag')].map(e => e.textContent.trim()) + expect(tags).toEqual(['Cardio', 'Herz-Kreislauf', 'Körpergewicht']) + }) + + it('Muscles explorer row names the target the same way', () => { + seed(custom()) + const host = render() + const chip = [...host.querySelectorAll('.chip[aria-pressed]')].find(e => e.textContent.startsWith('Glutes')) + act(() => chip.click()) + act(() => type(host.querySelector('.search input'), 'QA Custom')) + expect(rowFor(host, 'QA Custom Thrust').querySelector('.ss').textContent).toBe('Primary target · Glutes · barbell') + }) +}) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index dee908e..08273a1 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -21,6 +21,7 @@ import { progressionGuidance } from '../lib/progression-copy.js' import { glyphOf } from '../lib/glyphs.js' import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt } from '../lib/workout-model.js' import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js' +import { MUSCLE_NAME } from '../lib/muscles.js' const SWIPE_MIN_DISTANCE = 48 const SWIPE_AXIS_RATIO = 1.25 @@ -378,7 +379,7 @@ function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onFie "{n} per side" chip — which halved the combined total for display — is gone: the split is no longer derived, it is what you enter. The tag only flags that this is per-side. */} {!cardio && !timed && isPerSide(cfg) && {t('Per side')}} - {(ex.tg || ex.bp) && {t(ex.tg || ex.bp)}} + {(ex.tg || ex.bp) && {t(MUSCLE_NAME[ex.tg] || ex.tg || ex.bp)}} {ex.eq && {t(ex.eq)}} {best > 0 && {t('Best:')} {fmtNum(best)} {S.unit}}
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index d7f06ab..e3b669d 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -1408,3 +1408,32 @@ describe('per-side effort completion', () => { expect(mocks.startRest).toHaveBeenCalledTimes(calls) }) }) + +// QA C9: custom exercises store their target as a muscle-map id ("gluteal"); the tag under the +// exercise name has to show the same label the detail sheet does (Glutes), not the raw id. +describe('Workout exercise tags', () => { + it('names a custom exercise\'s target muscle by its display name', async () => { + const { registerCustom } = await import('../lib/exercises.js') + registerCustom([{ id: 'cqa1', n: 'QA Custom Thrust', bp: 'upper legs', eq: 'barbell', custom: true, tg: 'gluteal', sm: [], primaries: ['gluteal'], secondaries: [], muscleGroups: ['gluteal'] }]) + try { + await mount([exercise('cqa1', [false])]) + const tags = [...container.querySelectorAll('.tag')].map(tag => tag.textContent.trim()) + expect(tags).toContain('Glutes') + expect(tags).not.toContain('gluteal') + } finally { registerCustom([]) } + }) + + // The cardio target "cardiovascular system" is a translated key of its own; mapping it through + // MUSCLE_NAME must not turn "Herz-Kreislauf" back into English for every built-in cardio exercise. + it('keeps the cardio target translated (burpee, de)', async () => { + const { _setLangState } = await import('../lib/i18n-core.js') + const { default: de } = await import('../locales/de.js') + _setLangState('de', de, null, null) + try { + await mount([exercise('1160', [false])]) + const tags = [...container.querySelectorAll('.tag')].map(tag => tag.textContent.trim()) + expect(tags).toContain('Herz-Kreislauf') + expect(tags).not.toContain('Cardiovascular system') + } finally { _setLangState('en', null, null, null) } + }) +})