import { describe, expect, it } from 'vitest'; import type { State } from '../src/features/ui-editor/types/State'; import { applyUiDesignSuggestions } from '../src/features/ui-editor/uiDesignSuggestions'; 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(''); }); });