Files
knowledge-governance/web/src/QAPeopleAnalysis.test.tsx
T
姚章浩 1c065846f6
build / build (push) Successful in 1m10s
fix(qaops): 按人视图同步直接展示部门及列宽
按人和按区域均直接显示部门名称与完整路径悬停,统一列宽;移除不再使用的折叠摘要、模式开关和样式。统计、兼属与分页不变。

验证:按人部门直显与统一列宽回归先红后绿,14项相关测试与类型检查通过。完整门禁、候选及上线验收待执行。
2026-10-24 14:33:44 +08:00

69 lines
3.5 KiB
TypeScript

import { it, expect } from 'vitest'
import { renderToStaticMarkup } from 'react-dom/server'
import { PeopleAnalysisView, PeopleRankingTable } from './QAPeopleAnalysis'
import { peopleAnalysis } from './qaPeopleAnalysis'
import { parseDepartmentStatistics } from './qaDepartmentStatistics'
import { departmentStatisticsFixture } from './qaDepartmentStatistics.fixture'
const fixture = () =>
parseDepartmentStatistics(structuredClone(departmentStatisticsFixture), { period: 'all' }).snapshot!
it('renders at most fifty ranked people with actual question counts and no department write controls', () => {
const template = peopleAnalysis(fixture()).people[0]
const rows = Array.from({ length: 123 }, (_, i) => ({
...template,
key: 'person-' + i.toString(16).padStart(64, '0'),
visits: 122 - i,
}))
const html = renderToStaticMarkup(<PeopleRankingTable people={rows} page={2} onPage={() => {}} label="全体人员" />)
expect(html.match(/data-ranking-person-key=/g)).toHaveLength(50)
expect(html).toContain('data-ranking="51"')
expect(html).toContain('data-ranking="100"')
expect(html).not.toContain('data-ranking="101"')
expect(html).toContain('50 人/页')
expect(html).toContain('上一页')
expect(html).toContain('下一页')
expect(html).not.toContain('checkbox')
expect(html).not.toContain('绑定选中部门')
})
it('shows both regional and all-person department names inline with complete path titles', () => {
const data = fixture()
data.rows.find((d) => d.id === 'root')!.name = '研发/视觉'
const html = renderToStaticMarkup(<PeopleAnalysisView data={data} mode="regions" />)
expect(html).toContain('qa-people-departments-inline')
expect(html).toContain('title="研发/视觉/Fixture Child"')
expect(html).toContain('>研发/视觉</li>')
expect(html).toContain('>Fixture Child</li>')
expect(html).not.toContain('<summary')
expect(html).not.toContain('个直属部门')
const all = renderToStaticMarkup(<PeopleAnalysisView data={data} mode="people" />)
expect(all).not.toContain('<summary')
expect(all).not.toContain('个直属部门')
expect(all).toContain('qa-people-departments-inline')
expect(all).toContain('title="研发/视觉/Fixture Child"')
expect(all).toContain('>研发/视觉</li>')
expect(all).toContain('>Fixture Child</li>')
})
it('uses the same widened personnel and department columns in both ranking views', () => {
const data = fixture()
const widths = (mode: 'regions' | 'people') =>
[
...renderToStaticMarkup(<PeopleAnalysisView data={data} mode={mode} />).matchAll(/<col style="width:(\d+)%"/g),
].map((m) => Number(m[1]))
expect(widths('regions')).toEqual([6, 20, 9, 36, 9, 20])
expect(widths('people')).toEqual([6, 20, 9, 36, 9, 20])
})
it('region analysis lists the saved region members once and all-person analysis retains unassigned and zero-use people', () => {
const data = fixture()
const region = renderToStaticMarkup(<PeopleAnalysisView data={data} mode="regions" />)
expect(region).toContain('按区域查看人员')
expect(region.match(/data-ranking-person-key=/g)).toHaveLength(2)
expect(region).toContain('Fixture Alpha')
expect(region).not.toContain('Fixture Beta')
expect(region).toContain('跨区域待核对')
expect(region).toContain('未归属')
const all = renderToStaticMarkup(<PeopleAnalysisView data={data} mode="people" />)
expect(all.match(/data-ranking-person-key=/g)).toHaveLength(3)
expect(all).toContain('未命名人员')
expect(all).toContain('Fixture Beta')
expect(all.indexOf('Fixture Beta')).toBeLessThan(all.indexOf('Fixture Alpha'))
})