import assert from 'node:assert/strict'; import fs from 'node:fs'; import vm from 'node:vm'; const sourcePath = new URL('../src/Modules/GrapesJS/resources/assets/js/save-page.js', import.meta.url); const source = fs.readFileSync(sourcePath, 'utf8'); class TestElement { constructor() { this._innerHTML = ''; } set innerHTML(value) { this._innerHTML = value; } get innerHTML() { return this._innerHTML; } querySelectorAll() { const pattern = /
Source locale text
Source child text
', settings: {label: 'Source child setting'}}, newChild: {html: 'New shared block
', settings: {label: 'New setting'}}, }, }, newParent: {html: 'New shared parent
', settings: {label: 'New parent setting'}}, }; const targetBlocks = { parent: { html: 'Translated parent text
Existing translated child
', settings: {label: 'Translated child setting'}}, }, }, localeOnlyParent: {html: 'Existing locale-only content
'}, }; const synchronizedBlocks = window.synchronizePageBlockVariants(sourceBlocks, targetBlocks); assert.match(synchronizedBlocks.parent.html, /Translated parent text/); assert.match(synchronizedBlocks.parent.html, /id="new-child"/); assert.equal(synchronizedBlocks.parent.settings.label, 'Translated parent setting'); assert.equal(synchronizedBlocks.parent.blocks.existingChild.html, 'Existing translated child
'); assert.equal(synchronizedBlocks.parent.blocks.existingChild.settings.label, 'Translated child setting'); assert.equal(synchronizedBlocks.parent.blocks.newChild.html, 'New shared block
'); assert.equal(synchronizedBlocks.newParent.html, 'New shared parent
'); assert.equal(synchronizedBlocks.localeOnlyParent.html, 'Existing locale-only content
'); sourceBlocks.parent.blocks.newChild.html = 'Source changed after synchronization
'; assert.equal(synchronizedBlocks.parent.blocks.newChild.html, 'New shared block
'); console.log('PASS: shared block structure synchronizes without overwriting existing locale content.');