Files
xenia-pos-local/manager_dashboard/tests/floor.test.mjs
T
bonaminandClaude Opus 5.5 244e93f827 feat(manager): the floor plan editor reworked; Management -> Tables on the page rule; area colours
- Floor editor: one toolbar over the map and the panels (grid on / off, grid resolution Ultra high
  ... Very low, edit the shape, Fit width / Whole plan, undo, save), panels top-aligned and sticky.
- The floor's shape: a '+' on the edge under the pointer, press to add a corner (and drag it);
  resting on a corner shows a bubble to remove it (never below 3).
- Areas: resize handles on the sides and corners, a colour (pastel, see-through; floor_items.color,
  migration 0041), the name repeated in the corner when tables cover it (live maps too).
- Labels can be clicked again after they're placed (transparent fill, not none).
- Management -> Tables: <Page> with the tabs above (?tab=), the list as a container, toolbar
  buttons one height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:17:45 +02:00

76 lines
4.4 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.
// 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, color: 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 })
})
test('the floor’s shape: a corner added where the edge was pressed; an area resized by its handles', async () => {
const { addCornerAt, nearestEdge, resizeBox, coveredAreas } = await import('@xenia/floorplan/geometry')
const square = [[0, 0], [100, 0], [100, 100], [0, 100]]
const e = nearestEdge(square, [50, 4])
assert.equal(e.index, 0)
assert.deepEqual(addCornerAt(square, e.index, e.x, e.y, { width: 100, height: 100 }), [[0, 0], [50, 0], [100, 0], [100, 100], [0, 100]])
const area = { x: 100, y: 100, width: 100, height: 60 }
assert.deepEqual(resizeBox(area, 'e', 220, 0, { width: 500, height: 500 }), { x: 135, y: 100, width: 170, height: 60 })
assert.deepEqual(resizeBox(area, 'nw', 40, 40, { width: 500, height: 500, grid_on: true, grid_size: 20 }), { x: 95, y: 85, width: 110, height: 90 })
const named = { key: 'a', kind: 'area', text: 'Terrace', x: 200, y: 200, width: 300, height: 200 }
assert.equal(coveredAreas([named], []).size, 0)
assert.equal(coveredAreas([named], [{ x: 200, y: 200, width: 80, height: 80 }]).has('a'), true)
})