feat(ui): @xenia/ui design tokens, Tailwind preset and base components

Platform-v2 step 2.3 (APPS_PLATFORM D-15 §9):
- tokens.css: --x- prefixed colours (light/dark/system + 5 venue accent themes),
  spacing, radius, type scale, shadows, motion, z-index; variables only
- components.css: .x-* classes only, no element selectors (new rule CS-16)
- Button, IconButton, Dialog, Sheet, Toast, PinPad, InfoTip, EmptyState,
  Spinner, Field/Input/Textarea/Select, Switch (accessible: focus trap and
  restore, ARIA wiring, 44px targets)
- tailwind-preset.js (adds names only); manager uses it + styles.css, the
  waiter imports tokens.css; existing screens unchanged
- dev-only /ui-gallery in the manager; e2e suite tests/e2e/ui.mjs; unit tests
  for PIN rules and WCAG AA contrast of every token pair, both in run-all

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 19:33:58 +02:00
co-authored by Claude Opus 5.5
parent c7102f1c89
commit 3580f2815c
36 changed files with 1920 additions and 8 deletions
+4
View File
@@ -14,6 +14,9 @@ python -m pytest tests -q -m db # DB tests only: real app + temp SQLite
cd ../waiter_pwa
npm test # server rediscovery scan
cd ..
npm test -w @xenia/ui # PIN rules + WCAG contrast of every token pair (light/dark × venue themes)
```
**DB tests** (`local_backend/tests/conftest.py`) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: `db` (session, rolled back after each test even if the code commits), `client` (TestClient with `get_db` overridden, license check open, no lifespan), `make_user(role=..., perms=...)` (password `password`, PIN `1234`), `login(user)` (auth headers). A test that uses any of them is marked `db` automatically.
@@ -33,6 +36,7 @@ Or run one suite at a time:
|---|---|---|---|
| `node install.mjs` | `install.sh`: VPN-safe `HOST_IP` detection (simulated WireGuard/WiFi hosts); fresh install, upgrade, re-run; proxy config identical to `nginx-proxy/nginx.conf` | Docker | ~1 min |
| `python license_e2e.py` | Offline licensing with a real cloud + site process: 400 days offline, tampered file, clock set back, expiry deferred to workday close, renewal, remote lock | Python deps of both backends | ~2 min |
| `node ui.mjs` | `@xenia/ui` components on the dev-only gallery (`/ui-gallery`, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes | Edge | ~30 s |
| `node browser.mjs` | Waiter web modes (same-origin, plain HTTP by LAN IP, venue mode), install dialog + drawer entry (Android / iPhone / desktop / no APK) | Docker, Edge | ~2 min |
| `node android.mjs basics` | Pairing, wrong address / other venue's QR, login + live WS, back button, restart, two venues, camera permission | Android emulator | ~5 min |
| `node android.mjs rediscovery` | Server IP change (logged in / out), server down + manual search, cold start while offline | Android emulator | ~4 min |
+3 -1
View File
@@ -2,15 +2,17 @@
// node run-all.mjs everything (Android included)
// node run-all.mjs --no-android skip the emulator suite
import { spawnSync } from 'node:child_process'
import { BACKEND, E2E, PYTHON, WAITER } from './lib/env.mjs'
import { BACKEND, CS, E2E, PYTHON, WAITER } from './lib/env.mjs'
const shell = process.platform === 'win32'
const suites = [
['unit: local_backend (pytest)', PYTHON, ['-m', 'pytest', 'tests', '-q'], BACKEND],
['unit: waiter_pwa (node --test)', 'npm', ['test', '--silent'], WAITER],
['unit: packages/ui (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/ui'], CS],
['install.sh', 'node', ['install.mjs'], E2E],
['license (cloud + site)', PYTHON, ['license_e2e.py'], E2E],
['browser', 'node', ['browser.mjs'], E2E],
['ui (@xenia/ui gallery)', 'node', ['ui.mjs'], E2E],
]
if (!process.argv.includes('--no-android')) suites.push(['android (emulator)', 'node', ['android.mjs'], E2E])
+129
View File
@@ -0,0 +1,129 @@
// @xenia/ui suite (Playwright + Edge): the shared components' behaviour on the
// gallery page (plan step 2.3). Starts the manager's Vite dev server (:5185), which
// serves /ui-gallery in dev builds only. No backend needed.
// node ui.mjs
import { spawn } from 'node:child_process'
import { openSync } from 'node:fs'
import path from 'node:path'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
import { killTree, waitHttp } from './lib/proc.mjs'
const PORT = 5185
const URL = `http://localhost:${PORT}/ui-gallery`
const log = openSync(path.join(OUT, `vite-${PORT}.log`), 'w')
const vite = spawn('npx', ['vite', '--port', String(PORT), '--strictPort'], {
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
stdio: ['ignore', log, log],
})
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
const r = reporter('ui: @xenia/ui components (gallery)')
try {
await waitHttp(`http://localhost:${PORT}/`)
const p = await browser.newPage({ viewport: { width: 1280, height: 900 } })
const errs = []
p.on('pageerror', e => errs.push('pageerror: ' + e.message))
// The manager shell may call the API (no backend here): ignore failed requests only
p.on('console', m => { if (m.type() === 'error' && !/Failed to load resource/i.test(m.text())) errs.push(m.text().slice(0, 200)) })
const active = () => p.evaluate(() => { const a = document.activeElement; return a ? (a.getAttribute('aria-label') || a.textContent || a.tagName).trim().slice(0, 40) : null })
const btn = name => p.getByRole('button', { name, exact: true })
await p.goto(URL)
await p.waitForSelector('text=@xenia/ui gallery', { timeout: 60_000 })
// Dialog
await btn('Open dialog').click()
const dlg = p.getByRole('dialog', { name: 'Delete product?' })
r.check('dialog: opens with role + accessible name', await dlg.isVisible())
r.check('dialog: focuses the first field, not the ×', await p.evaluate(() => document.activeElement?.tagName) === 'INPUT')
for (let i = 0; i < 6; i++) await p.keyboard.press('Tab')
r.check('dialog: Tab stays inside', await p.evaluate(() => !!document.activeElement?.closest('[role="dialog"]')))
r.check('dialog: page scroll locked', await p.evaluate(() => document.body.style.overflow) === 'hidden')
await p.keyboard.press('Escape')
r.check('dialog: Escape closes, focus back on the opener', !(await dlg.isVisible()) && (await active()) === 'Open dialog')
r.check('dialog: scroll unlocked', await p.evaluate(() => document.body.style.overflow) === '')
await btn('Open dialog').click()
await p.mouse.click(10, 10)
r.check('dialog: backdrop click closes', !(await dlg.isVisible()))
await btn('Non-dismissible dialog').click()
await p.keyboard.press('Escape'); await p.mouse.click(10, 10)
const locked = p.getByRole('dialog', { name: 'Finish the close of day' })
r.check('dialog: non-dismissible ignores Escape/backdrop, no ×', await locked.isVisible() && (await locked.getByRole('button', { name: 'Close' }).count()) === 0)
await locked.getByRole('button', { name: 'Done' }).click()
// Sheet
await btn('Bottom sheet').click()
const sheet = p.getByRole('dialog', { name: 'Move order' })
await sheet.getByRole('button', { name: 'Close' }).click()
r.check('sheet: × closes', !(await sheet.isVisible()))
// Toast
await btn('Toast: success').click()
await btn('Toast: danger').click()
r.check('toast: success is a polite status, danger an alert',
await p.locator('.x-toast--success[role="status"]').count() === 1 && await p.locator('.x-toast--danger[role="alert"]').count() === 1)
await btn('Toast: action').click()
await p.getByRole('button', { name: 'Undo' }).click()
r.check('toast: action runs and dismisses', await p.locator('.x-toast', { hasText: 'Undone' }).count() === 1 && await p.locator('.x-toast', { hasText: 'Order moved' }).count() === 0)
await sleep(4500)
r.check('toast: auto-dismisses', await p.locator('.x-toast', { hasText: 'Saved' }).count() === 0)
// Field
const price = p.getByLabel('Price')
r.check('field: error wired (aria-invalid + aria-describedby)', await price.getAttribute('aria-invalid') === 'true' &&
await p.evaluate(id => document.getElementById(id)?.textContent, await price.getAttribute('aria-describedby')) === 'Enter a price, e.g. 3,50')
const name = p.getByLabel('Product name *')
r.check('field: required + hint wired', await name.getAttribute('required') !== null &&
(await p.evaluate(id => document.getElementById(id)?.textContent, await name.getAttribute('aria-describedby'))).startsWith('Shown on'))
// Switch
const sw = p.getByRole('switch', { name: 'Alert after print failures' })
await sw.click()
r.check('switch: toggles aria-checked', await sw.getAttribute('aria-checked') === 'true')
await p.getByText('Print kitchen tickets').click()
r.check('switch: the label toggles it', await p.getByRole('switch', { name: 'Print kitchen tickets' }).getAttribute('aria-checked') === 'false')
// InfoTip
const tip = p.getByRole('button', { name: 'More info' }).first()
await tip.click()
r.check('infotip: opens', await p.getByRole('tooltip').isVisible())
await p.keyboard.press('Escape')
r.check('infotip: Escape closes, focus back', !(await p.getByRole('tooltip').isVisible()) && (await active()) === 'More info')
await tip.click(); await p.mouse.click(5, 300)
r.check('infotip: click outside closes', !(await p.getByRole('tooltip').isVisible()))
// PinPad
const pad = p.locator('.x-pinpad')
await pad.scrollIntoViewIfNeeded()
for (const d of '9999') await pad.getByRole('button', { name: d, exact: true }).click()
await sleep(900)
r.check('pinpad: wrong PIN → error, cleared', await pad.getByRole('alert').textContent() === 'Wrong PIN' && await pad.locator('.x-pinpad__dot--filled').count() === 0)
await pad.getByRole('button', { name: '1', exact: true }).click()
await pad.getByRole('button', { name: 'Delete' }).click()
r.check('pinpad: backspace', await pad.locator('.x-pinpad__dot--filled').count() === 0)
await p.locator('body').click({ position: { x: 5, y: 5 } })
await p.keyboard.type('1234')
await sleep(900)
r.check('pinpad: right PIN from the keyboard', (await p.getByTestId('pin-result').textContent()).startsWith('Unlocked'))
await name.fill('')
await name.type('12')
r.check('pinpad: typing in a field does not feed it', await pad.locator('.x-pinpad__dot--filled').count() === 0)
// Themes
await p.getByLabel('Theme', { exact: true }).selectOption('dark')
await p.getByLabel('Venue theme').selectOption('amber')
await sleep(500) // buttons fade between colours
const bg = await p.evaluate(() => getComputedStyle(document.querySelector('.x-btn--primary')).backgroundColor)
r.check('theme: dark + venue amber change the accent', bg === 'rgb(245, 158, 11)', bg)
await p.screenshot({ path: path.join(OUT, 'ui-gallery-dark-amber.png'), fullPage: true })
await p.evaluate(() => { history.pushState({}, '', '/login'); dispatchEvent(new PopStateEvent('popstate')) })
await sleep(500)
r.check('theme: leaving the gallery restores <html>', await p.evaluate(() => !document.documentElement.hasAttribute('data-theme') && !document.documentElement.hasAttribute('data-venue-theme')))
r.check('no page or console errors', errs.length === 0, errs.slice(0, 3).join(' | '))
} finally {
await browser.close()
killTree(vite)
}
process.exit(r.done() ? 1 : 0)