Owner review 2026-11-23 of every widget: - A widget card is its main settings (the row and what needs room under it: pictures, a gallery's pictures or folder, weather details and place, a countdown's start and end, reviews' stars and author, a scrolling text's speed, a shape's colours and border, QR caption), then "Text and colours" (new LookFields.jsx: text colour, plate, font, style, size, weight, highlight, shadow, QR colours; a logo's / gallery's border), then More settings (opacity, rotation, animation, fit, typing, blink, QR logo; shadow / border only where there is no Text and colours). - Date format / separator and clock 12/24 / separator are main settings. - Alignment only where it lines something up; the TV now aligns the lines of a text, the hours (centre: days and times meet in the middle), contact rows, Wi-Fi (code left / right / above), the weather's column / card / list / hourly, reviews (stars too), a countdown, a QR caption. - Text and message: a 2-line textarea in its own row; Enter makes new lines (the TV sizes by the longest line and the number of lines). - Gallery: a title above or below the pictures (title_position). - A widget's box may reach 400 % of the slide (a logo zoomed in past the slide's edges saved again). - "Auto" stays "Auto" in Greek; scrolling text Left / Right; reviews' stars choice no longer clipped; countdown "When it ends" hint as an info tip (fields level). Calibration: an edge may go past the recognised window (down to -2000 px); the dialog's rows are centred, "Each click moves" sits above its choice, the window size is labelled "Recognised resolution" with what it means; the TV asks for its screen answer on every calibrate event and while calibrating (the outline shows the first time), the dialog sends "on" again after 1.5 s. NumberInput takes a leading minus when min < 0. E2E: waits for the Add-a-slide dialog to go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
9.7 KiB
JavaScript
135 lines
9.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, moreChanged, 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)
|
|
})
|
|
|
|
test("a widget's More settings: changed or as usual (6R.17)", () => {
|
|
assert.equal(moreChanged({ kind: 'clock' }), false)
|
|
assert.equal(moreChanged({ kind: 'clock', opacity: 100, shadow: 'none', animation: 'none', clock_separator: ':' }), false)
|
|
assert.equal(moreChanged({ kind: 'clock', clock_format: '12' }), false) // a main setting since 2026-11-23
|
|
assert.equal(moreChanged({ kind: 'clock', shadow: 'soft', weight: 300, highlight: '#ff0000' }), false) // under Text and colours
|
|
assert.equal(moreChanged({ kind: 'shape', shadow: 'soft' }), true) // a shape has no Text and colours
|
|
assert.equal(moreChanged({ kind: 'gallery', border_width: 4 }), false) // a picture's border: Text and colours
|
|
assert.equal(moreChanged({ kind: 'clock', border_width: 4 }), true)
|
|
assert.equal(moreChanged({ kind: 'date', rotation: -15 }), true)
|
|
assert.equal(moreChanged({ kind: 'qr', media_id: 4 }), true)
|
|
assert.equal(moreChanged({ kind: 'logo', media_id: 4 }), false)
|
|
})
|