refactor: @xenia/signage: the slides and the player's logic shared by the terminal and the manager (platform-v2 step 5.6a)
The signage slides (SlideView, TextSlide, MenuSlide, Widgets) and the pure logic (schedule pick, slide windows, menu pages) move from the terminal into packages/signage, so the manager's previews draw a slide exactly as the TV does. Sizes are container units (cqmin) instead of viewport units: a slide draws inside any box with container-type: size (frameStyle sets it on the TV). Tests move with it (10). Dockerfiles copy its package.json; both apps' Tailwind content include it; run-all runs its tests. Signage e2e and the compose stack passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
// The signage player's logic (plan step 5.5a): the same schedule cases as the server's
|
||||
// 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 { 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`)
|
||||
const [h, m] = hhmm.split(':').map(Number)
|
||||
return { weekday: (d.getUTCDay() + 6) % 7, minutes: h * 60 + m, date }
|
||||
}
|
||||
const MON_10 = at('2026-11-16', '10:00')
|
||||
const MON_13 = at('2026-11-16', '13:00')
|
||||
const SAT_13 = at('2026-11-21', '13:00')
|
||||
const SAT_23 = at('2026-11-21', '23:30')
|
||||
const SUN_01 = at('2026-11-22', '01:00')
|
||||
const MON_01 = at('2026-11-16', '01:00')
|
||||
|
||||
test('the venue clock in its own time zone', () => {
|
||||
const l = localNow('Europe/Athens', new Date('2026-11-16T22:30:00Z')) // 00:30 on Tuesday in Athens
|
||||
assert.deepEqual(l, { weekday: 1, minutes: 30, date: '2026-11-17' })
|
||||
})
|
||||
|
||||
test('which windows match (the server\'s cases)', () => {
|
||||
const lunch = { time_from: '12:00', time_to: '15:00' }
|
||||
assert.ok(matches(lunch, MON_13) && !matches(lunch, MON_10))
|
||||
const night = { days: [5], time_from: '22:00', time_to: '02:00' }
|
||||
assert.ok(matches(night, SAT_23) && matches(night, SUN_01) && !matches(night, MON_01))
|
||||
const xmas = { date_from: '2026-12-20', date_to: '2026-12-27' }
|
||||
assert.ok(matches(xmas, at('2026-12-24', '20:00')) && !matches(xmas, at('2026-12-28', '09:00')))
|
||||
assert.ok(matches({}, MON_10))
|
||||
assert.ok(matches({ time_from: '18:00' }, at('2026-11-16', '23:59')))
|
||||
})
|
||||
|
||||
test('the schedule\'s winner (the server\'s cases)', () => {
|
||||
const entries = [{ playlist_id: 10, time_from: '12:00', time_to: '15:00' }, { playlist_id: 20, days: [5, 6] },
|
||||
{ playlist_id: 30, days: [5, 6], time_from: '12:00', time_to: '15:00' },
|
||||
{ playlist_id: 40, date_from: '2026-11-21', date_to: '2026-11-21', priority: 5 }]
|
||||
assert.equal(pick(entries, 99, MON_10), 99)
|
||||
assert.equal(pick(entries, 99, MON_13), 10)
|
||||
assert.equal(pick(entries, 99, at('2026-11-22', '13:00')), 30)
|
||||
assert.equal(pick(entries, 99, SAT_13), 40)
|
||||
assert.equal(pick(entries, null, MON_10), null)
|
||||
})
|
||||
|
||||
test('the playlist now, alone or from a schedule', () => {
|
||||
assert.equal(playlistNow({ playlist: { id: 1 } }).id, 1)
|
||||
const data = { schedule: { timezone: 'Europe/Athens', entries: [{ playlist_id: 2, time_from: '12:00', time_to: '15:00' }], fallback_playlist_id: 3 },
|
||||
playlists: { 2: { id: 2 }, 3: { id: 3 } } }
|
||||
assert.equal(playlistNow(data, new Date('2026-11-16T11:00:00Z')).id, 2) // 13:00 in Athens
|
||||
assert.equal(playlistNow(data, new Date('2026-11-16T08:00:00Z')).id, 3)
|
||||
assert.equal(playlistNow(null), null)
|
||||
})
|
||||
|
||||
test('the next slide skips the ones outside their window, and wraps', () => {
|
||||
const slides = [{ id: 1 }, { id: 2, time_from: '12:00', time_to: '15:00' }, { id: 3, days: [0] }]
|
||||
assert.equal(nextSlide(slides, -1, MON_10), 0)
|
||||
assert.equal(nextSlide(slides, 0, MON_10), 2) // 2 is a lunch slide
|
||||
assert.equal(nextSlide(slides, 2, MON_10), 0)
|
||||
assert.equal(nextSlide(slides, 0, MON_13), 1)
|
||||
assert.equal(nextSlide([{ id: 1, days: [6] }], -1, MON_10), -1)
|
||||
assert.equal(nextSlide([], -1, MON_10), -1)
|
||||
})
|
||||
|
||||
test('how long a slide stays; the frame for a turned TV; what to keep on the device', () => {
|
||||
assert.equal(slideMs({ kind: 'text', duration_s: 8 }), 8000)
|
||||
assert.equal(slideMs({ kind: 'video', video_to_end: true, duration_s: 8 }), null)
|
||||
assert.equal(slideMs({ kind: 'image' }), 10000)
|
||||
assert.equal(frameStyle(90).width, '100vh')
|
||||
assert.equal(frameStyle(0).width, '100vw')
|
||||
assert.equal(frameStyle(180).transform, 'rotate(180deg)')
|
||||
const data = { schedule: {}, playlists: { 1: { media: { 5: { url: '/a' } } }, 2: { media: { 6: { url: '/b' }, 5: { url: '/a' } } } } }
|
||||
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')
|
||||
})
|
||||
Reference in New Issue
Block a user