Files
pulse-signage/test/player-time-date-region.test.js
T
lzstealth 222162df57
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile, web, pulse-signage-web) (push) Successful in 1m50s
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile.player, player, pulse-signage-player) (push) Successful in 33s
Fix player cached images and blank time dates
2026-09-13 23:56:08 +01:00

84 lines
2.4 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
function loadTimeDateModule() {
const webUiHelpersScript = fs.readFileSync(require.resolve('../src/web/public/js/web-ui-helpers.js'), 'utf8');
const renderingScript = fs.readFileSync(require.resolve('../src/player/public/js/player-page-rendering.js'), 'utf8');
const placeholderScript = fs.readFileSync(require.resolve('../src/web/public/js/shared/placeholder-utils.js'), 'utf8');
const timeDateScript = fs.readFileSync(require.resolve('../src/player/regions/time-date.js'), 'utf8');
const registry = new Map();
const sandbox = {
document: {
addEventListener() {}
},
window: {
pulsePlayerRegionTypes: {
register(type, module) {
registry.set(type, module);
}
},
innerWidth: 1280,
innerHeight: 720,
Intl: Intl,
Date: Date,
Object: Object,
Array: Array,
Number: Number,
String: String,
Boolean: Boolean,
Math: Math,
JSON: JSON,
RegExp: RegExp,
console: console
}
};
sandbox.window = Object.assign({}, sandbox.window);
vm.runInNewContext(webUiHelpersScript, sandbox, { filename: 'web-ui-helpers.js' });
sandbox.escapeHtml = sandbox.window.escapeHtml;
vm.runInNewContext(renderingScript, sandbox, { filename: 'player-page-rendering.js' });
vm.runInNewContext(placeholderScript, sandbox, { filename: 'placeholder-utils.js' });
vm.runInNewContext(timeDateScript, sandbox, { filename: 'time-date.js' });
return registry.get('time-date');
}
test('time/date region renders placeholder tokens on the player side', () => {
const module = loadTimeDateModule();
const markup = module.renderRegion(
{
pixelWidth: 320,
pixelHeight: 180,
canvasScale: 1,
baseStyle: 'position:absolute;'
},
{
value: '{{hh}}:{{mm}}',
timezone: 'UTC'
}
);
assert.match(markup, /<p>\d{2}:\d{2}<\/p>/);
});
test('time/date region stays blank when its format is blank', () => {
const module = loadTimeDateModule();
const markup = module.renderRegion(
{
pixelWidth: 320,
pixelHeight: 180,
canvasScale: 1,
baseStyle: 'position:absolute;'
},
{
value: '',
timezone: 'UTC'
}
);
assert.match(markup, /data-time-date-format=""/);
assert.doesNotMatch(markup, /<p>\d{2}:\d{2}<\/p>/);
});