// @vitest-environment jsdom import { afterEach, describe, expect, it } from 'vitest'; import { walkDOM } from '../walk'; import type { CSTInteractiveNode } from '../../cst/types'; import { isContainerNode, isInteractiveNode } from '../../cst/types'; afterEach(() => { document.body.innerHTML = ''; }); /** Flatten a CST subtree to all interactive nodes. */ function allInteractive(root: HTMLElement) { const { children } = walkDOM(root); const out: CSTInteractiveNode[] = []; const visit = (nodes: ReturnType['children']) => { for (const n of nodes) { if (isInteractiveNode(n)) out.push(n); else if (isContainerNode(n) || n.type === 'root') visit(n.children); } }; visit(children); return out; } describe('walkDOM', () => { it('captures interactive elements with refs', () => { document.body.innerHTML = `
`; const result = walkDOM(document.body); const interactive = allInteractive(document.body); expect(interactive).toHaveLength(2); expect(interactive[0].ref).toBe('@e1'); expect(interactive[1].ref).toBe('@e2'); expect(result.refMap.size).toBe(2); }); it('resolves accessible name from a