补充UI树删除计数测试

覆盖嵌套节点定位与后代节点递归计数
This commit is contained in:
2026-09-05 13:17:51 +08:00
parent 8242885c79
commit 897683e63f
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import {
countUiNodeDescendants,
findUiNode,
} from '../src/features/ui-editor/treeUtils';
import type { Node } from '../src/features/ui-editor/types/Node';
function node(id: string, children: Node[] = []): Node {
return {
id,
layout: {} as Node['layout'],
metadata: {} as Node['metadata'],
components: [],
children_display_mode: 'Stack',
children,
};
}
describe('ui tree utilities', () => {
it('finds a nested node and counts all descendants', () => {
const nested = node('nested', [node('leaf')]);
const root = node('root', [node('page'), nested]);
expect(findUiNode(root, 'nested')).toBe(nested);
expect(findUiNode(root, 'missing')).toBeNull();
expect(countUiNodeDescendants(nested)).toBe(1);
expect(countUiNodeDescendants(root)).toBe(3);
});
});