A slide is drawn at its playlist's shape, as large as fits the screen's picture, the bands in its own background (or stretched, the screen's choice). Playlists and library slides may have a shape of their own (aspect, Alembic 0045). Signage -> Screens -> Calibrate the picture: the TV outlines its area with arrows and its size, each edge moves pixel by pixel or a preset centres a shape; the TV follows live (signage.calibrate) and reports its window (POST /screen/viewport). Plan 6R.13, F-110. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
8.7 KiB
JavaScript
122 lines
8.7 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)
|
|
// custom shapes (6R.13): wide or tall by their ratio
|
|
assert.equal(fitsOrientation({ width: 2560, height: 1080 }, '21:9'), true)
|
|
assert.equal(fitsOrientation({ width: 1920, height: 1080 }, '10:16'), false)
|
|
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])
|
|
})
|
|
|
|
test('widgets moved and sized on the preview: boxes kept on the slide, snapping, custom and back (2026-11-21)', async () => {
|
|
const { boxFromRect, moveBox, placeWidget, presetWidget, resizeBox, snapBox } = await import('../src/pages/signage/signageLogic.js')
|
|
const frame = { left: 100, top: 50, width: 800, height: 450 }
|
|
assert.deepEqual(boxFromRect({ left: 500, top: 95, width: 160, height: 45 }, frame), { x: 50, y: 10, w: 20, h: 10 })
|
|
const b = { x: 50, y: 10, w: 20, h: 10 }
|
|
assert.deepEqual(moveBox(b, 40, -20), { x: 80, y: 0, w: 20, h: 10 }) // stopped at the edges
|
|
assert.deepEqual(resizeBox(b, 'se', 5, 5), { x: 50, y: 10, w: 25, h: 15 })
|
|
assert.deepEqual(resizeBox(b, 'nw', 30, 30), { x: 67, y: 17, w: 3, h: 3 }) // never smaller than 3 %
|
|
assert.deepEqual(resizeBox(b, 'e', 90, 0), { x: 50, y: 10, w: 50, h: 10 })
|
|
const s = snapBox({ x: 40.5, y: 0.8, w: 20, h: 10 }) // its middle near 50, its top near 0
|
|
assert.deepEqual(s.box, { x: 40, y: 0, w: 20, h: 10 })
|
|
assert.deepEqual(s.guides, ['x:50', 'y:0'])
|
|
assert.deepEqual(snapBox({ x: 10, y: 10, w: 89.5, h: 10 }, 'e').box, { x: 10, y: 10, w: 90, h: 10 }) // a handle moves only its edge
|
|
const w = placeWidget({ kind: 'clock', position: 'top-right', size: 'large' }, b)
|
|
assert.deepEqual(w, { kind: 'clock', position: 'custom', size: 'custom', box: b })
|
|
assert.deepEqual(presetWidget(w, 'bottom-left'), { kind: 'clock', position: 'bottom-left', size: 'medium' })
|
|
assert.deepEqual(presetWidget({ kind: 'clock', position: 'top-right', size: 'large' }, 'top-left').size, 'large')
|
|
})
|
|
|
|
test('a schedule line runs on weekdays or on smart days, not both (2026-11-21)', async () => {
|
|
const { setDayShortcut, shortcutOf, toggleMonthDay, toggleWeekday } = await import('../src/pages/signage/signageLogic.js')
|
|
const line = { days: [0, 1], month_days: [] }
|
|
assert.deepEqual(toggleMonthDay(line, 'holiday'), { month_days: ['holiday'], days: [] })
|
|
assert.deepEqual(toggleWeekday({ days: [], month_days: ['first'] }, 3), { days: [3], month_days: [] })
|
|
assert.deepEqual(setDayShortcut('weekend'), { days: [5, 6], month_days: [] })
|
|
assert.equal(shortcutOf({ days: [], month_days: [] }), 'everyday')
|
|
assert.equal(shortcutOf({ days: [], month_days: ['last'] }), null) // a smart day: "every day" isn't lit
|
|
assert.equal(shortcutOf({ days: [0, 1, 2, 3, 4], month_days: [] }), 'weekdays')
|
|
})
|
|
|
|
test('the Slides library: what is saved, and a copy for a playlist', async () => {
|
|
const { savedBody, slideFromSaved } = await import('../src/pages/signage/signageLogic.js')
|
|
const saved = { id: 4, name: ' Logo ', description: ' ', orientation: 'portrait', kind: 'blank', duration_s: 12, enabled: true, days: [], content: { widgets: [{ kind: 'name' }] } }
|
|
const body = savedBody(saved)
|
|
assert.equal(body.name, 'Logo')
|
|
assert.equal(body.description, null)
|
|
assert.equal(body.orientation, 'portrait')
|
|
const copy = slideFromSaved(saved)
|
|
assert.equal(copy.kind, 'blank')
|
|
assert.equal(copy.duration_s, 12)
|
|
copy.content.widgets[0].kind = 'clock'
|
|
assert.equal(saved.content.widgets[0].kind, 'name') // a copy, never the kept slide
|
|
})
|
|
|
|
|
|
test('owner review 6: a box off the slide (a strip stays), a tight box scaled keeping its shape', async () => {
|
|
const { moveLoose, scaleBox, secondsMissing } = await import('../src/pages/signage/signageLogic.js')
|
|
assert.deepEqual(moveLoose({ x: 50, y: 10, w: 20, h: 10 }, 60, -30), { x: 95, y: -5, w: 20, h: 10 })
|
|
assert.deepEqual(moveLoose({ x: 50, y: 10, w: 20, h: 10 }, -100, 0), { x: -15, y: 10, w: 20, h: 10 })
|
|
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'se', 20, 0), { x: 10, y: 10, w: 40, h: 20 }) // twice as wide → twice as tall
|
|
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'n', 0, -10), { x: 0, y: 0, w: 40, h: 20 }) // the bottom stays, centred across
|
|
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'nw', 10, 2), { x: 14, y: 12, w: 16, h: 8 }) // a corner: the larger of the two (0.5, 0.8)
|
|
assert.equal(secondsMissing({ kind: 'menu', duration_s: 10, content: { page_seconds: null } }), true)
|
|
assert.equal(secondsMissing({ kind: 'text', duration_s: null, content: {} }), true)
|
|
assert.equal(secondsMissing({ kind: 'video', video_to_end: true, duration_s: null, content: {} }), false)
|
|
assert.equal(secondsMissing({ kind: 'blank', duration_s: 5, content: { widgets: [{ kind: 'stack', cells: [{ widgets: [{ kind: 'menu', board: { page_seconds: null } }] }] }] } }), true)
|
|
assert.equal(secondsMissing({ kind: 'menu', duration_s: 5, content: { page_seconds: 3 } }), false)
|
|
})
|