594063a1e0
- 按 vitest 0.34 的参数元组口径改写 mock 泛型 - 修正 noUncheckedIndexedAccess 下的下标访问 - 补齐与当前类型脱节的测试桩字段 - 按 scripts/*.mjs 的运行时契约补局部类型声明
32 lines
896 B
TypeScript
32 lines
896 B
TypeScript
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'],
|
|
component: null,
|
|
children_display_mode: 'Stack',
|
|
children,
|
|
offset: {} as Node['offset'],
|
|
};
|
|
}
|
|
|
|
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);
|
|
});
|
|
});
|