import { it, expect } from 'vitest' import { defaultDepartmentCollapsed, departmentTree } from './qaRegionSelection' import { parseDepartmentStatistics } from './qaDepartmentStatistics' import { departmentStatisticsFixture as f } from './qaDepartmentStatistics.fixture' it('defaults to company, business centers and second-level departments while preserving deeper search and expansion', () => { const nodes = [ { id: 'company', parent_id: '', name: '示例公司' }, { id: 'finance', parent_id: 'company', name: '财务中心' }, { id: 'department', parent_id: 'finance', name: '财务部' }, { id: 'office', parent_id: 'department', name: '更深财务组' }, { id: 'global', parent_id: 'company', name: '全球业务支持中心' }, { id: 'solution', parent_id: 'global', name: '解决方案部' }, { id: 'support', parent_id: 'global', name: '全球技术支持部' }, ] const collapsed = defaultDepartmentCollapsed(nodes) expect(departmentTree(nodes, collapsed).map((r) => r.department.id)).not.toContain('office') expect(new Set(departmentTree(nodes, collapsed).map((r) => r.department.id))).toEqual( new Set(nodes.filter((n) => n.id !== 'office').map((n) => n.id)) ) expect(departmentTree(nodes, collapsed, '更深财务组').some((r) => r.department.id === 'office')).toBe(true) collapsed.delete('department') expect(departmentTree(nodes, collapsed).some((r) => r.department.id === 'office')).toBe(true) }) it('accepts an exact natural week response and rejects a mismatched week or non-Monday start', () => { const raw = { ...f, snapshot: { ...f.snapshot, period: 'week', week: '2026-W42', start: '2026-10-12T00:00:00+08:00', end: '2026-10-19T00:00:00+08:00', }, } const query = JSON.parse('{"period":"week","week":"2026-W42"}') expect(parseDepartmentStatistics(raw, query).snapshot?.period).toBe('week') expect(() => parseDepartmentStatistics({ ...raw, snapshot: { ...raw.snapshot, week: '2026-W43' } }, query)).toThrow() expect(() => parseDepartmentStatistics({ ...raw, snapshot: { ...raw.snapshot, start: '2026-10-11T00:00:00+08:00' } }, query) ).toThrow() })