9ea3b3cfe6
- 添加页面树同步逻辑,确保 `Page` 节点与 UI 树一致。 - 实现节点的新增、删除、移动和元数据更新功能。 - 扩展节点 Inspector,支持查看和修改选中节点的名称、描述和变换属性。 - 重构相关测试,覆盖新的页面树和节点操作功能。 - 引入嵌套节点坐标计算逻辑,确保节点相对位置一致性。
94 lines
2.4 KiB
TypeScript
94 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { applyUiDesignSuggestions } from '../src/features/ui-editor/uiDesignSuggestions';
|
|
import type { State } from '../src/features/ui-editor/types/State';
|
|
|
|
function state(): State {
|
|
return {
|
|
ui_trees: [],
|
|
sprite_assets: {},
|
|
font_assets: {},
|
|
ui_design_images: {
|
|
page: {
|
|
metadata: { name: '', description: '', role: null, slave_to: null },
|
|
path: 'page.png',
|
|
pixel_size: [100, 100],
|
|
pixels_per_unit: 1,
|
|
},
|
|
section: {
|
|
metadata: {
|
|
name: '已有名称',
|
|
description: '',
|
|
role: 'Section',
|
|
slave_to: null,
|
|
},
|
|
path: 'section.png',
|
|
pixel_size: [100, 100],
|
|
pixels_per_unit: 1,
|
|
},
|
|
detail: {
|
|
metadata: {
|
|
name: '',
|
|
description: '已有描述',
|
|
role: null,
|
|
slave_to: null,
|
|
},
|
|
path: 'detail.png',
|
|
pixel_size: [100, 100],
|
|
pixels_per_unit: 1,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
describe('applyUiDesignSuggestions', () => {
|
|
it('masks existing metadata and maps descendants to their owning Page', () => {
|
|
const before = state();
|
|
const after = applyUiDesignSuggestions(before, [
|
|
{
|
|
id: 'page',
|
|
name: '主页面',
|
|
description: '页面描述',
|
|
role: 'Page',
|
|
children: [
|
|
{
|
|
id: 'section',
|
|
name: '模型名称不应覆盖',
|
|
description: '页签描述',
|
|
role: 'Section',
|
|
children: [
|
|
{
|
|
id: 'detail',
|
|
name: '详情',
|
|
description: '模型描述不应覆盖',
|
|
role: 'Detail',
|
|
children: [],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
expect(after.ui_design_images.page.metadata).toEqual({
|
|
name: '主页面',
|
|
description: '页面描述',
|
|
role: 'Page',
|
|
slave_to: null,
|
|
});
|
|
expect(after.ui_design_images.section.metadata).toEqual({
|
|
name: '已有名称',
|
|
description: '页签描述',
|
|
role: 'Section',
|
|
slave_to: 'page',
|
|
});
|
|
expect(after.ui_design_images.detail.metadata).toEqual({
|
|
name: '详情',
|
|
description: '已有描述',
|
|
role: 'Detail',
|
|
slave_to: 'page',
|
|
});
|
|
expect(before.ui_design_images.page.metadata.name).toBe('');
|
|
});
|
|
});
|