feat: the table map (platform-v2 step 6.8, D-31)

- floor_plans / floor_items (0035), tables' plan_id + width/height/rotation/shape;
  /api/floor-plans (set-up, catalog.tables.manage, floor_plans.changed) and
  /api/floor-plans/live (each table's state, guests, waiters, time; zone rule)
- @xenia/floorplan: the drawing (Floor, Item, TableShape, FloorView) and its geometry
  (grid snap in whole cells, outlines, chairs), tested
- manager: Management -> Tables -> Floor plans (editor: drag, grid, irregular floor,
  walls/bar/labels/areas, background picture), Tables page List / Map
- counter POS: Tables List / Map; waiter: Map mode, the list stays the default
- tests: test_floor_plans.py, floor + geometry unit tests, manager/waiter/terminal e2e

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 17:00:45 +02:00
co-authored by Claude Opus 5.5
parent fd3254aa31
commit f4aae6abbc
47 changed files with 2102 additions and 8 deletions
+54
View File
@@ -953,6 +953,60 @@ try {
for (let i = 0; i < 20 && limits?.max_total_value_workday !== null; i++) { await sleep(250); limits = await api('GET', '/api/pricing/discount-settings/global', { token: boss }) }
r.check(`${pg} emptied: no limit`, limits?.max_total_value_workday === null, JSON.stringify(limits))
// ── 6.8: a floor plan drawn in the manager (the phones and the counter: waiter.mjs, terminal.mjs) ──
const fl = 'floor plans:'
await page.goto(`${APP}/management/tables`)
await page.getByTestId('tables-tab-floor').click()
await page.getByTestId('floor-new').first().click()
await page.getByTestId('floor-new-name').fill('E2E ground floor')
await page.getByTestId('floor-create').click()
await page.getByTestId('floor-editor').waitFor({ timeout: 10_000 })
const ownButtons = page.getByTestId('floor-own-tables').locator('button')
await ownButtons.first().waitFor({ timeout: 5000 })
const firstId = Number(await ownButtons.first().getAttribute('data-table'))
await ownButtons.first().click()
await page.keyboard.press('Escape')
await page.getByTestId('floor-canvas').click({ position: { x: 5, y: 5 } })
const secondId = Number(await ownButtons.first().getAttribute('data-table'))
await ownButtons.first().click()
await page.getByTestId('floor-shape-round').click()
await page.getByTestId('floor-canvas').click({ position: { x: 5, y: 5 } })
await page.getByTestId('floor-add-bar').click()
// drag the first table 150 px to the right
await page.locator(`[data-testid="floor-canvas"] [data-testid="floor-table"][data-table="${firstId}"]`).scrollIntoViewIfNeeded()
const tb = await page.locator(`[data-testid="floor-canvas"] [data-testid="floor-table"][data-table="${firstId}"]`).boundingBox()
await page.mouse.move(tb.x + tb.width / 2, tb.y + tb.height / 2)
await page.mouse.down()
await page.mouse.move(tb.x + tb.width / 2 + 75, tb.y + tb.height / 2, { steps: 5 })
await page.mouse.move(tb.x + tb.width / 2 + 150, tb.y + tb.height / 2 + 60, { steps: 5 })
await page.mouse.up()
// an irregular floor: a corner more, pulled in
await page.getByTestId('floor-shape-mode').click()
await page.getByTestId('floor-corner').nth(1).click()
await page.getByTestId('floor-corner-add').click()
await page.getByTestId('floor-corner').nth(2).scrollIntoViewIfNeeded()
const corner = await page.getByTestId('floor-corner').nth(2).boundingBox()
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2)
await page.mouse.down()
await page.mouse.move(corner.x - 120, corner.y + 10, { steps: 6 })
await page.mouse.up()
await page.getByTestId('floor-shape-mode').click()
await page.screenshot({ path: path.join(OUT, 'manager-floor-editor.png') })
await page.getByTestId('floor-save').click()
let saved = null
for (let i = 0; i < 30 && !(saved?.tables?.filter(x => x.plan_id != null).length >= 2); i++) { await sleep(250); saved = await api('GET', '/api/floor-plans', { token: boss }) }
const sp = saved.plans.find(x => x.name === 'E2E ground floor')
const placedNow = saved.tables.filter(x => x.plan_id === sp?.id)
const t1 = placedNow.find(x => x.id === firstId)
r.check(`${fl} drawn and saved: two tables (one round), the bar, a five-corner floor`, placedNow.length === 2 && placedNow.find(x => x.id === secondId)?.shape === 'round'
&& sp.items.some(i => i.kind === 'bar') && sp.outline?.length === 5, JSON.stringify({ placed: placedNow.map(x => [x.id, x.x, x.y, x.shape]), outline: sp?.outline }))
r.check(`${fl} the dragged table moved, on the grid`, t1 && t1.x > 600 && t1.x % 20 === 0, JSON.stringify(t1))
await page.goto(`${APP}/tables`)
await page.getByTestId('tables-view-map').click()
r.check(`${fl} the Tables page shows the plan live`, await page.locator('[data-testid="manager-floor"] [data-testid="floor-table"]').first().waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
&& await page.locator('[data-testid="manager-floor"] [data-testid="floor-table"]').count() >= 2)
await page.screenshot({ path: path.join(OUT, 'manager-floor-live.png') })
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
await page.goto(`${APP}/online-orders`)
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})
+1
View File
@@ -15,6 +15,7 @@ const suites = [
['unit: packages/api (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/api'], CS],
['unit: packages/access (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/access'], CS],
['unit: packages/signage (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/signage'], CS],
['unit: packages/floorplan (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/floorplan'], CS],
['unit: manager_dashboard (node --test)', 'npm', ['test', '--silent', '-w', 'manager-dashboard'], CS],
['lint: manager_dashboard (v2 code)', 'npm', ['run', 'lint', '--silent', '-w', 'manager-dashboard'], CS],
['unit: terminal (node --test)', 'npm', ['test', '--silent', '-w', 'terminal'], CS],
+20
View File
@@ -522,6 +522,26 @@ try {
return card?.dataset.state === 'open' && card.textContent.includes(due)
}, [phoneTable.id, (2 * simple.price).toFixed(2)], { timeout: 8000 }).then(() => true).catch(() => false))
await page.screenshot({ path: path.join(OUT, 'terminal-pos-tables.png') })
// ── 6.8: the floor plan at the counter, with live states ──────────────────
const third = counterTables.find(t => !t.order && mariaTables.has(t.id) && t.id !== shared.id && t.id !== phoneTable.id)
const fp = await api('POST', '/api/floor-plans', { token: boss, body: { name: 'E2E floor', width: 1000, height: 600, grid_on: true, grid_size: 50 } })
await api('PUT', `/api/floor-plans/${fp.id}/layout`, { token: boss, body: {
tables: [shared, phoneTable, third].map((t, i) => ({ id: t.id, x: 200 + i * 250, y: 300, width: 100, height: 100, shape: i === 1 ? 'round' : 'square', seats: 4 })),
items: [{ kind: 'bar', x: 500, y: 60, width: 400, height: 60 }] } })
await page.getByTestId('pos-tables-map').click()
const mapTable = id => page.locator(`[data-testid="pos-floor"] [data-testid="floor-table"][data-table="${id}"]`)
r.check("6.8: the counter shows the floor plan: the phone's table open, the others free", await mapTable(phoneTable.id).waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
&& await mapTable(phoneTable.id).getAttribute('data-state') === 'open' && await mapTable(shared.id).getAttribute('data-state') === 'free')
const thirdOrder = await api('POST', '/api/orders/', { token: maria, body: { table_id: third.id } })
await api('POST', `/api/orders/${thirdOrder.id}/items`, { token: maria, body: { lines: [{ product_id: simple.id, quantity: 1 }] } })
r.check("6.8: a table opened on the phone turns open on the counter's map at once", await page.waitForFunction(id =>
document.querySelector(`[data-testid="pos-floor"] [data-testid="floor-table"][data-table="${id}"]`)?.dataset.state === 'open', third.id, { timeout: 8000 }).then(() => true).catch(() => false))
await page.screenshot({ path: path.join(OUT, 'terminal-pos-floor.png') })
await mapTable(third.id).click()
r.check('6.8: a tap on the map opens the table', await shown(page, 'table-panel', 5000) && Number(await page.getByTestId('table-panel').getAttribute('data-order')) === thirdOrder.id)
await page.getByTestId('mode-tables').click()
await page.getByTestId('pos-tables-list').click().catch(() => {})
phoneWs.close()
// ── 3.3d: online orders on the POS ──────────────────────────────────────
+24
View File
@@ -358,6 +358,30 @@ try {
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: waiterRole.default_keys } })
await a.goto(`${APP}/tables`)
// ── 6.8: the floor plan on the phone; the list stays the default (D-31) ──
const liveNow = (await api('GET', '/api/floor-plans/live', { token: tokenA })).tables
const [fA, fB] = liveNow.filter(t => t.state === 'free')
const fp = await api('POST', '/api/floor-plans', { token: boss, body: { name: 'E2E floor', group_id: fA.group_id, width: 800, height: 500 } })
await api('PUT', `/api/floor-plans/${fp.id}/layout`, { token: boss, body: {
tables: [fA, fB].map((t, i) => ({ id: t.id, x: 200 + i * 300, y: 250, width: 120, height: 90, shape: 'long', seats: 6 })) } })
await a.getByTestId('tables-map-toggle').waitFor({ timeout: 10_000 })
r.check('6.8: the Tables page opens on the list', await a.getByTestId('tables-map-toggle').getAttribute('aria-pressed') === 'false' && await a.getByTestId('waiter-floor').count() === 0)
await a.getByTestId('tables-map-toggle').click()
const onMap = id => a.locator(`[data-testid="waiter-floor"] [data-testid="floor-table"][data-table="${id}"]`)
r.check('6.8: Map shows the floor plan with the tables free', await onMap(fA.id).waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
&& await onMap(fA.id).getAttribute('data-state') === 'free')
const oF = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: fA.id } })
await api('POST', `/api/orders/${oF.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
r.check('6.8: the waiter opens a table → it turns "yours" on the map at once', await a.waitForFunction(id =>
document.querySelector(`[data-testid="waiter-floor"] [data-testid="floor-table"][data-table="${id}"]`)?.dataset.state === 'mine', fA.id, { timeout: 8000 }).then(() => true).catch(() => false))
await a.screenshot({ path: path.join(OUT, 'waiter-floor.png') })
await onMap(fA.id).click()
r.check('6.8: a tap opens the table', await a.waitForURL(new RegExp(`/tables/${fA.id}$`), { timeout: 8000 }).then(() => true).catch(() => false))
await api('DELETE', `/api/orders/${oF.id}`, { token: boss }).catch(() => {})
await a.goto(`${APP}/tables`)
await a.getByTestId('tables-map-toggle').waitFor({ timeout: 10_000 })
r.check("6.8: back on Tables: the list again (the map isn't remembered)", await a.getByTestId('tables-map-toggle').getAttribute('aria-pressed') === 'false')
// ── 4.6: the look on the shared tokens: the venue's colour and light / dark reach the phone ──
const accentOf = () => a.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--x-accent-rgb').trim())
r.check('4.6: the venue colour (default amber) is on the phone', await a.evaluate(() => document.documentElement.dataset.venueTheme) === 'amber')