- 7 个 spec 的本地 mount()(createRoot + act 容器循环)替换为 renderRoot():sidechat-view、subagent-jobs-view、subagent-live-polling、 lazy-chunk、side-card-section-rows(本地 mount 删除,调用点改名); editor-refresh、markdown-manual-refresh(EditorHost 包装 mount 改为 委托 renderRoot,调用点不动) - 24 个 spec 的内联 IS_REACT_ACT_ENVIRONMENT 赋值替换为 setupReactAct() (subagent-jobs-view / subagent-live-polling / lazy-chunk 原本未设 flag,保持原样不引入) 全部为语义相同的样板替换:迁移后全量 118 files / 1241 passed + 9 skipped,与迁移前一致。
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { createElement } from 'react'
|
|
import { createRoot, type Root } from 'react-dom/client'
|
|
import { act } from 'react-dom/test-utils'
|
|
import { DiffFiles } from '../src/client/diff/DiffFiles.tsx'
|
|
|
|
import { setupReactAct } from './test-utils.ts'
|
|
setupReactAct()
|
|
|
|
const diff = [
|
|
'diff --git a/src/a.ts b/src/a.ts',
|
|
'--- a/src/a.ts',
|
|
'+++ b/src/a.ts',
|
|
'@@ -1 +1 @@',
|
|
'-old-a',
|
|
'+new-a',
|
|
'diff --git a/tests/b.spec.ts b/tests/b.spec.ts',
|
|
'--- a/tests/b.spec.ts',
|
|
'+++ b/tests/b.spec.ts',
|
|
'@@ -1 +1 @@',
|
|
'-old-b',
|
|
'+new-b',
|
|
'diff --git a/README.md b/README.md',
|
|
'--- a/README.md',
|
|
'+++ b/README.md',
|
|
'@@ -1 +1 @@',
|
|
'-old-doc',
|
|
'+new-doc',
|
|
].join('\n')
|
|
|
|
afterEach(() => { document.body.innerHTML = '' })
|
|
|
|
describe('DiffFiles file folding', () => {
|
|
it('expands source by default while tests and docs stay collapsed', () => {
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
try {
|
|
act(() => { root.render(createElement(DiffFiles, { diff })) })
|
|
const headers = [...container.querySelectorAll<HTMLButtonElement>('button[aria-expanded]')]
|
|
expect(headers).toHaveLength(3)
|
|
expect(headers.map(header => header.getAttribute('aria-expanded'))).toEqual(['true', 'false', 'false'])
|
|
expect(container.textContent).toContain('new-a')
|
|
expect(container.textContent).not.toContain('new-b')
|
|
expect(container.textContent).not.toContain('new-doc')
|
|
|
|
act(() => { headers[1]!.click() })
|
|
expect(headers[1]!.getAttribute('aria-expanded')).toBe('true')
|
|
expect(container.textContent).toContain('new-b')
|
|
|
|
act(() => { headers[0]!.click() })
|
|
expect(headers[0]!.getAttribute('aria-expanded')).toBe('false')
|
|
expect(container.textContent).not.toContain('new-a')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
})
|