- @xenia/ui theme.js: a look = mode (light | dark | system) + palette (data-palette) + style (data-style); applyLook / getStoredLook (per device), 'system' resolved with matchMedia and followed live, so a palette is just a light and a dark token block; applyTheme kept for older callers (keeps palette and style) - tokens.css: 'Palettes' (first: Nord, light + dark, every colour and the nav rail) and 'Styles' (first: sharp: small corners, 1.5px borders, flat cards); --x-border-width used by every component and Tailwind's 'border' - contrast test: every palette in both modes (+ the nav rail); it caught the default rail's active item at 3.7:1 -> 5.5:1 - manager: the saved look applied at start (was light only); profile menu -> Look: Light / Dark / Device, Colours (Xenia, Nord), Shapes (Rounded, Sharp), applied at once and kept on this device - e2e: manager_look.mjs (every page in light and dark, no large near-white area in dark, contact sheets; 'nord-sharp' adds that look; in run-all), manager.mjs 'look:' (dark at once, kept after a reload, Device follows the device) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
7.1 KiB
JavaScript
107 lines
7.1 KiB
JavaScript
// Every manager page in each look (plan step 6.15: "every manager page reads well in dark, side
|
|
// by side screenshots reviewed"). For each page and look: a screenshot, and in dark looks a check
|
|
// that nothing large is still painted near-white (a colour that didn't come from the tokens).
|
|
// Then contact sheets (light | dark side by side, a few pages each) to review.
|
|
//
|
|
// node manager_look.mjs → out/manager-look/<page>-<look>.png, sheet-N.png
|
|
// node manager_look.mjs nord-sharp → also the Nord palette with the sharp style
|
|
//
|
|
// Starts its own backend (:8066, demo data) and the manager (:5190).
|
|
import { mkdirSync, openSync, writeFileSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { spawn } from 'node:child_process'
|
|
import { chromium } from 'playwright'
|
|
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
|
|
import { killTree, login, startBackend, waitHttp } from './lib/proc.mjs'
|
|
|
|
const DIR = path.join(OUT, 'manager-look')
|
|
mkdirSync(DIR, { recursive: true })
|
|
const extra = process.argv.includes('nord-sharp')
|
|
const LOOKS = [
|
|
{ id: 'light', mode: 'light', palette: 'default', style: 'rounded' },
|
|
{ id: 'dark', mode: 'dark', palette: 'default', style: 'rounded' },
|
|
...(extra ? [{ id: 'nord-light', mode: 'light', palette: 'nord', style: 'sharp' }, { id: 'nord-dark', mode: 'dark', palette: 'nord', style: 'sharp' }] : []),
|
|
]
|
|
const PAGES = [
|
|
'dashboard', 'tables', 'online-orders', 'online/fees', 'online/qr', 'crm/contacts', 'crm/customers', 'financials/expenses', 'financials/tabs',
|
|
'management/products', 'management/media', 'management/signage', 'management/tables', 'management/staff', 'management/sessions',
|
|
'management/approvals', 'management/schedule', 'management/prep-zones', 'management/pricing', 'inventory/throwaways', 'inventory/stock', 'notes',
|
|
'reports/today', 'reports/store', 'reports/staff', 'reports/products', 'reports/prep-zones', 'reports/expenses', 'reports/technical', 'reports/misc',
|
|
'apps', 'integrations', 'devices', 'license', 'settings?tab=app-info', 'settings?tab=venue', 'settings?tab=security', 'settings?tab=operation',
|
|
'settings?tab=colours', 'settings?tab=print-fonts', 'settings?tab=customer-display', 'settings?tab=menu-tablets', 'settings?tab=fiscal', 'apps/phone',
|
|
]
|
|
const MODULES = ['connect_orders', 'connect_menu', 'crm', 'tabs', 'expenses', 'inventory', 'notes', 'chat', 'customer_display', 'menu_tablet', 'signage',
|
|
'fiscal', 'staff_planning', 'reservations', 'pricing', 'caller_id', 'waiter_app']
|
|
|
|
const backend = await startBackend({ port: 8066, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
|
|
const APP = 'http://localhost:5190'
|
|
const log = openSync(path.join(OUT, 'vite-5190.log'), 'w')
|
|
const vite = spawn('npx', ['vite', '--port', '5190', '--strictPort'], {
|
|
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
|
|
stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url },
|
|
})
|
|
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
|
const r = reporter(`manager look (6.15): every page in ${LOOKS.map(l => l.id).join(', ')}`)
|
|
const name = p => p.replace(/[/?=]/g, '-')
|
|
try {
|
|
await waitHttp(APP)
|
|
const boss = await login(backend.url)
|
|
const put = (url, body) => fetch(`${backend.url}${url}`, { method: 'PUT', headers: { 'content-type': 'application/json', authorization: `Bearer ${boss}` }, body: JSON.stringify(body) })
|
|
for (const m of MODULES) await put(`/api/platform/modules/${m}`, { enabled: true }).catch(() => {})
|
|
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: 1280, height: 800 } })
|
|
const page = await ctx.newPage()
|
|
const errors = []
|
|
page.on('pageerror', e => errors.push(String(e)))
|
|
await page.goto(`${APP}/login`)
|
|
await page.getByTestId('login-form').waitFor({ timeout: 60_000 })
|
|
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
|
|
await page.getByLabel('Password').fill('password')
|
|
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
|
|
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 20_000 })
|
|
const bright = {}
|
|
for (const look of LOOKS) {
|
|
await page.evaluate(l => { localStorage.setItem('xenia_theme', l.mode); localStorage.setItem('xenia_palette', l.palette); localStorage.setItem('xenia_style', l.style) }, look)
|
|
for (const p of PAGES) {
|
|
await page.goto(`${APP}/${p}`)
|
|
await page.waitForLoadState('networkidle').catch(() => {})
|
|
await sleep(600)
|
|
await page.screenshot({ path: path.join(DIR, `${name(p)}-${look.id}.png`) })
|
|
if (look.mode === 'dark') {
|
|
// large elements still near-white in a dark look: colours that didn't come from the tokens
|
|
const hits = await page.evaluate(() => {
|
|
const lum = c => { const m = c.match(/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?/); if (!m || (m[4] !== undefined && Number(m[4]) < 0.5)) return 0; const f = x => { x /= 255; return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4 }; return 0.2126 * f(+m[1]) + 0.7152 * f(+m[2]) + 0.0722 * f(+m[3]) }
|
|
const out = []
|
|
for (const el of document.querySelectorAll('body *')) {
|
|
if (el.closest('.x-qr__tile, svg, img, video, canvas, [data-venue-colour], [data-testid^="signage-"], [data-testid="colours-free"], [data-testid^="colours-"]')) continue
|
|
const r = el.getBoundingClientRect()
|
|
if (r.width * r.height < 2000 || r.bottom < 0 || r.top > innerHeight) continue
|
|
if (lum(getComputedStyle(el).backgroundColor) > 0.8) out.push(`${el.tagName.toLowerCase()}.${String(el.className).split(' ').slice(0, 4).join('.')}`)
|
|
}
|
|
return out.slice(0, 5)
|
|
})
|
|
if (hits.length) bright[`${p} (${look.id})`] = hits
|
|
}
|
|
}
|
|
}
|
|
r.check('dark looks: no large near-white areas left', Object.keys(bright).length === 0, JSON.stringify(bright, null, 1).slice(0, 2000))
|
|
// contact sheets: for each page, every look side by side
|
|
const per = 5
|
|
for (let i = 0; i < PAGES.length; i += per) {
|
|
const rows = PAGES.slice(i, i + per).map(p => `<tr><th colspan="${LOOKS.length}">${p}</th></tr><tr>${LOOKS.map(l => `<td><img src="${name(p)}-${l.id}.png"></td>`).join('')}</tr>`).join('')
|
|
const file = path.join(DIR, `sheet-${i / per + 1}.html`)
|
|
writeFileSync(file, `<!doctype html><meta charset="utf-8"><style>body{margin:0;font:12px sans-serif;background:#888}th{text-align:left;padding:4px}td{padding:2px}img{width:${LOOKS.length > 2 ? 400 : 640}px;display:block}</style><table>${rows}</table>`)
|
|
const sheet = await ctx.newPage()
|
|
await sheet.goto(`file://${file.replace(/\\/g, '/')}`)
|
|
await sheet.screenshot({ path: path.join(DIR, `sheet-${i / per + 1}.png`), fullPage: true })
|
|
await sheet.close()
|
|
}
|
|
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
|
console.log(` screenshots and sheets: ${DIR}`)
|
|
} finally {
|
|
await browser.close()
|
|
killTree(vite)
|
|
await backend.stop()
|
|
}
|
|
process.exit(r.done() ? 1 : 0)
|