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); }); });