- Menu board: everything or chosen whole categories (sub-categories included, new products join) plus single products found by search; hide a product from the board (and show it again); the board's own order with arrows on what the server resolved (categories and products; boardOrder writes it); a badge per product; grouping, headings, photos, descriptions, whose prices (a sales point or none), sold out crossed out or hidden, columns, products per page (or as many as fit), seconds per page; colours, font, size, background. - Widgets (text and menu slides): logo, venue name, date (long / short), clock (seconds), message of the day (or its own text), QR code (ordering / QR menu / a link + caption), weather (1-3 days, says it needs internet); where (corners, bars) and size. - The preview stays in view while the settings scroll. - @xenia/signage: the venue clock's Intl call names its time zone where the i18n guard reads it. - tests: manager signage.test.mjs +1; e2e signage.mjs builds a menu board in the editor (categories, a single product, the order, a badge, hiding, a clock) and checks what was saved and resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
3.9 KiB
JavaScript
60 lines
3.9 KiB
JavaScript
// The signage editor's helpers (plan step 5.6a).
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { fitsOrientation, mediaEntry, misfits, moved, slideBody, slideFromTemplate, TEMPLATES, totalSeconds, windowParts } from '../src/pages/signage/signageLogic.js'
|
|
|
|
test('templates fill their texts in the manager\'s language and copy their content', () => {
|
|
const tpl = TEMPLATES.find(x => x.key === 'happyHour')
|
|
const a = slideFromTemplate(tpl, k => `T(${k})`)
|
|
assert.equal(a.kind, 'text')
|
|
assert.equal(a.content.title, 'T(signage.templates.happyHour.title)')
|
|
assert.equal(a.time_from, '17:00')
|
|
a.content.background.colour = '#000000'
|
|
assert.notEqual(tpl.content.background.colour, '#000000') // a copy, never the template itself
|
|
assert.ok(TEMPLATES.every(x => ['image', 'video', 'text', 'menu'].includes(x.kind)))
|
|
})
|
|
|
|
test('does a picture fit the playlist\'s shape', () => {
|
|
assert.equal(fitsOrientation({ width: 1920, height: 1080 }, 'landscape'), true)
|
|
assert.equal(fitsOrientation({ width: 1080, height: 1920 }, 'landscape'), false)
|
|
assert.equal(fitsOrientation({ width: 1080, height: 1920 }, 'portrait'), true)
|
|
assert.equal(fitsOrientation({ width: 800, height: 800 }, 'portrait'), true)
|
|
assert.equal(fitsOrientation({}, 'portrait'), null)
|
|
const media = { 1: { width: 1080, height: 1920 }, 2: { width: 1920, height: 1080 } }
|
|
const slides = [{ id: 10, content: { media_id: 1 } }, { id: 11, content: { media_id: 2 } },
|
|
{ id: 12, content: { background: { kind: 'media', media_id: 1 } } }, { id: 13, content: { background: { kind: 'colour', media_id: 1 } } }]
|
|
assert.deepEqual(misfits(slides, media, 'landscape'), { 10: [1], 12: [1] })
|
|
})
|
|
|
|
test('the timeline: when a slide shows, the round\'s time, moving', () => {
|
|
assert.deepEqual(windowParts({}), [])
|
|
assert.deepEqual(windowParts({ days: [0, 1, 2, 3, 4, 5, 6] }), [])
|
|
assert.deepEqual(windowParts({ days: [5, 6], time_from: '12:00' }).map(p => p.key), ['days', 'hours'])
|
|
assert.equal(windowParts({ date_to: '2026-12-31' })[0].params.from, '…')
|
|
const media = { 7: { duration_ms: 12_400 } }
|
|
assert.equal(totalSeconds([{ enabled: true, duration_s: 8 }, { enabled: false, duration_s: 50 },
|
|
{ enabled: true, kind: 'video', video_to_end: true, content: { media_id: 7 } }], media), 20)
|
|
assert.deepEqual(moved([1, 2, 3, 4], 3, 0), [4, 1, 2, 3])
|
|
assert.deepEqual(moved([1, 2, 3], 0, 9), [1, 2, 3])
|
|
})
|
|
|
|
test('what is sent back, and library items as the slides need them', () => {
|
|
const b = slideBody({ id: 1, kind: 'text', name: '', duration_s: 9, enabled: 1, days: undefined, content: { title: 'x' }, menu: {} })
|
|
assert.deepEqual(b, { name: null, duration_s: 9, transition: null, video_to_end: false, enabled: true, days: [], time_from: null, time_to: null,
|
|
date_from: null, date_to: null, content: { title: 'x' } })
|
|
assert.deepEqual(mediaEntry({ id: 3, kind: 'video', name: 'v', width: 1, height: 2, duration_ms: 5, urls: { original: '/o' } }).url, '/o')
|
|
assert.equal(mediaEntry({ id: 3, kind: 'image', urls: { full: '/f', original: '/o', thumb: '/t' } }).url, '/f')
|
|
})
|
|
|
|
test('the board\'s own order from what it shows; moving categories and products; toggling ids', async () => {
|
|
const { boardOrder, moveGroup, moveItem, toggled } = await import('../src/pages/signage/signageLogic.js')
|
|
const groups = [{ category: { id: 1 }, items: [{ id: 10 }, { id: 11 }] }, { category: { id: 2 }, items: [{ id: 20 }] }]
|
|
assert.deepEqual(boardOrder(groups), { category_order: [1, 2], product_order: [10, 11, 20] })
|
|
assert.deepEqual(boardOrder(moveGroup(groups, 1, -1)), { category_order: [2, 1], product_order: [20, 10, 11] })
|
|
assert.deepEqual(boardOrder(moveItem(groups, 0, 1, -1)).product_order, [11, 10, 20])
|
|
assert.deepEqual(boardOrder([{ category: null, items: [{ id: 5 }] }]), { category_order: [], product_order: [5] })
|
|
assert.deepEqual(toggled([3, 1], 2), [1, 2, 3])
|
|
assert.deepEqual(toggled([1, 2], 2), [1])
|
|
assert.deepEqual(toggled(undefined, 4), [4])
|
|
})
|