84 lines
2.4 KiB
JavaScript
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>/);
|
|
}); |