Files
cms-SiteForge/tests/test_nested_helpers_v823.cjs
T
浅念 8884e100f9 upgrade: adopt V8.31.1 (theme 1.3/1.4 redesigns, editor deep-canvas, guided launch, component library)
Overlay 190 upstream items (V8.22→8.31) preserving trade-pro theme,
registry tests, and design docs. Re-applied full patch set on identical
anchors (discovery/env_for/blocks.css/type-mapping/locale-override/
theme_color/frontend entries/test_theme_pro_v3 mods) plus compose pins.

Verified: theme suites 35/35; dual-baseline full run 415 passed vs
pristine 386+29 ours, FAILED-set diff EMPTY (same 10 Windows env fails).
Live: container 8.31.1-dev.1 healthy, hesupipe 192 entries intact,
trade-pro build 203 pages 0 errors.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-26 09:43:17 +08:00

23 lines
1.9 KiB
JavaScript

const assert=require('node:assert/strict');
const H=require('../app/static/editor-helpers.js');
const layout={id:'layout_0001',type:'layout',columns:[{width:1,blocks:[{id:'child_0001',type:'cta',title:'A'},{id:'child_0002',type:'cta',title:'B'}]},{width:1,blocks:[]}]};
const rows=[layout];const spec={cta:{fields:['title','subtitle','href']}};
assert.equal(H.findNestedChild(rows,'layout_0001','child_0002').child.title,'B');
assert.equal(H.findNestedChild(rows,'layout_0001','unknown'),null);
assert.equal(H.findNestedChild(rows,'unknown','child_0001'),null);
assert.equal(H.safeNestedCanvasCommand({action:'child-select',blockId:'layout_0001',childId:'child_0001'},rows,spec),true);
assert.equal(H.safeNestedCanvasCommand({action:'child-inline-text',blockId:'layout_0001',childId:'child_0001',field:'title',value:'New'},rows,spec),true);
assert.equal(H.safeNestedCanvasCommand({action:'child-inline-text',blockId:'layout_0001',childId:'child_0001',field:'body',value:'<script>'},rows,spec),false);
assert.equal(H.safeNestedCanvasCommand({action:'child-delete',blockId:'other',childId:'child_0001'},rows,spec),false);
assert.equal(H.safeNestedCanvasCommand({action:'child-execute',blockId:'layout_0001',childId:'child_0001'},rows,spec),false);
assert.equal(H.safeNestedCanvasCommand({action:'child-inline-text',blockId:'layout_0001',childId:'child_0001',field:'title',value:'x'.repeat(501)},rows,spec),false);
assert.deepEqual(H.layoutPreset(layout,'equal'),[1,1]);
assert.deepEqual(H.layoutPreset(layout,'left-wide'),[2,1]);
assert.deepEqual(H.layoutPreset(layout,'right-wide'),[1,2]);
assert.equal(H.layoutPreset(layout,'script'),null);
assert.deepEqual(H.moveNested(layout,0,1,-1).map(x=>x.id),['child_0002','child_0001']);
assert.equal(H.moveNested(layout,0,0,-1),null);
const cp=H.duplicate(layout.columns[0].blocks[0],()=> 'child_0003');assert.equal(cp.id,'child_0003');
assert.equal(layout.columns[0].blocks[0].id,'child_0001');
console.log('PASS: V8.23 nested helper checks');