@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { applyBulkRegionRules, departmentLevels } from './qaRegionSelection'
|
||||
import type { DepartmentRegion } from './qaOrg'
|
||||
describe('department multi-selection', () => {
|
||||
it('applies only explicitly selected IDs without deleting child overrides or mutating saved rules', () => {
|
||||
const saved = [
|
||||
{ department_id: 'child', region: 'west' },
|
||||
{ department_id: 'sibling', region: 'education' },
|
||||
]
|
||||
const draft = applyBulkRegionRules(saved, ['parent', 'other', 'parent'], 'education')
|
||||
expect(draft).toEqual([
|
||||
...saved,
|
||||
{ department_id: 'parent', region: 'education' },
|
||||
{ department_id: 'other', region: 'education' },
|
||||
])
|
||||
expect(saved).toHaveLength(2)
|
||||
expect(applyBulkRegionRules(draft, [], 'west')).toEqual(draft)
|
||||
})
|
||||
it('derives every hierarchy level from parent IDs, not slashes in names or a three-level cutoff', () => {
|
||||
const departments = Array.from({ length: 5 }, (_, i) => ({
|
||||
id: String(i),
|
||||
parent_id: i ? String(i - 1) : '',
|
||||
name: `部门/${i}`,
|
||||
path: '',
|
||||
region: '',
|
||||
explicit: false,
|
||||
inherited_from: '',
|
||||
})) as DepartmentRegion[]
|
||||
expect(departmentLevels(departments, '4')).toEqual(departments.map((d) => d.name))
|
||||
expect(() =>
|
||||
departmentLevels([...departments, { ...departments[0], id: 'cycle', parent_id: 'cycle' }], 'cycle')
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user