Files
xenia-pos-local/tests/e2e/waiter_look.mjs
T
bonaminandClaude Opus 5.5 beb53c65bb feat(waiter): the look on the shared tokens; the venue's colour (platform-v2 step 4.6)
- The waiter's --bg/--text/--accent… are made of @xenia/ui tokens: light / dark (user
  menu) and the venue's accent reach every screen; the 751 colour literals in
  waiter_pwa/src became tokens (by hue family and lightness), hex-alpha suffixes became
  fade() (color-mix), fixing 'var(--accent)18' tints that never showed.
- @xenia/ui: new `special` (violet: offers, discounts, deals; contrast-tested) and
  `on-colour` tokens.
- Setting venue.theme (teal | amber | blue | violet | rose, default amber), bootstrap
  venue.theme, manager Settings → Venue → Colour; the waiter sets data-venue-theme and
  the theme before the first render.
- Guard tests/no-colours.test.mjs; tests/e2e/waiter_look.mjs (every page light + dark,
  side-by-side compare page); waiter e2e +3; backend test_venue_theme.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:08:39 +02:00

94 lines
5.2 KiB
JavaScript

// Screenshots of every waiter page, light and dark, on a phone-sized screen (plan step 4.6:
// "the screenshots of every page are reviewed side by side with today's").
//
// node waiter_look.mjs <label> → out/look/<label>/<page>-<theme>.png
// node waiter_look.mjs --compare a b → out/look/compare.html (a and b side by side)
//
// Starts its own backend (:8062, demo data) and the venue-mode dev build (:5182).
import { mkdirSync, readdirSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, OUT, sleep } from './lib/env.mjs'
import { login, startBackend, startViteNative } from './lib/proc.mjs'
const LOOK = path.join(OUT, 'look')
if (process.argv[2] === '--compare') {
const [a, b] = process.argv.slice(3)
const shots = readdirSync(path.join(LOOK, a)).filter(f => f.endsWith('.png')).sort()
const rows = shots.map(f => `<tr><th colspan="2">${f}</th></tr><tr><td><img src="${a}/${f}"></td><td><img src="${b}/${f}"></td></tr>`).join('\n')
writeFileSync(path.join(LOOK, 'compare.html'), `<!doctype html><meta charset="utf-8"><title>Waiter look ${a} / ${b}</title>
<style>body{font-family:sans-serif;background:#ddd}td{vertical-align:top;padding:6px}img{width:393px;border:1px solid #999}th{text-align:left;padding-top:18px}</style>
<table><tr><th>${a}</th><th>${b}</th></tr>${rows}</table>`)
console.log(`✓ ${path.join(LOOK, 'compare.html')} (${shots.length} pages)`)
process.exit(0)
}
const label = process.argv[2] || 'now'
const dir = path.join(LOOK, label)
mkdirSync(dir, { recursive: true })
const backend = await startBackend({ port: 8062, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
const vite = await startViteNative({ port: 5182, backendUrl: backend.url })
const APP = 'http://localhost:5182'
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
try {
const boss = await login(backend.url)
await fetch(`${backend.url}/api/business-day/open`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${boss}` }, body: '{}' }).catch(() => {})
const ctx = await browser.newContext({ viewport: { width: 393, height: 852 }, deviceScaleFactor: 1, isMobile: true, hasTouch: true })
const page = await ctx.newPage()
await page.goto(`${APP}/login`)
await page.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click()
for (const d of '3302') await page.getByRole('button', { name: d, exact: true }).first().click()
await page.getByRole('button', { name: /Start shift/ }).click({ timeout: 10_000 }).catch(() => {})
await page.waitForURL(u => u.pathname.startsWith('/tables'), { timeout: 15_000 }).catch(() => {})
const token = await page.evaluate(() => localStorage.getItem('xenia:dev:token'))
const api = (m, u, body) => fetch(backend.url + u, { method: m, headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` }, body: body && JSON.stringify(body) }).then(r => r.json())
const tables = await api('GET', '/api/tables/')
// an order with a few items on the first table (the demo data has only finished orders)
const [busy, free] = tables
const prods = (await api('GET', '/api/products/')).filter(p => p.is_available && !p.is_service_item && !(p.preference_sets || []).some(ps => ps.default_choice_id == null))
const o = await api('POST', '/api/orders/', { table_id: busy.id, order_type: 'here' })
await api('POST', `/api/orders/${o.id}/items`, { lines: prods.slice(0, 4).map((p, i) => ({ product_id: p.id, quantity: i + 1 })) })
const shots = [
['01-tables', '/tables'],
['02-orders', '/tables?tab=orders'],
['03-table-detail', `/tables/${busy.id}`],
['04-table-free', `/tables/${free.id}`],
['05-add-items', `/tables/${busy.id}/add`],
['06-shift', '/shift-overview'],
['07-order-log', '/order-log'],
['08-settings', '/settings'],
['09-messages', '/messages'],
]
for (const theme of ['dark', 'light']) {
await page.evaluate(th => { localStorage.setItem('pos-theme', JSON.stringify({ state: { dark: th === 'dark' }, version: 0 })) }, theme)
for (const [name, url] of shots) {
await page.goto(APP + url)
await sleep(2500)
await page.screenshot({ path: path.join(dir, `${name}-${theme}.png`) })
}
// the cart and the options drawer
await page.goto(`${APP}/tables/${busy.id}/add`)
await sleep(2000)
await page.locator('[data-testid="product-card"]').first().click().catch(() => {})
await sleep(1200)
await page.screenshot({ path: path.join(dir, `10-drawer-${theme}.png`) })
await page.goto(`${APP}/tables/${busy.id}`)
await sleep(2000)
await page.getByText(/ACTIONS/i).first().click().catch(() => {})
await sleep(800)
await page.screenshot({ path: path.join(dir, `11-actions-${theme}.png`) })
await page.getByTestId('user-menu').click().catch(() => {})
}
const p2 = await ctx.newPage()
await page.evaluate(() => localStorage.removeItem('xenia:dev:token'))
await p2.goto(`${APP}/login`)
await sleep(2000)
await p2.screenshot({ path: path.join(dir, '00-login-light.png') })
console.log(`✓ ${dir}`)
} finally {
await browser.close()
vite.stop(); await backend.stop()
}