601451f22b
Overlay ~150 upstream items onto our V8.12 base, preserving trade-pro
theme, registry tests, and design docs. Re-applied our patch set
(discovery/env_for/blocks.css/type-mapping/theme_color/frontend entries,
test_theme_pro_v3 mods) — all anchors survived upstream evolution.
New platform enhancement (fixes upgrade-introduced regression):
multilingual.site_locale now honors settings_json.locale, plus
PUT /api/i18n/sites/{id}/locale — standalone English sites get
<html lang='en'> under the V8.15 locale-rewrite pipeline.
compose: adopt V8.21.3 (image 8.21.3-dev.1, /api/ready probes, MySQL/S3
env) with project name pinned to siteforge-v8-10 (data volumes).
Tests: 356 passed / 11 failed — all 11 confirmed pre-existing in
pristine V8.21.3 on this host (10 upstream Windows env + our build test
now green after locale fix). Patch registry updated in plan doc.
Co-Authored-By: Claude Code <noreply@anthropic.com>
45 lines
2.4 KiB
JavaScript
45 lines
2.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {reorder,duplicate,filterBlocks,historyState,clampNumber,shouldAcceptPreview}=require('../app/static/editor-helpers.js');
|
|
test('move item up and down without mutating input',()=>{
|
|
const source=[{id:'a'},{id:'b'},{id:'c'}];
|
|
assert.deepEqual(reorder(source,0,2).map(x=>x.id),['b','c','a']);
|
|
assert.deepEqual(reorder(source,2,0).map(x=>x.id),['c','a','b']);
|
|
assert.deepEqual(source.map(x=>x.id),['a','b','c']);
|
|
assert.equal(reorder(source,-1,1),null);
|
|
assert.equal(reorder(source,1,5),null);
|
|
assert.equal(reorder(source,1,1).length,3);
|
|
});
|
|
test('clone nested layout and recursively regenerate every component ID',()=>{
|
|
const nested={id:'original',type:'layout',columns:[{blocks:[{id:'nested',type:'richtext'}]},{blocks:[]}]};
|
|
let n=0;
|
|
const clone=duplicate(nested,()=>`copy-${++n}`);
|
|
assert.equal(clone.id,'copy-1');assert.equal(clone.columns[0].blocks[0].id,'copy-2');
|
|
clone.columns[0].blocks[0].type='hero';
|
|
assert.equal(nested.columns[0].blocks[0].type,'richtext');
|
|
});
|
|
test('find by title, type, translated name, nested layout child',()=>{
|
|
const list=[{type:'hero',title:'Global Trade'},{type:'layout',columns:[{blocks:[{type:'richtext',title:'移动端布局'}]}]},{type:'cta'}];
|
|
const spec={hero:{name:'横幅'},layout:{name:'多列'},cta:{name:'行动号召'}};
|
|
assert.deepEqual(filterBlocks(list,'gLoBaL',spec).map(x=>x.index),[0]);
|
|
assert.deepEqual(filterBlocks(list,'移动端',spec).map(x=>x.index),[1]);
|
|
assert.deepEqual(filterBlocks(list,'行动号召',spec).map(x=>x.index),[2]);
|
|
assert.equal(filterBlocks(list,'',spec).length,3);
|
|
assert.equal(filterBlocks(list,'不存在',spec).length,0);
|
|
});
|
|
test('undo redo disabled at correct boundaries',()=>{
|
|
assert.deepEqual(historyState(['s1'],0),{canUndo:false,canRedo:false});
|
|
assert.deepEqual(historyState(['s1','s2'],0),{canUndo:false,canRedo:true});
|
|
assert.deepEqual(historyState(['s1','s2'],1),{canUndo:true,canRedo:false});
|
|
});
|
|
test('preview accepts only latest request from current page',()=>{
|
|
assert.equal(shouldAcceptPreview('about',12,'about',12),true);
|
|
assert.equal(shouldAcceptPreview('about',11,'about',12),false);
|
|
assert.equal(shouldAcceptPreview('about',12,'home',12),false);
|
|
});
|
|
test('numeric style input is clamped',()=>{
|
|
assert.equal(clampNumber(180,0,120,10),120);
|
|
assert.equal(clampNumber(-5,0,120,10),0);
|
|
assert.equal(clampNumber('not-number',0,120,10),10);
|
|
});
|