Files
xenia-pos-local/tests/e2e/menu_tablet.mjs
T
bonaminandClaude Opus 5.5 5048f82a4c feat(manager): products and categories on v2, a product in several categories, allergens (platform-v2 step 6.3)
- Management/ProductsTab + ProductFormModal (3.1k lines) → src/pages/products/: category tree,
  list/grid, toolbar + filters (search folds accents and Latin letters), bulk actions, category
  dialogs; the editor in editor/ (details, sold at, cost, fiscal; the waiter's choices).
  Arithmetic in productsLogic.js / editor/formLogic.js (tests/products.test.mjs).
- Several categories per product with a main one (D-23): edited in the editor, "also in" on the
  rows, each category's list ordered on its own (drag or up/down → PUT /reorder with category_id);
  bulk "move to" / "also list in". The waiter's picker now shows a product in every category.
- Allergens: products.allergens (Alembic 0032, core/allergens.py: 14 EU, contains | may_contain,
  catalog.allergen), in the API, POS menu, menu tablet, catalogue bundles and the cloud snapshot
  (C-2); @xenia/access allergens.js + <Allergens> shown on the phone, the counter, the tablet.
- Bell: only the newest load sets the list (an older answer could hide a live notification).
- e2e: manager (two categories, order per category, allergens), terminal / menu tablet / waiter
  (allergens shown); media saves by test id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 10:04:35 +02:00

120 lines
7.8 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; a tablet at a table calls
// a waiter (5.7b).
// 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), call a waiter (5.7b)')
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]
await api('PUT', `/api/products/${souvlaki.id}`, { token: boss, body: { allergens: { gluten: 'contains', mustard: 'may_contain' } } })
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)))
r.check('6.3: …with its allergens', await tab.getByTestId('menu-details').locator('[data-allergen="gluten"][data-level="contains"]').count() === 1
&& await tab.getByTestId('menu-details').locator('[data-allergen="mustard"][data-level="may_contain"]').count() === 1)
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)
// 5.7b: a tablet at a table calls a waiter; one without a table has no button
r.check('5.7b: a tablet not at a table has no "Call a waiter" button', await tab.getByTestId('menu-call-button').count() === 0)
const tables = await api('GET', '/api/tables/', { token: boss })
const t5 = tables.find(x => x.is_active !== false) || tables[0]
await api('PATCH', `/api/devices/${dev.id}`, { token: boss, body: { config: { table: t5.id } } })
r.check('5.7b: set at a table, it gets the button', await shown(tab, 'menu-call-button', 15_000))
await tab.getByTestId('menu-call-button').click()
r.check('5.7b: calling says a waiter is on the way, and waits before it can call again',
await shown(tab, 'menu-call-sent', 5000) && await tab.getByTestId('menu-call-button').isDisabled()
&& (await tab.getByTestId('menu-call-sent').textContent()).includes(t5.label || String(t5.number)))
await tab.screenshot({ path: path.join(OUT, 'menu-tablet-call.png') })
// 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)