// 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') })