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:
@@ -0,0 +1,65 @@
|
||||
// The table map's geometry (plan step 6.8): the grid, outlines, chairs, what a table shows.
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
addCorner, chairs, defaultSize, durationText, minutesSince, moveCorner, moveTo, outlineOf, peopleText, plansFor, removeCorner,
|
||||
snap, snapCentre, snapSize, splitTables, toneOf,
|
||||
} from '../src/geometry.js'
|
||||
|
||||
const plan = { width: 1000, height: 600, grid_on: true, grid_size: 50 }
|
||||
|
||||
test('the grid snaps positions and sizes; off, they stay as they are', () => {
|
||||
assert.equal(snap(73, 50), 50)
|
||||
assert.equal(snap(73.27, 0), 73.3)
|
||||
assert.equal(snapSize(20, 50), 50) // at least one cell
|
||||
assert.equal(snapSize(130, 50), 150)
|
||||
assert.equal(snapCentre(130, 50, 50), 125) // one cell: the centre of a cell
|
||||
assert.equal(snapCentre(130, 100, 50), 150) // two cells: on a line
|
||||
assert.deepEqual(moveTo({ width: 50, height: 50 }, 1210, -20, plan), { width: 50, height: 50, x: 1000, y: 0 })
|
||||
assert.deepEqual(moveTo({ width: 50, height: 50 }, 312.4, 99, { ...plan, grid_on: false }), { width: 50, height: 50, x: 312.4, y: 99 })
|
||||
})
|
||||
|
||||
test('new tables get a size from their shape and seats', () => {
|
||||
assert.deepEqual(defaultSize('round', 2), { width: 70, height: 70 })
|
||||
assert.deepEqual(defaultSize('long', 8), { width: 240, height: 80 })
|
||||
assert.deepEqual(defaultSize('square', 4, 50), { width: 100, height: 100 })
|
||||
})
|
||||
|
||||
test('irregular floors: corners added, moved, removed (never fewer than 3)', () => {
|
||||
const rect = outlineOf(plan)
|
||||
assert.equal(rect.length, 4)
|
||||
const five = addCorner(rect, 1) // the middle of the right side
|
||||
assert.deepEqual(five[2], [1000, 300])
|
||||
const moved = moveCorner(five, 2, 640, 333, plan)
|
||||
assert.deepEqual(moved[2], [650, 350])
|
||||
assert.equal(removeCorner(removeCorner(moved, 0), 0).length, 3)
|
||||
assert.equal(removeCorner([[0, 0], [1, 0], [0, 1]], 0).length, 3)
|
||||
assert.deepEqual(outlineOf({ ...plan, outline: moved }), moved)
|
||||
})
|
||||
|
||||
test('chairs go around round tables and along the long sides', () => {
|
||||
const r = chairs('round', 80, 80, 4)
|
||||
assert.deepEqual(r[0], [0, -50])
|
||||
assert.equal(r.length, 4)
|
||||
const l = chairs('long', 200, 80, 6)
|
||||
assert.equal(l.filter(([, y]) => y < 0).length, 3)
|
||||
assert.equal(l.filter(([, y]) => y > 0).length, 3)
|
||||
assert.deepEqual(chairs('square', 80, 80, 0), [])
|
||||
})
|
||||
|
||||
test('what a table shows', () => {
|
||||
assert.equal(toneOf({ state: 'open', mine: true }), 'mine')
|
||||
assert.equal(toneOf({ state: 'paid', mine: true }), 'paid')
|
||||
assert.equal(durationText(42), '42′')
|
||||
assert.equal(durationText(65), '1:05')
|
||||
assert.equal(peopleText(['Maria', 'Nikos']), 'Maria +1')
|
||||
assert.equal(minutesSince('2026-11-18T10:00:00Z', Date.parse('2026-11-18T10:42:30Z')), 42)
|
||||
})
|
||||
|
||||
test('plans of a zone, and the tables not on a plan', () => {
|
||||
const plans = [{ id: 1, group_id: 1 }, { id: 2, group_id: 2 }, { id: 3, group_id: null }]
|
||||
assert.deepEqual(plansFor(plans, 2).map(p => p.id), [2, 3])
|
||||
const tables = [{ id: 1, plan_id: 1, x: 5, group_id: 1 }, { id: 2, plan_id: null, group_id: 1 }, { id: 3, plan_id: null, group_id: 2 }]
|
||||
const s = splitTables(tables, 1, 1)
|
||||
assert.deepEqual([s.placed.map(t => t.id), s.unplaced.map(t => t.id)], [[1], [2]])
|
||||
})
|
||||
Reference in New Issue
Block a user