feat(terminal): signage menu boards that page by themselves, and the widgets (platform-v2 step 5.5b)

- Menu board: the board's own order, grouped with headings or one list,
  photos, descriptions, badges (translated), sold out crossed out with a
  label, prices in the venue's money format, dotted leaders, a page dot row.
  Pages: rows that fit from the frame's shape (portrait fits more), text size,
  photos / descriptions, the title and widget bars (`page_size` overrides);
  they go round every `page_seconds` while the slide lasts.
- Widgets on text and menu slides: logo, name, date, clock, message of the
  day, QR code, weather (hidden without a forecast) in corners and bars, three
  sizes.
- logic.js: menuPages, rowsPerColumn, frameHeightVmin, boardPages, menuMs,
  pageAt, weatherIcon (+4 tests).
- e2e signage.mjs: a long board pages by itself, widgets in place, weather
  hidden with no place, the chosen product first with its badge, a price change
  and sold out show within seconds, a portrait TV needs fewer pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:00:14 +02:00
co-authored by Claude Opus 5.5
parent e612e2436c
commit e90c2f4f8f
8 changed files with 375 additions and 40 deletions
+45 -1
View File
@@ -2,7 +2,7 @@
// local_backend/tests/test_signage_schedule.py, slide windows, the next slide, the frame.
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { frameStyle, localNow, matches, mediaUrls, nextSlide, pick, playlistNow, slideMs } from '../src/apps/signage/logic.js'
import { boardPages, frameHeightVmin, frameStyle, localNow, matches, mediaUrls, menuMs, menuPages, nextSlide, pageAt, pick, playlistNow, rowsPerColumn, slideMs, weatherIcon } from '../src/apps/signage/logic.js'
const at = (date, hhmm) => {
const d = new Date(`${date}T12:00:00Z`)
@@ -73,3 +73,47 @@ test('how long a slide stays; the frame for a turned TV; what to keep on the dev
assert.deepEqual(mediaUrls(data).sort(), ['/a', '/b'])
assert.deepEqual(mediaUrls({ playlist: null }), [])
})
test('a menu board in pages: headings count, a cut group repeats its heading', () => {
const g = [{ category: { id: 1, name: 'A' }, items: [1, 2, 3, 4, 5, 6, 7].map(id => ({ id })) }, { category: { id: 2, name: 'B' }, items: [{ id: 9 }] }]
const pages = menuPages(g, 4)
assert.deepEqual(pages.map(p => p.map(x => [x.category.name, x.items.length])), [[['A', 3]], [['A', 3]], [['A', 1], ['B', 1]]])
assert.deepEqual(menuPages(g, 4, false).map(p => p.reduce((n, x) => n + x.items.length, 0)), [4, 4])
assert.deepEqual(menuPages([], 4), [])
assert.equal(menuPages([{ category: null, items: [{ id: 1 }] }], 10).length, 1)
})
test('rows that fit: taller screens and smaller text fit more, photos fewer', () => {
assert.equal(frameHeightVmin(0, 1920, 1080), 100)
assert.ok(Math.abs(frameHeightVmin(0, 1080, 1920) - 177.8) < 0.1)
assert.ok(Math.abs(frameHeightVmin(90, 1920, 1080) - 177.8) < 0.1) // a wide TV turned: a tall frame
const base = rowsPerColumn({ heightVmin: 100 })
assert.ok(rowsPerColumn({ heightVmin: 178 }) > base && rowsPerColumn({ heightVmin: 100, textSize: 70 }) > base)
assert.ok(rowsPerColumn({ heightVmin: 100, photos: true }) < base && rowsPerColumn({ heightVmin: 100, bars: 2 }) < base)
assert.ok(rowsPerColumn({ heightVmin: 10 }) >= 3)
const slide = { kind: 'menu', content: { columns: 1, page_size: 5 }, menu: { groups: [{ category: null, items: Array.from({ length: 12 }, (_, i) => ({ id: i })) }] } }
assert.equal(boardPages(slide, 0, 1920, 1080).length, 3)
})
test('a menu slide stays for all its pages; the page on screen', () => {
const slide = { kind: 'menu', duration_s: 10, content: { page_seconds: 8 } }
assert.equal(menuMs(slide, 1), 10_000)
assert.equal(menuMs(slide, 3), 24_000)
assert.equal(pageAt(3, 8, 0), 0)
assert.equal(pageAt(3, 8, 8_100), 1)
assert.equal(pageAt(3, 8, 16_500), 2)
assert.equal(pageAt(3, 8, 24_100), 0) // round again on a long slide
assert.equal(pageAt(1, 8, 99_000), 0)
assert.equal(pageAt(3, 8, -400), 0)
})
test('weather codes → icons', () => {
assert.equal(weatherIcon(0, true), 'sun')
assert.equal(weatherIcon(0, false), 'moon')
assert.equal(weatherIcon(2), 'cloud-sun')
assert.equal(weatherIcon(61), 'rain')
assert.equal(weatherIcon(73), 'snow')
assert.equal(weatherIcon(95), 'storm')
assert.equal(weatherIcon(45), 'fog')
assert.equal(weatherIcon(null), 'cloud')
})