cc-haha/desktop/src/preview-agent/treeNav.test.ts
2026-05-31 17:40:45 +08:00

18 lines
720 B
TypeScript

import { describe, expect, it, beforeEach } from 'vitest'
import { climb, descend } from './treeNav'
beforeEach(() => { document.body.innerHTML = `<main><section><h1>A</h1></section></main>` })
describe('tree navigation', () => {
it('climb returns parent element, not past body', () => {
const h1 = document.querySelector('h1')!
expect(climb(h1)?.tagName.toLowerCase()).toBe('section')
expect(climb(document.querySelector('main')!)).toBeNull() // body 为界
})
it('descend returns first element child', () => {
const section = document.querySelector('section')!
expect(descend(section)?.tagName.toLowerCase()).toBe('h1')
expect(descend(document.querySelector('h1')!)).toBeNull()
})
})