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( {}} 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() expect(html).toContain('qa-people-departments-inline') expect(html).toContain('title="研发/视觉/Fixture Child"') expect(html).toContain('>研发/视觉') expect(html).toContain('>Fixture Child') expect(html).not.toContain(') expect(all).not.toContain('研发/视觉') expect(all).toContain('>Fixture Child') }) it('uses the same widened personnel and department columns in both ranking views', () => { const data = fixture() const widths = (mode: 'regions' | 'people') => [ ...renderToStaticMarkup().matchAll(/ 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() 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() 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')) })