Salud moves to Home's header: a sixth tab pushed Start off centre
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
The tab bar is a flex row of equal columns with the Start button raised in the middle, so the tab count has to stay odd. Adding Salud as a sixth pushed that disc half a column to the right, and it read immediately as "the button moved" — the app's primary action is the one thing in the bar that must not drift. Salud is now the heart button in Home's header, next to the gear, with the same destination and the same route (/health). It is reachable from Settings → Data as well, which was already there. The tab bar is back to five: Home, Plan, Start, Stats, Exercises. Two tests, because this is the kind of change that regresses silently: TabBar.test.jsx asserts the odd count and that the raised button is the middle child (plus that no tab points at /health), and Home.health-door.test.jsx asserts the heart sits in the same non-shrinking container as the gear and navigates to /health — if that breaks, the screen is only reachable from Settings, where nobody looks for it. Also: the Comments in Home, TabBar, README, CHANGELOG and docs/HEALTH.md now say where Salud is, and one test assertion checks flexGrow/flexShrink rather than the `flex: none` shorthand — the CSSOM rewrites that to `0 0 auto`, which is what the first version of the test tripped over.
This commit is contained in:
1 parent
691e664d3f
commit
8d190bb591
7 files changed
+129
-9
No files matched your search
@@ -32,9 +32,11 @@ export default function TabBar({ onStart }) {
|
||||
<nav id="tabbar">
|
||||
<Tab k="home" icon="house" to="/home" label={t('Home')} />
|
||||
<Tab k="plan" icon="calendar" to="/plan" label={t('Plan')} />
|
||||
{/* Apple Health. Next to Plan because both answer "what am I doing about my body", and
|
||||
second in the bar (not last) because it is a place you go on purpose, not a drawer. */}
|
||||
<Tab k="health" icon="heart" to="/health" label={t('Health')} />
|
||||
{/* NOTE: five tabs, and it has to stay an odd number. The bar is a flex row of equal
|
||||
columns with the Start button raised in the middle, so a sixth tab pushes Start off
|
||||
centre by half a column and the app's primary action visibly drifts right (tried with
|
||||
Salud, reverted). A new destination belongs in a header — Salud lives next to the gear
|
||||
on Home — or it replaces one of these five. */}
|
||||
{/* On the workout screen itself there is nothing to resume, so the button reads as the
|
||||
tab it is and stays lit (#29); anywhere else it brings you back to the exercise you
|
||||
were on — the marker is kept in S.active.cur and never moves on its own (#21). */}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// @vitest-environment happy-dom
|
||||
/* The bar is a flex row of equal columns with the Start button raised in the middle, so the
|
||||
number of tabs has to stay ODD: a sixth tab pushed Start off centre by half a column and the
|
||||
app's primary action visibly drifted right (Salud lived here for one afternoon). Which five
|
||||
they are matters too — Salud is reached from Home's header, next to the gear. */
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
|
||||
const nav = vi.fn()
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useNavigate: () => nav,
|
||||
useLocation: () => ({ pathname: '/home' })
|
||||
}))
|
||||
vi.mock('../sheets.jsx', () => ({ startFlow: vi.fn() }))
|
||||
|
||||
const { default: TabBar } = await import('./TabBar.jsx')
|
||||
|
||||
let host, root
|
||||
beforeEach(() => {
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
nav.mockClear()
|
||||
host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
|
||||
useStore.setState(s => ({ S: { ...s.S, active: null, routines: [], week: {}, dayPlan: {} }, user: { id: 'u1', name: 'Test' } }))
|
||||
})
|
||||
afterEach(() => { act(() => root.unmount()); host.remove() })
|
||||
|
||||
const mount = () => act(() => root.render(<TabBar onStart={vi.fn()} />))
|
||||
const tabs = () => [...host.querySelectorAll('#tabbar > button')]
|
||||
|
||||
describe('the tab bar', () => {
|
||||
it('has an odd number of tabs, so the raised Start button stays in the middle', () => {
|
||||
mount()
|
||||
expect(tabs().length).toBe(5)
|
||||
expect(tabs()[2].classList.contains('start')).toBe(true)
|
||||
// Two on each side of it, or the disc is off centre by half a column.
|
||||
expect(tabs().slice(0, 2).every(b => !b.classList.contains('start'))).toBe(true)
|
||||
expect(tabs().slice(3).every(b => !b.classList.contains('start'))).toBe(true)
|
||||
})
|
||||
|
||||
it('goes Home, Plan, Start, Stats, Exercises', () => {
|
||||
mount()
|
||||
const labels = tabs().map(b => b.querySelector('span:last-child').textContent)
|
||||
expect(labels).toEqual(['Home', 'Plan', 'Start', 'Stats', 'Exercises'])
|
||||
})
|
||||
|
||||
it('does not carry Salud: it lives in Home\'s header, next to the gear', () => {
|
||||
mount()
|
||||
expect(host.textContent).not.toContain('Health')
|
||||
const clicked = []
|
||||
tabs().forEach(b => { b.dispatchEvent(new MouseEvent('click', { bubbles: true })); clicked.push(nav.mock.calls.at(-1)[0]) })
|
||||
expect(clicked).not.toContain('/health')
|
||||
expect(clicked).toContain('/plan')
|
||||
expect(clicked).toContain('/stats')
|
||||
expect(clicked).toContain('/library')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
// @vitest-environment happy-dom
|
||||
/* Salud is not in the tab bar (five tabs, so Start stays centred — see TabBar.test.jsx), which
|
||||
makes Home's header the way in. It has to sit next to the gear and go to /health: if this
|
||||
breaks, the screen is reachable only from Settings, which is where nobody looks for it. */
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
|
||||
const nav = vi.fn()
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => nav }))
|
||||
vi.mock('../sheets.jsx', () => ({
|
||||
starterPlanSheet: vi.fn(), bwSheet: vi.fn(), goalSheet: vi.fn(), dayOverrideSheet: vi.fn(),
|
||||
calendarSheet: vi.fn(), startFlow: vi.fn(), bwDeltaColor: () => ''
|
||||
}))
|
||||
|
||||
const { default: Home } = await import('./Home.jsx')
|
||||
|
||||
let host, root
|
||||
beforeEach(() => {
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
nav.mockClear()
|
||||
host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
|
||||
useStore.setState(s => ({ S: { ...s.S, routines: [], week: {}, dayPlan: {}, workouts: [], bodyweight: [], active: null }, user: { id: 'u1', name: 'Test' } }))
|
||||
})
|
||||
afterEach(() => { act(() => root.unmount()); host.remove() })
|
||||
|
||||
const headerButtons = () => [...host.querySelectorAll('.hdr button')]
|
||||
const click = el => act(() => { el.dispatchEvent(new MouseEvent('click', { bubbles: true })) })
|
||||
|
||||
describe('Home\'s header', () => {
|
||||
it('offers Salud next to the gear, in that order', () => {
|
||||
act(() => root.render(<Home />))
|
||||
const labels = headerButtons().map(b => b.getAttribute('aria-label'))
|
||||
expect(labels).toEqual(['Health', 'Settings'])
|
||||
// Same container, or they end up on separate lines / far apart on a narrow phone.
|
||||
expect(headerButtons()[0].parentElement).toBe(headerButtons()[1].parentElement)
|
||||
// ...and that container must not shrink. The CSSOM rewrites `flex: none` to `0 0 auto`, so
|
||||
// this asserts the property that actually matters rather than the shorthand that was typed.
|
||||
const wrap = headerButtons()[0].parentElement
|
||||
expect([wrap.style.flexGrow, wrap.style.flexShrink]).toEqual(['0', '0'])
|
||||
})
|
||||
|
||||
it('takes Salud to /health', () => {
|
||||
act(() => root.render(<Home />))
|
||||
click(headerButtons()[0])
|
||||
expect(nav).toHaveBeenCalledWith('/health')
|
||||
click(headerButtons()[1])
|
||||
expect(nav).toHaveBeenCalledWith('/settings')
|
||||
})
|
||||
})
|
||||
@@ -66,7 +66,14 @@ export default function Home() {
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
<div><h1>{user ? t('Hi {0}', user.name) : 'KuentaGYM'}</h1><div className="sub">{today.toLocaleDateString(dateLocale(), { weekday: 'long', day: 'numeric', month: 'long' })}</div></div>
|
||||
<button className="iconbtn" onClick={() => nav('/settings')} aria-label={t('Settings')}><Icon name="gear" /></button>
|
||||
{/* Salud sits here rather than in the tab bar: the bar holds five tabs so its raised
|
||||
Start button stays centred, and Health is a place you visit on purpose, not a drawer
|
||||
you flip through mid-session. `flex: none` for the same reason `.hdr>.btn` has it —
|
||||
the title gives way on a narrow phone, these two do not. */}
|
||||
<div style={{ display: 'flex', gap: 8, flex: 'none' }}>
|
||||
<button className="iconbtn" onClick={() => nav('/health')} aria-label={t('Health')} title={t('Health')}><Icon name="heart" /></button>
|
||||
<button className="iconbtn" onClick={() => nav('/settings')} aria-label={t('Settings')}><Icon name="gear" /></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
|
||||
Reference in new issue
Block a user