Files
xenia-pos-local/manager_dashboard/tests/floor.test.mjs
T
bonaminandClaude Opus 5.5 301502965c feat(manager): UI review pass 3 (fees tabs, products panes, floor editor, permissions search, pricing heads)
- Online orders → Settings: the fee tabs breathe (inset strip); a rule's buttons
  and switch centred together.
- Products: categories and list as panes that scroll on their own, headers and
  footers stay; the list sunken with white rows; the category search is the
  shared SearchInput. Product editor: "Make main" text instead of a star, the
  left tabs share the width.
- Floor editor: no "+" next to a corner; − / fit width / whole plan / +;
  "Edit the floor's shape" → "Save shape" (saves the shape and size at once);
  sizes in grid cells by half cells (steppers; typing snapped every keystroke
  before), resize handles on every unrotated table and thing, half-cell snapping.
- MediaField: the picture's name under the buttons, Remove red on hover.
- Staff permissions: a search box at the top.
- Prep zone name hint fixed. Offers & pricing: title first, then tabs; every tab
  has its head with the New button at the top right.
- Tests: floor cells, e2e (cell steppers, no + near a corner, Save shape,
  permission search, products panes).

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

93 lines
5.3 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)
})
test('sizes in grid cells (by half cells) follow the grid resolution', async () => {
const { cellOf, resizeCells, toCells } = await import('../src/pages/floor/editorLogic.js')
assert.equal(cellOf(plan), 50)
assert.equal(toCells(100, plan), 2)
assert.equal(toCells(70, plan), 1.5)
assert.equal(toCells(5, plan), 0.5)
const table = { x: 100, y: 100, width: 100, height: 100 }
const r = resizeCells(table, plan, 3, null)
assert.equal(r.width, 150)
assert.equal(r.height, 100)
assert.equal(r.x % 50, 25) // 3 cells: the centre goes into the middle of a cell
assert.equal(resizeCells(table, { ...plan, grid_size: 25 }, 3, 1.5).height, 37.5)
// a resize handle snaps to half cells
const { resizeBox } = await import('@xenia/floorplan/geometry')
assert.equal(resizeBox({ x: 100, y: 100, width: 100, height: 100 }, 'e', 172, 0, { width: 500, height: 500, grid_on: true, grid_size: 50 }).width, 125)
})