Hide exercise animations during a workout: gifSize gains 'off' — Settings segment Full/Small/Hidden, workout media collapses entirely when hidden, strings in all 14 languages; pt-BR guard re-fingerprinted

This commit is contained in:
Duarte Santos committed 2026-08-31 11:02:57 +02:00
1 parent 188979151b
commit 887a036832
18 files changed
+231 -3

No files matched your search

+4 -1
View File
@@ -8,12 +8,15 @@ import Icon from './Icon.jsx'
// Custom exercises have no media — the animation stays blank by design (issue #11).
// `minimizable` (workout view) adds a persistent minimize/expand control so the animation stops
// eating the screen; the chosen size is saved to settings and carries across exercises and
// future workouts (issue #12).
// future workouts (issue #12). Settings can also turn workout media off entirely
// (gifSize 'off') — then nothing renders here and the exercise card closes up, exactly like
// a custom exercise without media. Any other/legacy value behaves as 'full'.
export default function Media({ ex, id, compact, minimizable }) {
const [playing, setPlaying] = useState(true)
const gifSize = useStore(s => s.S.gifSize)
const update = useStore(s => s.update)
if (!ex.gif) return null
if (minimizable && gifSize === 'off') return null
const mini = minimizable && gifSize === 'mini'
const toggleSize = e => { e.stopPropagation(); update(s => { s.gifSize = mini ? 'full' : 'mini' }) }
return (
+74
View File
@@ -0,0 +1,74 @@
// @vitest-environment happy-dom
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import Media from './Media.jsx'
globalThis.IS_REACT_ACT_ENVIRONMENT = true
const mocks = vi.hoisted(() => {
const state = { S: { gifSize: 'full' } }
state.snapshot = () => ({
S: state.S,
update: mut => {
const next = structuredClone(state.S)
mut(next)
state.S = next
},
})
return state
})
vi.mock('../store/useStore.js', () => {
const useStore = selector => selector(mocks.snapshot())
useStore.getState = mocks.snapshot
return { useStore }
})
const EX = { id: 'bench', n: 'bench press', gif: 'bench.gif', img: 'bench.jpg' }
let host, root
beforeEach(() => {
mocks.S = { gifSize: 'full' }
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
})
afterEach(() => {
act(() => root.unmount())
host.remove()
})
const mount = props => act(() => root.render(<Media ex={EX} {...props} />))
describe('Media gifSize', () => {
it('renders the full animation by default and toggles to mini in the workout', () => {
mount({ minimizable: true })
expect(host.querySelector('.exmedia img')).toBeTruthy()
expect(host.querySelector('.exmedia.mini')).toBeFalsy()
act(() => { host.querySelector('.giftoggle').click() })
expect(mocks.S.gifSize).toBe('mini')
mount({ minimizable: true })
expect(host.querySelector('.exmedia.mini')).toBeTruthy()
})
it("renders nothing at all in the workout when gifSize is 'off'", () => {
mocks.S = { gifSize: 'off' }
mount({ minimizable: true })
expect(host.querySelector('.exmedia')).toBeFalsy()
expect(host.querySelector('img')).toBeFalsy()
expect(host.innerHTML).toBe('')
})
it("'off' only applies to the workout — the detail sheet (not minimizable) still shows media", () => {
mocks.S = { gifSize: 'off' }
mount({})
expect(host.querySelector('.exmedia img')).toBeTruthy()
})
it('treats a legacy/unknown value as full', () => {
mocks.S = { gifSize: 'huge' }
mount({ minimizable: true })
expect(host.querySelector('.exmedia img')).toBeTruthy()
expect(host.querySelector('.exmedia.mini')).toBeFalsy()
})
})
+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(338)
expect(inherited).toHaveLength(454)
expect(inherited).toHaveLength(458)
// 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('549332a72036a9fda6e3c3b129ea57ae9863a6e87099135bc3ae638d2bd31a58')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('67edc754880ed2a392eee8839549a36bd8bf55b16f889b655b40fc6c493fc6dd')
})
test('does not leak European Portuguese UI terms', () => {
+4
View File
@@ -413,6 +413,10 @@ export default {
'Remove from routine': 'Aus Routine entfernen',
'Minimize': 'Verkleinern',
'Expand': 'Vergrössern',
'Exercise animations': 'Übungs-Animationen',
'Full': 'Gross',
'Small': 'Klein',
'Hidden': 'Versteckt',
'Invite code': 'Einladungscode',
'This app is invite-only — enter the code you were given.': 'Diese App ist nur mit Einladung — gib den Code ein, den du erhalten hast.',
'An invite code is required': 'Ein Einladungscode ist erforderlich',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Quitar de la rutina',
'Minimize': 'Minimizar',
'Expand': 'Ampliar',
'Exercise animations': 'Animaciones de los ejercicios',
'Full': 'Completa',
'Small': 'Pequeña',
'Hidden': 'Oculta',
'Invite code': 'Código de invitación',
'This app is invite-only — enter the code you were given.': 'Esta app es solo por invitación: introduce el código que te dieron.',
'An invite code is required': 'Se requiere un código de invitación',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Retirer de la routine',
'Minimize': 'Réduire',
'Expand': 'Agrandir',
'Exercise animations': 'Animations des exercices',
'Full': 'Grande',
'Small': 'Petite',
'Hidden': 'Masquée',
'Invite code': 'Code d’invitation',
'This app is invite-only — enter the code you were given.': 'Cette appli est sur invitation — saisissez le code qu’on vous a donné.',
'An invite code is required': 'Un code d’invitation est requis',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'रूटीन से हटाएं',
'Minimize': 'छोटा करें',
'Expand': 'बड़ा करें',
'Exercise animations': 'व्यायाम एनिमेशन',
'Full': 'पूर्ण',
'Small': 'छोटा',
'Hidden': 'छिपा',
'Invite code': 'इनवाइट कोड',
'This app is invite-only — enter the code you were given.': 'यह ऐप केवल इनवाइट से है — आपको दिया गया कोड डालें।',
'An invite code is required': 'एक इनवाइट कोड आवश्यक है',
+4
View File
@@ -401,6 +401,10 @@ export default {
'Remove from routine': 'Eltávolítás a rutinból',
'Minimize': 'Kicsinyítés',
'Expand': 'Kibontás',
'Exercise animations': 'Gyakorlat-animációk',
'Full': 'Teljes',
'Small': 'Kicsi',
'Hidden': 'Rejtett',
'Invite code': 'Meghívókód',
'This app is invite-only — enter the code you were given.': 'Ez az app csak meghívóval elérhető — add meg a kapott kódot.',
'An invite code is required': 'Meghívókód szükséges',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Rimuovi dalla routine',
'Minimize': 'Riduci',
'Expand': 'Ingrandisci',
'Exercise animations': 'Animazioni degli esercizi',
'Full': 'Grande',
'Small': 'Piccola',
'Hidden': 'Nascosta',
'Invite code': 'Codice di invito',
'This app is invite-only — enter the code you were given.': 'Questa app è solo su invito: inserisci il codice che hai ricevuto.',
'An invite code is required': 'È richiesto un codice di invito',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': '루틴에서 제거',
'Minimize': '축소',
'Expand': '확대',
'Exercise animations': '운동 애니메이션',
'Full': '전체',
'Small': '작게',
'Hidden': '숨김',
'Invite code': '초대 코드',
'This app is invite-only — enter the code you were given.': '이 앱은 초대 전용입니다 — 받은 코드를 입력하세요.',
'An invite code is required': '초대 코드가 필요합니다',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Usuń z planu',
'Minimize': 'Zmniejsz',
'Expand': 'Powiększ',
'Exercise animations': 'Animacje ćwiczeń',
'Full': 'Pełna',
'Small': 'Mała',
'Hidden': 'Ukryta',
'Invite code': 'Kod zaproszenia',
'This app is invite-only — enter the code you were given.': 'Ta aplikacja jest tylko na zaproszenie — wpisz otrzymany kod.',
'An invite code is required': 'Wymagany jest kod zaproszenia',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Remover da rotina',
'Minimize': 'Minimizar',
'Expand': 'Ampliar',
'Exercise animations': 'Animações dos exercícios',
'Full': 'Grande',
'Small': 'Pequena',
'Hidden': 'Oculta',
'Invite code': 'Código de convite',
'This app is invite-only — enter the code you were given.': 'Esta app é só por convite — introduz o código que recebeste.',
'An invite code is required': 'É necessário um código de convite',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Убрать из программы',
'Minimize': 'Свернуть',
'Expand': 'Развернуть',
'Exercise animations': 'Анимации упражнений',
'Full': 'Полная',
'Small': 'Малая',
'Hidden': 'Скрыта',
'Invite code': 'Код приглашения',
'This app is invite-only — enter the code you were given.': 'Приложение только по приглашению — введите выданный вам код.',
'An invite code is required': 'Требуется код приглашения',
+4
View File
@@ -401,6 +401,10 @@ export default {
'Remove from routine': 'ลบออกจากรูทีน',
'Minimize': 'ย่อ',
'Expand': 'ขยาย',
'Exercise animations': 'ภาพเคลื่อนไหวท่าออกกำลังกาย',
'Full': 'เต็ม',
'Small': 'เล็ก',
'Hidden': 'ซ่อน',
'Invite code': 'รหัสเชิญ',
'This app is invite-only — enter the code you were given.': 'แอปนี้ต้องมีรหัสเชิญ — กรอกรหัสที่ได้รับมา',
'An invite code is required': 'ต้องมีรหัสเชิญ',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': 'Rutinden çıkar',
'Minimize': 'Küçült',
'Expand': 'Büyüt',
'Exercise animations': 'Egzersiz animasyonları',
'Full': 'Tam',
'Small': 'Küçük',
'Hidden': 'Gizli',
'Invite code': 'Davet kodu',
'This app is invite-only — enter the code you were given.': 'Bu uygulama yalnızca davetle — sana verilen kodu gir.',
'An invite code is required': 'Bir davet kodu gerekli',
+4
View File
@@ -395,6 +395,10 @@ export default {
'Remove from routine': '从计划中移除',
'Minimize': '缩小',
'Expand': '放大',
'Exercise animations': '动作动画',
'Full': '完整',
'Small': '小',
'Hidden': '隐藏',
'Invite code': '邀请码',
'This app is invite-only — enter the code you were given.': '此应用仅限邀请——请输入你收到的邀请码。',
'An invite code is required': '需要邀请码',
@@ -0,0 +1,90 @@
// @vitest-environment happy-dom
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import Settings from './Settings.jsx'
globalThis.IS_REACT_ACT_ENVIRONMENT = true
const mocks = vi.hoisted(() => {
const state = { S: null }
state.snapshot = () => ({
S: state.S,
user: null,
update: mut => {
const next = structuredClone(state.S)
mut(next)
state.S = next
},
replaceState: vi.fn(), setUser: vi.fn(), pullState: vi.fn(), pushState: vi.fn(),
signOut: vi.fn(), signOutAll: vi.fn(), resetDemo: vi.fn(), disconnectServer: vi.fn(),
})
return state
})
vi.mock('../store/useStore.js', () => {
const useStore = selector => selector ? selector(mocks.snapshot()) : mocks.snapshot()
useStore.getState = mocks.snapshot
return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false }
})
vi.mock('../store/useUI.js', () => {
const snap = () => ({ toast: vi.fn(), openSheet: vi.fn() })
const useUI = selector => selector ? selector(snap()) : snap()
useUI.getState = snap
return { useUI }
})
vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
vi.mock('../lib/api.js', () => ({
api: vi.fn(), webauthnOK: () => false, passkeyLogin: vi.fn(), passkeyRegister: vi.fn(), IS_ANDROID: false,
}))
vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
vi.mock('../lib/mobile.js', () => ({ MOBILE: false, shareExport: vi.fn(), syncReminder: vi.fn() }))
vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
vi.mock('../sheets.jsx', () => ({
loadStarterPlan: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
}))
// The Settings view reads the build-time version constant at render time.
globalThis.__APP_VERSION__ ??= 'test'
let host, root
beforeEach(() => {
mocks.S = {
unit: 'kg', restSec: 90, restPauseSec: 15, sound: false, effort: 'none',
gifSize: 'full', workouts: [], routines: [], exWeights: {},
}
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
})
afterEach(() => {
act(() => root.unmount())
host.remove()
})
const mount = () => act(() => root.render(<Settings />))
const segButton = label => [...host.querySelectorAll('.seg button')].find(b => b.textContent === label)
describe('Settings — exercise animations', () => {
it('offers Full / Small / Hidden and writes gifSize to the store', () => {
mount()
expect(segButton('Full')).toBeTruthy()
expect(segButton('Small')).toBeTruthy()
expect(segButton('Hidden')).toBeTruthy()
expect(segButton('Full').getAttribute('aria-pressed')).toBe('true')
act(() => { segButton('Hidden').click() })
expect(mocks.S.gifSize).toBe('off')
mount()
expect(segButton('Hidden').getAttribute('aria-pressed')).toBe('true')
act(() => { segButton('Small').click() })
expect(mocks.S.gifSize).toBe('mini')
})
it('shows a legacy/absent value as Full', () => {
delete mocks.S.gifSize
mount()
expect(segButton('Full').getAttribute('aria-pressed')).toBe('true')
expect(segButton('Hidden').getAttribute('aria-pressed')).toBe('false')
})
})
+9
View File
@@ -145,6 +145,15 @@ export default function Settings() {
onChange={v => update(s => { s.keepAwake = v })} />
</Row>
)}
{/* 'full'/'mini' is also what the tap-toggle on the workout animation writes; 'off' hides
workout media entirely (library, detail sheet and picker thumbs are unaffected).
Legacy/unknown values read as 'full'. */}
<Row icon="figureRun" iconTint="var(--green)" title={t('Exercise animations')}>
<Segmented className="seg-inline"
options={[{ value: 'full', label: t('Full') }, { value: 'mini', label: t('Small') }, { value: 'off', label: t('Hidden') }]}
value={S.gifSize === 'mini' || S.gifSize === 'off' ? S.gifSize : 'full'}
onChange={v => update(s => { s.gifSize = v })} />
</Row>
<Row icon="bell" iconTint="var(--pink)" title={t('Sounds')}>
<Switch checked={!!S.sound} onChange={v => update(s => { s.sound = v })} />
</Row>