Consolidate slide preview content resolution
This commit is contained in:
1 parent
726a7fedc7
commit
e9a53f577c
11 files changed
+77
-240
No files matched your search
@@ -6,6 +6,8 @@ const vm = require('node:vm');
|
||||
const { render } = require('../src/web/public/js/shared/slide-preview-renderer');
|
||||
const { buildThumbnailPreviewPayload } = require('../src/web/lib/media/slide-thumbnails');
|
||||
const placeholderUtils = require('../src/web/public/js/shared/placeholder-utils');
|
||||
const { resolveRegionContent } = require('../src/web/public/js/shared/region-content');
|
||||
const { getRegionEditorScripts } = require('../src/web/lib/region-scripts');
|
||||
|
||||
function loadEditorTimeDateModule() {
|
||||
const source = fs.readFileSync(require.resolve('../src/web/public/js/regions/type/time-date.js'), 'utf8');
|
||||
@@ -49,6 +51,49 @@ test('thumbnail payload passes saved region geometry and content to the popup re
|
||||
assert.equal(payload.existingContent.clock.timezone, 'Europe/London');
|
||||
});
|
||||
|
||||
test('thumbnail popup respects template defaults, read-only regions and explicit slide content', () => {
|
||||
const payload = buildThumbnailPreviewPayload({
|
||||
template: {
|
||||
canvas_size_width: 1280,
|
||||
canvas_size_height: 720,
|
||||
regions: [
|
||||
{ region_key: 'logo', region_type: 'image', read_only: 1, default_content: { value: '/media/uploads/template-logo.png' }, x: 0, y: 0, width: 200, height: 100 },
|
||||
{ region_key: 'heading', region_type: 'text', default_content: JSON.stringify({ value: 'Template heading' }), x: 0, y: 100, width: 400, height: 100 },
|
||||
{ region_key: 'custom', region_type: 'text', default_content: { value: 'Default custom' }, x: 0, y: 200, width: 400, height: 100 },
|
||||
{ region_key: 'blank', region_type: 'text', default_content: { value: 'Do not restore' }, x: 0, y: 300, width: 400, height: 100 }
|
||||
]
|
||||
},
|
||||
content: {
|
||||
logo: { value: '/media/uploads/stale-logo.png' },
|
||||
custom: { value: 'Slide heading' },
|
||||
blank: { value: '' }
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(payload.regions[0].content.value, '/media/uploads/template-logo.png');
|
||||
assert.equal(payload.regions[0].content.type, 'image');
|
||||
assert.equal(payload.regions[1].content.value, 'Template heading');
|
||||
assert.equal(payload.regions[2].content.value, 'Slide heading');
|
||||
assert.equal(payload.regions[3].content.value, '');
|
||||
assert.equal(payload.existingContent.logo.value, '/media/uploads/template-logo.png');
|
||||
assert.equal(payload.existingContent.heading.value, 'Template heading');
|
||||
assert.match(payload.html, /template-logo\.png/);
|
||||
assert.match(payload.html, /Template heading/);
|
||||
assert.match(payload.html, /Slide heading/);
|
||||
assert.doesNotMatch(payload.html, /stale-logo|Default custom|Do not restore/);
|
||||
});
|
||||
|
||||
test('editor and popup load the same browser-compatible content resolver', () => {
|
||||
const sandbox = { window: {} };
|
||||
vm.runInNewContext(fs.readFileSync(require.resolve('../src/web/public/js/shared/region-content'), 'utf8'), sandbox);
|
||||
const region = { region_key: 'brand', region_type: 'text', read_only: true, default_content: { value: 'Shared brand' } };
|
||||
const saved = { brand: { value: 'Stale brand' } };
|
||||
assert.equal(JSON.stringify(sandbox.window.pulseRegionContent.resolveRegionContent(region, saved)), JSON.stringify(resolveRegionContent(region, saved)));
|
||||
assert.ok(getRegionEditorScripts().includes('js/shared/region-content.js'));
|
||||
const editorSource = fs.readFileSync(require.resolve('../src/web/public/js/slides/slide-form.js'), 'utf8');
|
||||
assert.match(editorSource, /window\.pulseRegionContent\.resolveRegionContent\(region, existingContent\)/);
|
||||
});
|
||||
|
||||
test('thumbnail regions use shared region renderers and their source context', () => {
|
||||
const calls = [];
|
||||
const registry = {
|
||||
|
||||
Reference in new issue
Block a user