Files
xenia-pos-local/tests/e2e/menu_tablet.mjs
T
bonaminandClaude Opus 5.5 cc81e0a31f feat(terminal): the menu tablet app (platform-v2 step 5.7a)
terminal/src/apps/menu-tablet: the venue's menu for staff (a quick price
check) and guests. Category chips that jump to their section, or one A–Z
list; compact rows, expanded rows (photo, description) or full cards; tap a
product to see it big (photo, price, description, tags); search that ignores
accents and also finds names typed in Latin letters ("souvl"); sold out
marked; the guest's language for the tablet's texts; back to the start (search
cleared, first language, top) after the set time without a touch; light or
dark; the last menu kept for offline; live on menu_tablet.changed /
device.updated. @xenia/i18n exports ./latin for plain-JS use.
tests: logic (3), e2e menu_tablet.mjs (10 checks, in run-all).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 23:44:42 +02:00

104 lines
6.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Menu tablet suite (plan step 5.7a): a tablet paired as a menu tablet shows the venue's menu with
// prices; search finds a product (also typed in Latin letters) and its price; a product opens big;
// the view options from the device config change it live; a price change shows without a reload;
// the guest's language; back to the start after a while without a touch.
// Starts its own backend (:8067) and the terminal (:5195).
// node menu_tablet.mjs
import path from 'node:path'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, OUT, reporter, sleep, waitFor } from './lib/env.mjs'
import { startBackend, startTerminalVite } from './lib/proc.mjs'
import { supportLogin } from './lib/support.mjs'
const backend = await startBackend({ port: 8067, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
const term = await startTerminalVite({ port: 5195, backendUrl: backend.url })
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
const r = reporter('menu tablet: the menu, search, views, live prices, languages, idle reset (5.7a)')
const errors = []
let failures = 0
async function api(method, url, { token, body } = {}) {
const res = await fetch(backend.url + url, {
method, headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
body: body === undefined ? undefined : JSON.stringify(body),
})
const text = await res.text()
let data = null
try { data = JSON.parse(text) } catch { data = text }
if (!res.ok) throw new Error(`${method} ${url} → ${res.status} ${text.slice(0, 200)}`)
return data
}
const shown = (page, testId, timeout = 10_000) => page.getByTestId(testId).first().waitFor({ timeout }).then(() => true).catch(() => false)
try {
const boss = await supportLogin(backend.url)
await api('PUT', '/api/platform/modules/menu_tablet', { token: boss, body: { enabled: true } }).catch(() => {})
const products = (await api('GET', '/api/products/?sold_at=in_store', { token: boss })).filter(p => !p.is_service_item && p.lifecycle_status === 'active')
const souvlaki = products.find(p => /Σουβλάκι/.test(p.name)) || products[0]
const tab = await (await browser.newContext({ viewport: { width: 1180, height: 820 }, hasTouch: true })).newPage()
tab.on('pageerror', e => errors.push(e.message))
await tab.goto(term.url)
await shown(tab, 'pairing-code', 20_000)
const code = await tab.getByTestId('pairing-code').getAttribute('data-code')
const dev = await api('POST', '/api/devices', { token: boss, body: { code, app_key: 'menu_tablet', name: 'Entrance' } })
r.check('a tablet paired as a menu tablet shows the menu by category, with prices', await shown(tab, 'menu-section', 20_000)
&& await tab.getByTestId('menu-section').count() > 1 && await tab.getByTestId('menu-price').count() > 5)
await tab.screenshot({ path: path.join(OUT, 'menu-tablet-expanded.png') })
// the staff's price check
await tab.getByTestId('menu-search').fill('souvl')
const hit = tab.getByTestId('menu-results').locator(`[data-testid="menu-item"][data-id="${souvlaki.id}"]`)
r.check(`search in Latin letters ("souvl") finds "${souvlaki.name}" with its price`, await hit.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
&& (await hit.textContent()).includes(souvlaki.base_price.toFixed(2)))
await hit.click()
r.check('…and opens it big with its price', await shown(tab, 'menu-details', 5000)
&& (await tab.getByTestId('menu-details').getByTestId('menu-price').textContent()).includes(souvlaki.base_price.toFixed(2)))
await tab.keyboard.press('Escape')
await tab.getByTestId('menu-search').fill('zzzz')
r.check('nothing found: says so', await shown(tab, 'menu-no-results', 5000))
await tab.getByTestId('menu-search').fill('')
// the view options from the device config, live
await api('PATCH', `/api/devices/${dev.id}`, { token: boss, body: { config: { view: 'full', theme: 'dark' } } })
r.check('the view from the manager (full cards, dark) changes the tablet at once',
!!(await waitFor(async () => (await tab.getByTestId('app-menu_tablet').getAttribute('data-view')) === 'full', 15_000, 300))
&& await tab.evaluate(() => document.documentElement.dataset.theme) === 'dark')
await tab.screenshot({ path: path.join(OUT, 'menu-tablet-full.png') })
await api('PATCH', `/api/devices/${dev.id}`, { token: boss, body: { config: { view: 'compact', group: false, theme: 'light' } } })
r.check('compact, one A–Z list', !!(await waitFor(async () => (await tab.getByTestId('app-menu_tablet').getAttribute('data-view')) === 'compact'
&& (await tab.getByTestId('menu-section').count()) === 1, 15_000, 300)))
await tab.screenshot({ path: path.join(OUT, 'menu-tablet-compact.png') })
// a price change, live
await api('PUT', `/api/products/${souvlaki.id}`, { token: boss, body: { base_price: 7.7 } })
const live = await waitFor(async () => ((await tab.locator(`[data-testid="menu-item"][data-id="${souvlaki.id}"]`).textContent().catch(() => '')).includes('7.70') ? true : null), 15_000, 300)
r.check('a price change shows on the tablet without a reload', !!live)
// the guest's language, then back to the start after a while
await tab.getByTestId('menu-lang-en').click()
const enPlaceholder = await tab.getByTestId('menu-search').getAttribute('placeholder')
await tab.getByTestId('menu-lang-el').click()
const elPlaceholder = await tab.getByTestId('menu-search').getAttribute('placeholder')
r.check('the guest picks the language (the tablet\'s own texts)', enPlaceholder !== elPlaceholder, `${enPlaceholder} / ${elPlaceholder}`)
await api('PATCH', `/api/devices/${dev.id}`, { token: boss, body: { config: { idle_seconds: 30 } } })
await sleep(1500)
await tab.getByTestId('menu-search').fill('souvl')
await tab.getByTestId('menu-lang-en').click()
const reset = await waitFor(async () => ((await tab.getByTestId('menu-search').inputValue()) === '' ? true : null), 45_000, 1000)
r.check('after a while without a touch: back to the start (search cleared, the first language)', !!reset
&& await tab.getByTestId('menu-lang-el').getAttribute('aria-pressed') === 'true')
r.check('no page errors', errors.length === 0, errors.join(' | '))
failures += r.done()
} catch (e) {
console.error(e)
r.check('the suite ran to the end', false, String(e.message).split(/\r?\n/)[0])
failures += r.done()
} finally {
await browser.close()
term.stop()
await backend.stop()
}
process.exit(failures ? 1 : 0)