const test = require('node:test');
const assert = require('node:assert/strict');
require('../src/common');
const {
mediaKind,
normalizeSlide,
renderEditorJsContent,
sanitizeRichText
} = require('../src/player/render-helpers');
test('mediaKind classifies player media by extension', () => {
assert.equal(mediaKind('poster.PNG'), 'image');
assert.equal(mediaKind('intro.mp4'), 'video');
assert.equal(mediaKind('manual.pdf'), 'pdf');
assert.equal(mediaKind('notes.txt'), 'file');
});
test('sanitizeRichText strips unsafe content but preserves allowed markup', () => {
const html = '
';
assert.equal(
sanitizeRichText(html),
''
);
});
test('normalizeSlide normalizes nested content without mutating the source', () => {
const slide = {
id: 12,
content: {
hero: {
value: '{"headline":"Hello"}',
font_family: ' Open Sans! ',
font_size: '42',
font_color: 'not-a-color',
type: 'text'
},
footer: 'plain text'
}
};
const normalized = normalizeSlide(slide);
assert.notEqual(normalized.content, slide.content);
assert.deepEqual(normalized.content.hero, {
value: { headline: 'Hello' },
font_family: ' Open Sans! ',
font_size: '42',
font_color: 'not-a-color',
type: 'text'
});
assert.deepEqual(normalized.content.footer, {
type: 'text',
value: 'plain text'
});
assert.deepEqual(slide.content.hero, {
value: '{"headline":"Hello"}',
font_family: ' Open Sans! ',
font_size: '42',
font_color: 'not-a-color',
type: 'text'
});
});
test('renderEditorJsContent sanitizes editor blocks and wraps legacy text', () => {
const editorJson = {
blocks: [
{ type: 'header', data: { level: 2, text: 'Title' } },
{ type: 'paragraph', data: { text: 'badok' } },
{ type: 'list', data: { style: 'ordered', items: ['One', { text: 'Two' }] } }
]
};
assert.equal(
renderEditorJsContent(editorJson),
'Title
badok
- One
- Two
'
);
assert.equal(renderEditorJsContent('plain text'), 'plain text
');
});