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,61 @@
|
||||
// The floor plan editor's state (plan step 6.8): placing tables and things, moving, the body saved.
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { addItem, addable, freeSpot, layoutBody, layoutOf, nudge, placeTable, planBody, remove, resize, rotate, sameLayout, update } from '../src/pages/floor/editorLogic.js'
|
||||
|
||||
const plan = { id: 1, name: 'Ground', group_id: 10, width: 1000, height: 600, grid_on: true, grid_size: 50, outline: null, background: null, background_opacity: 0.6 }
|
||||
const data = {
|
||||
plans: [{ ...plan, items: [{ id: 7, kind: 'bar', x: 500, y: 50, width: 300, height: 50, rotation: 0, text: null }] }],
|
||||
tables: [
|
||||
{ id: 1, name: '1', group_id: 10, seats: 4, plan_id: 1, x: 100, y: 100, width: 100, height: 100, rotation: 0, shape: 'square' },
|
||||
{ id: 2, name: '2', group_id: 10, seats: 2, plan_id: null, x: null, y: null },
|
||||
{ id: 3, name: 'T1', group_id: 11, seats: 6, plan_id: null, x: null, y: null },
|
||||
],
|
||||
}
|
||||
|
||||
test('a plan\'s layout and the tables that can be added (its zone first)', () => {
|
||||
const l = layoutOf(data, 1)
|
||||
assert.deepEqual(l.tables.map(t => t.id), [1])
|
||||
assert.equal(l.items[0].key, 'i7')
|
||||
const { own, other } = addable(data, plan, l)
|
||||
assert.deepEqual([own.map(t => t.id), other.map(t => t.id)], [[2], [3]])
|
||||
})
|
||||
|
||||
test('placing a table: sized from its seats, on the grid, not on top of another', () => {
|
||||
let l = layoutOf(data, 1)
|
||||
l = placeTable(l, plan, data.tables[1], 'round')
|
||||
const t2 = l.tables.find(t => t.id === 2)
|
||||
assert.deepEqual([t2.width, t2.height, t2.shape, t2.x % 25, t2.y % 25], [50, 50, 'round', 0, 0]) // 2 seats: 70, one 50-cell
|
||||
l = placeTable(l, plan, data.tables[2], 'long')
|
||||
const t3 = l.tables.find(t => t.id === 3)
|
||||
assert.ok(Math.abs(t3.x - t2.x) >= 50 || Math.abs(t3.y - t2.y) >= 50, 'placed apart')
|
||||
const spot = freeSpot({ tables: [] }, plan, { width: 100, height: 100 })
|
||||
assert.deepEqual(spot, [500, 300])
|
||||
})
|
||||
|
||||
test('things, moving with the arrows, resizing, turning, removing', () => {
|
||||
let l = layoutOf(data, 1)
|
||||
const r = addItem(l, plan, 'wall')
|
||||
l = r.layout
|
||||
const wall = l.items.find(i => i.key === r.key)
|
||||
assert.deepEqual([wall.kind, wall.height], ['wall', 12]) // a wall keeps its thickness
|
||||
l = nudge(l, { type: 'table', id: 1 }, plan, 1, 0)
|
||||
assert.equal(l.tables[0].x, 150) // one grid cell
|
||||
l = nudge(l, { type: 'table', id: 1 }, { ...plan, grid_on: false }, 0, 1, true)
|
||||
assert.equal(l.tables[0].y, 101)
|
||||
assert.deepEqual(resize(l.tables[0], plan, 130, undefined), { width: 150, height: 100 })
|
||||
assert.equal(rotate(350, 15), 5)
|
||||
l = update(l, { type: 'item', id: r.key }, { text: 'x' })
|
||||
l = remove(l, { type: 'table', id: 1 })
|
||||
assert.equal(l.tables.length, 0)
|
||||
})
|
||||
|
||||
test('what is saved', () => {
|
||||
const l = layoutOf(data, 1)
|
||||
const body = layoutBody(l)
|
||||
assert.deepEqual(body.tables[0], { id: 1, x: 100, y: 100, width: 100, height: 100, rotation: 0, shape: 'square', seats: 4 })
|
||||
assert.deepEqual(body.items[0], { kind: 'bar', x: 500, y: 50, width: 300, height: 50, rotation: 0, text: null })
|
||||
assert.equal(sameLayout(l, layoutOf(data, 1)), true)
|
||||
assert.deepEqual(planBody({ ...plan, name: ' Up ', background: { id: 4 }, outline: [[0, 0], [5, 5]] }),
|
||||
{ name: 'Up', group_id: 10, width: 1000, height: 600, outline: null, grid_on: true, grid_size: 50, media_id: 4, background_opacity: 0.6 })
|
||||
})
|
||||
Reference in New Issue
Block a user