Files
xenia-pos-local/terminal/tests/display.test.mjs
T
bonaminandClaude Opus 5.5 88a9703902 feat(terminal): the customer display, with an idle screen each venue designs
Plan step 3.4. Owner (2026-11-16): the idle screen is configurable per venue.
- routers/customer_display.py (module customer_display, /api/display): the counter POS
  pushes its state (POST /api/display/state: idle | cart | paid with lines, total, paid,
  change); only the displays linked to that POS get `display.state`; the last state is kept
  in memory for a display that reconnects (GET /api/display/state). pos_counter's device
  scope includes customer_display.state.
- The idle screen: setting customer_display.idle (name, logo, logo + name, blank, one
  image, slideshow, QR code to the online ordering / QR menu / any link; a line of text;
  dark or light); images uploaded to /app/data/display_media (JPG/PNG/WebP/GIF ≤ 5 MB,
  random names, served publicly on the LAN); a change sends `display.settings` to every
  display. New key customer_display.manage (owners, store managers; migration 0022).
- Terminal: CustomerDisplayApp (cart with a large total, "Thank you" with the change for
  12 s, the venue's idle screen, its theme), logic.js (unit-tested); the POS pushes from the
  sale cart and the payment dialog (tables, online orders too) via useDisplay().
  qrcode.react added to the terminal (already in the workspace).
- Manager: Settings → Customer display (style cards, venue name, text, look, slide seconds,
  QR target/link/caption, image upload/pick/order/delete).
- Tests: tests/test_customer_display.py (3), terminal display.test.mjs (3); e2e terminal
  (linked vs unlinked display, < 1 s, paid, QR and slideshow idle screens), manager (the
  settings tab).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:34:05 +02:00

38 lines
2.2 KiB
JavaScript

// The customer display's logic (plan step 3.4).
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { idleParts, PAID_MS, slideAt, viewOf } from '../src/apps/customer-display/logic.js'
test('what the display shows: the cart, thank you (for a while), idle', () => {
const t0 = 1_000_000
assert.equal(viewOf(null, 0, t0), 'idle')
assert.equal(viewOf({ mode: 'cart', lines: [{}] }, t0, t0), 'cart')
assert.equal(viewOf({ mode: 'cart', lines: [] }, t0, t0), 'idle')
assert.equal(viewOf({ mode: 'paid' }, t0, t0 + 1000), 'paid')
assert.equal(viewOf({ mode: 'paid' }, t0, t0 + PAID_MS + 1), 'idle')
})
test('the idle screen the venue chose', () => {
const idle = { logo_url: '/l.png', image_url: '/i.png', slide_urls: ['/a.png', '/b.png'], qr_link: 'https://x/order/s', qr_caption: 'Order online', message: 'Hi' }
assert.deepEqual(idleParts({ ...idle, style: 'name' }, 'Taverna'), { name: 'Taverna', logo: null, image: null, slides: [], qr: null, caption: null, message: 'Hi', blank: false })
assert.equal(idleParts({ ...idle, style: 'logo' }, 'Taverna').name, null)
assert.equal(idleParts({ ...idle, style: 'logo', logo_url: null }, 'Taverna').name, 'Taverna', 'no logo yet: the name instead')
const both = idleParts({ ...idle, style: 'name_logo' }, 'Taverna')
assert.equal(both.name, 'Taverna'); assert.equal(both.logo, '/l.png')
assert.equal(idleParts({ ...idle, style: 'image' }, 'T').image, '/i.png')
assert.deepEqual(idleParts({ ...idle, style: 'slideshow' }, 'T').slides, ['/a.png', '/b.png'])
const qr = idleParts({ ...idle, style: 'qr' }, 'T')
assert.equal(qr.qr, 'https://x/order/s'); assert.equal(qr.caption, 'Order online')
const blank = idleParts({ ...idle, style: 'blank' }, 'T')
assert.equal(blank.blank, true); assert.equal(blank.message, null); assert.equal(blank.name, null)
assert.equal(idleParts({ style: 'nonsense' }, 'T').name, 'T')
})
test('the slideshow moves on every N seconds', () => {
assert.equal(slideAt(0, 8, 0), -1)
assert.equal(slideAt(3, 8, 0), 0)
assert.equal(slideAt(3, 8, 8000), 1)
assert.equal(slideAt(3, 8, 24_000), 0)
assert.equal(slideAt(2, 1, 3000), 1, 'at least 3 seconds a slide')
})