Files
knowledge-governance/web/src/qaPeopleAnalysis.test.ts
T
姚章浩 f38541db06
build / build (push) Successful in 1m5s
fix(qaops): 区域人员表直接展示部门并调整列宽
仅按区域显示真实部门名称与完整路径悬停,替代部门数量折叠摘要;适配人员与部门列宽,按人视图保持原样。归属、统计与分页不变。

验证:真实节点名称、区域直显且按人不变、区域列宽分别先红后绿,14项相关测试与类型检查通过。完整门禁、候选和上线验收待执行。
2026-10-24 14:14:21 +08:00

72 lines
3.5 KiB
TypeScript

import { it, expect } from 'vitest'
import { peopleAnalysis, peoplePage } from './qaPeopleAnalysis'
import { parseDepartmentStatistics } from './qaDepartmentStatistics'
import { departmentStatisticsFixture } from './qaDepartmentStatistics.fixture'
const fixture = () =>
parseDepartmentStatistics(structuredClone(departmentStatisticsFixture), { period: 'all' }).snapshot!
it('ranks every unique roster person by questions descending including zero use without mutating the snapshot', () => {
const data = fixture(),
before = JSON.stringify(data),
result = peopleAnalysis(data)
expect(result.people.map((p) => p.visits)).toEqual([3, 2, 0])
expect(new Set(result.people.map((p) => p.key)).size).toBe(3)
expect(result.people.find((p) => p.visits === 0)?.name).toBe('')
expect(JSON.stringify(data)).toBe(before)
})
it('keeps the actual department name separately from its complete path without splitting name slashes', () => {
const data = fixture()
data.rows.find((d) => d.id === 'root')!.name = '研发/视觉'
const person = peopleAnalysis(data).people.find((p) => p.visits === 2)!
expect(person.department_paths.find((d) => d.id === 'root')?.name).toBe('研发/视觉')
expect(person.department_paths.find((d) => d.id === 'child')).toEqual({
id: 'child',
name: 'Fixture Child',
path: '研发/视觉/Fixture Child',
})
})
it('groups same-region memberships once and separates cross-region and unassigned without choosing a primary', () => {
const data = fixture()
data.regions.push({ id: 'industrial', name: 'Industrial' }, { id: 'empty', name: 'Empty' })
data.rows.find((d) => d.id === 'root')!.region = 'industrial'
const result = peopleAnalysis(data),
groups = new Map(result.groups.map((g) => [g.key, g]))
expect(groups.get('region:edu')?.people.map((p) => p.visits)).toEqual([0])
expect(groups.get('region:industrial')?.people.map((p) => p.visits)).toEqual([3])
expect(groups.get('state:cross_region')?.people.map((p) => p.visits)).toEqual([2])
expect(groups.get('region:empty')?.people).toEqual([])
expect(result.people.find((p) => p.visits === 2)?.region_label).toContain('跨区域待核对')
expect(
result.groups
.flatMap((g) => g.people)
.map((p) => p.key)
.sort()
).toEqual(data.people.map((p) => p.key).sort())
const initial = peopleAnalysis(fixture())
expect(initial.groups.find((g) => g.key === 'region:edu')?.people).toHaveLength(2)
expect(initial.groups.find((g) => g.key === 'state:unassigned')?.people).toHaveLength(1)
})
it('paginates all people at exactly fifty with no gaps, correct final page and deterministic ties', () => {
const template = peopleAnalysis(fixture()).people[0]
const data = Array.from({ length: 123 }, (_, i) => ({
...template,
key: 'person-' + i.toString(16).padStart(64, '0'),
visits: 122 - i,
}))
const pages = [1, 2, 3].map((n) => peoplePage(data, n))
expect(pages.map((p) => p.items.length)).toEqual([50, 50, 23])
expect(pages.map((p) => p.start)).toEqual([0, 50, 100])
expect(pages.flatMap((p) => p.items.map((r) => r.key))).toEqual(data.map((r) => r.key))
expect(peoplePage(data, 999).page).toBe(3)
expect(peoplePage(data, -1).page).toBe(1)
expect(peoplePage(data, NaN).page).toBe(1)
expect(peoplePage([], 1)).toMatchObject({ items: [], total: 0, start: 0, end: 0, page: 1, pages: 1 })
const same = fixture()
same.people.forEach((p) => {
p.name = '同名'
p.visits = 1
})
const first = peopleAnalysis(same).people.map((p) => p.key)
same.people.reverse()
expect(peopleAnalysis(same).people.map((p) => p.key)).toEqual(first)
})