feat(terminal): kitchen display on paired screens, live without polling (platform-v2 3.2b)
Port of the manager's KdsPage.jsx into terminal/src/apps/kds, split into pure logic (layout packing, age, buckets, rounds, totals, status cycle, settings; unit-tested) and components (card, item, action bars, dialogs, item totals, rails, settings panel). - Settings are the device's config; the settings panel saves them (managers only), zoom changes the size for the session. - Orders reload on live events and every reconnect; polling only while the live connection is down (DeviceProvider exposes liveUp; useLiveEvents helper). - "Tap to start" unlocks sound; venue clock via useFormat; English-first texts. - Undo of an item recomputes the order status at once; undo/redo clear the selection. - Tests: terminal unit +15, terminal.mjs +12 KDS checks (no polling, live order + chime, item/undo/prepare/decline, settings permission, change made elsewhere), backend regression for an item back to pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+81
-1
@@ -139,6 +139,84 @@ try {
|
||||
})
|
||||
r.check('3.2a: what the old page used instead (/api/prep-zones) stays out of its scope', outside === 'device.out_of_scope', outside)
|
||||
|
||||
// ── 3.2b: the kitchen board on the screen ────────────────────────────────
|
||||
await page.reload() // a fresh start: the browser needs a tap before it plays sound
|
||||
r.check('3.2b: "Tap to start" first (sound needs a tap)', await shown(page, 'kds-start'))
|
||||
await page.getByTestId('kds-start').click()
|
||||
const card = page.locator(`[data-testid="kds-card"][data-order="${opened.id}"]`)
|
||||
r.check('3.2b: the board shows the order with its Grill item only', await card.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||
&& await card.locator('[data-item]').count() === 1 && (await card.textContent()).includes(p1.name), (await card.textContent().catch(() => '')).slice(0, 120))
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-kds-board.png') })
|
||||
|
||||
// live, without polling: count the screen's order requests while nothing else happens
|
||||
let polls = 0
|
||||
const countPolls = req => { if (req.url().includes('/api/kds/orders')) polls++ }
|
||||
page.on('request', countPolls)
|
||||
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { config: { prep_zone_id: grill.id, font_scale: 120, refresh_seconds: 10 } } })
|
||||
await sleep(12_000)
|
||||
page.off('request', countPolls)
|
||||
r.check('3.2b: no polling while the live connection is up (refresh 10 s, 12 s quiet)', polls <= 1, `${polls} requests`) // ≤1: the settings change may reload once
|
||||
|
||||
// a new order arrives live, with the chime
|
||||
const chimes0 = await page.evaluate(() => window.__xeniaChimes || 0)
|
||||
const table2 = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id && t.id !== table.id)
|
||||
const second = await api('POST', '/api/orders/', { token: maria, body: { table_id: table2.id } })
|
||||
await api('POST', `/api/orders/${second.id}/items`, { token: maria, body: { items: [{ product_id: p1.id, quantity: 2 }] } })
|
||||
const card2 = page.locator(`[data-testid="kds-card"][data-order="${second.id}"]`)
|
||||
r.check('3.2b: a new order appears by itself (live) and chimes', await card2.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||||
&& await page.evaluate(() => window.__xeniaChimes || 0) > chimes0)
|
||||
|
||||
// the zoom is the device's font_scale, changed live from the manager
|
||||
r.check('3.2b: text size follows the device setting live (120%)', (await page.getByTestId('zoom-level').textContent()) === '120%')
|
||||
|
||||
// tap the card, tap its item → done; the backend agrees
|
||||
const kdsItem = async (orderId, itemId) => (await api('GET', '/api/kds/orders', { token: boss })).orders
|
||||
.find(o => o.id === orderId)?.items.find(i => i.id === itemId)
|
||||
await card2.click({ position: { x: 20, y: 120 } })
|
||||
const item2 = card2.locator('[data-item]').first()
|
||||
const item2Id = Number(await item2.getAttribute('data-item'))
|
||||
await item2.click()
|
||||
await sleep(800)
|
||||
r.check('3.2b: tapping an item on the selected card marks it done', (await kdsItem(second.id, item2Id))?.kds_status === 'done')
|
||||
|
||||
// undo
|
||||
await page.getByTestId('kds-undo').click()
|
||||
await sleep(800)
|
||||
r.check('3.2b: undo puts it back', (await kdsItem(second.id, item2Id))?.kds_status === 'pending')
|
||||
|
||||
// the action bar: in progress
|
||||
await card2.click({ position: { x: 20, y: 120 } })
|
||||
await card2.getByTestId('card-prepare').click()
|
||||
await sleep(800)
|
||||
r.check('3.2b: "in progress" from the card\'s buttons', (await api('GET', '/api/kds/orders', { token: boss })).orders.find(o => o.id === second.id)?.kds_status === 'preparing')
|
||||
|
||||
// long press → quick actions → decline with a reason
|
||||
const box = await card.boundingBox()
|
||||
await page.mouse.move(box.x + 30, box.y + 120)
|
||||
await page.mouse.down()
|
||||
await sleep(800)
|
||||
await page.mouse.up()
|
||||
r.check('3.2b: a long press shows the quick actions', await shown(page, 'quick-decline', 3000))
|
||||
await page.getByTestId('quick-decline').click()
|
||||
await page.locator('[data-reason="out_of_stock"]').click()
|
||||
await page.getByTestId('decline-confirm').click()
|
||||
await sleep(800)
|
||||
const declined = (await api('GET', `/api/kds/orders?zone_id=${grill.id}`, { token: boss })).orders.find(o => o.id === opened.id)
|
||||
r.check('3.2b: declined with the reason', !!declined && declined.items.some(i => i.kds_status === 'declined' && i.decline_note === 'Out of stock'),
|
||||
JSON.stringify(declined?.items?.map(i => [i.kds_status, i.decline_note])))
|
||||
|
||||
// settings on the screen: a chef sees them but can't save
|
||||
await page.getByTestId('kds-settings').click()
|
||||
r.check('3.2b: the screen\'s settings: a chef sees them, with "only a manager"', await shown(page, 'kds-settings-panel', 3000)
|
||||
&& await page.getByTestId('settings-no-permission').count() === 1 && await page.getByTestId('settings-save').isDisabled())
|
||||
await page.keyboard.press('Escape').catch(() => {})
|
||||
await page.getByTestId('kds-settings-panel').getByRole('button', { name: 'Close' }).click()
|
||||
|
||||
// a change made elsewhere (another screen, the waiter) reaches this screen live
|
||||
await api('PUT', `/api/kds/orders/${second.id}/kds_status`, { token: boss, body: { status: 'pending' } })
|
||||
await page.waitForFunction(id => document.querySelector(`[data-testid="kds-card"][data-order="${id}"]`)?.dataset.status === 'pending', second.id, { timeout: 5000 }).catch(() => {})
|
||||
r.check('3.2b: a change made elsewhere shows on the screen by itself', await card2.getAttribute('data-status') === 'pending')
|
||||
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
r.check('sign out → back to the names', await shown(page, 'user-grid'))
|
||||
|
||||
@@ -203,7 +281,9 @@ try {
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-removed.png') })
|
||||
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||||
} catch (e) {
|
||||
r.check(`terminal: ${e.message.split('\n')[0]}`, false)
|
||||
r.check(`terminal: ${e.message.split('\n').slice(0, 8).join(' | ')}`, false)
|
||||
const pages = browser.contexts().flatMap(c => c.pages())
|
||||
for (const [i, p] of pages.entries()) await p.screenshot({ path: path.join(OUT, `terminal-failure-${i}.png`) }).catch(() => {})
|
||||
} finally {
|
||||
await browser.close()
|
||||
term.stop()
|
||||
|
||||
Reference in New Issue
Block a user