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>
130 lines
7.4 KiB
JavaScript
130 lines
7.4 KiB
JavaScript
// @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)
|