Files
apes-sidebar/tests/clues-section-stack.spec.tsx
T
Menghuan1918 86dc34bd84 fix(ui): Git 页的 Changes 与 Graph 接入可拖动分区堆叠
把线索页的 SectionStack 抽成统一组件 WorkbenchStack(ui/WorkbenchStack.tsx +
workbench-stack.module.css,从 ui/index.ts 导出),线索页改为从统一层引用,
行为与权重持久化不变。

Git 页把 Changes 与 Graph 两个 WorkbenchSection 放进同一个堆叠:两区之间出现
可拖动的 sash(role=separator、aria-controls、Home/End/ArrowUp/ArrowDown),
权重只存本地 state——Git 页目前没有自己的设置键,不为此新增持久化。

布局:每个打开的分区各自内部滚动(changes 的 body 与 graph 区域),footer 仍是
贴底不滚;gitScroll 保留为 notices 的滚动容器。折叠到一个分区时 sash 消失。

测试:git-scm 新增「两个分区都开时存在 sash、键盘拖动改变两 pane 的 flexGrow、
折叠一个后 sash 消失」;changes-tab 的分隔条查询改为结构判别(sash 有
aria-controls、底部预览手柄没有),并把 .changesSection 的 CSS 契约从 flex:none
更新为 flex:1(现在由堆叠分配高度)。
2026-11-25 11:04:37 +08:00

44 lines
2.2 KiB
TypeScript

/** Three sections resize adjacent open neighbors, even across a collapsed pane. */
// @vitest-environment jsdom
import { createElement } from 'react'
import { act } from 'react-dom/test-utils'
import { expect, it, vi } from 'vitest'
import { WorkbenchStack } from '../src/client/ui/WorkbenchStack.tsx'
import { renderRoot, setupReactAct } from './test-utils.ts'
setupReactAct()
it('resizes a pair without moving the third or unmounting it when collapsed', () => {
const commit = vi.fn()
const sections = ['first', 'second', 'third'].map(id => ({ id, title: id, open: true, weight: 1,
content: createElement('input', { 'aria-label': id, defaultValue: id }) }))
const view = renderRoot(createElement(WorkbenchStack, { sections, onResize: commit }))
try {
const separators = () => Array.from(view.container.querySelectorAll<HTMLElement>('[role="separator"]'))
const press = (node: HTMLElement, key: string) => {
act(() => { node.dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true })) })
}
expect(separators()).toHaveLength(2)
press(separators()[0]!, 'End')
const firstResize = commit.mock.calls.at(-1)?.[0]
expect(firstResize.first).toBeCloseTo(2)
expect(firstResize.second).toBeCloseTo(0)
expect(firstResize.third).toBe(1)
const input = view.container.querySelector<HTMLInputElement>('[aria-label="second"]')!
input.value = 'retained draft'
view.rerender(createElement(WorkbenchStack, { sections: sections.map(section => section.id === 'second'
? { ...section, open: false } : section), onResize: commit }))
expect(separators()).toHaveLength(1)
expect(separators()[0]!.getAttribute('aria-label')).toBe('first / third')
press(separators()[0]!, 'Home')
const secondResize = commit.mock.calls.at(-1)?.[0]
expect(secondResize.first).toBeCloseTo(0)
expect(secondResize.second).toBe(firstResize.second)
expect(secondResize.third).toBeCloseTo(3)
view.rerender(createElement(WorkbenchStack, { sections, onResize: commit }))
expect(view.container.querySelector<HTMLInputElement>('[aria-label="second"]')).toBe(input)
expect(input.value).toBe('retained draft')
expect(separators()).toHaveLength(2)
} finally { view.unmount() }
})