刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, expect, it } from 'vitest';
 
import { formatOrganizationDisplayName, normalizeOrganizationConfig, resolveCurrentOrganizationDefaultIds } from './organizationConfig';
 
const user = {
  organizeId: 'd',
  organizeIds: ['d', 'e', 'missing'],
  organizeList: [
    { id: 'd', treeId: 'a,b,c,d', treeName: 'A/B/C/D' },
    { id: 'e', treeId: 'a,b,e', treeName: 'A/B/E' },
  ],
};
 
describe('organization form configuration', () => {
  it('selects an ancestor from the ID path and deduplicates multiple organizations', () => {
    expect(resolveCurrentOrganizationDefaultIds(user, 2, false)).toBe('b');
    expect(resolveCurrentOrganizationDefaultIds(user, 2, true)).toEqual(['b', 'missing']);
    expect(resolveCurrentOrganizationDefaultIds(user, 8, false)).toBe('d');
    expect(resolveCurrentOrganizationDefaultIds(user, 0, true)).toEqual(['d', 'e', 'missing']);
  });
 
  it('keeps the selected root visible and leaves incomplete paths unchanged', () => {
    expect(formatOrganizationDisplayName('A/B/C/D', 'a,b,c,d', 0)).toBe('B/C/D');
    expect(formatOrganizationDisplayName('A', 'a', 0)).toBe('A');
    expect(formatOrganizationDisplayName('A/B', undefined, 0)).toBe('A/B');
    expect(formatOrganizationDisplayName('A/B', 'a,b', 1)).toBe('A/B');
  });
 
  it('limits a mapped department display from the selected organization upward', () => {
    expect(formatOrganizationDisplayName('A/B/C/D', 'a,b,c,d', 1, 0)).toBe('A/B/C/D');
    expect(formatOrganizationDisplayName('A/B/C/D', 'a,b,c,d', 1, 2)).toBe('C/D');
    expect(formatOrganizationDisplayName('A/B/C/D', 'a,b,c,d', 0, 4)).toBe('B/C/D');
    expect(formatOrganizationDisplayName('A/B', 'a,b', 0, 2)).toBe('B');
    expect(formatOrganizationDisplayName('A', 'a', 0, 3)).toBe('A');
    expect(formatOrganizationDisplayName('A/B/C/D', 'a,b,c,d', 1, 8)).toBe('A/B/C/D');
  });
 
  it('uses compatible defaults when configuration is absent or invalid', () => {
    expect(normalizeOrganizationConfig()).toEqual({ showRootOrganizationName: 1, currentOrganizationDefaultLevel: 0, workflowDepartmentDisplayLevel: 0 });
    expect(normalizeOrganizationConfig({ showRootOrganizationName: 0, currentOrganizationDefaultLevel: 3, workflowDepartmentDisplayLevel: 2 })).toEqual({
      showRootOrganizationName: 0,
      currentOrganizationDefaultLevel: 3,
      workflowDepartmentDisplayLevel: 2,
    });
    expect(normalizeOrganizationConfig({ currentOrganizationDefaultLevel: -1 }).currentOrganizationDefaultLevel).toBe(0);
    expect(normalizeOrganizationConfig({ workflowDepartmentDisplayLevel: 2 }).currentOrganizationDefaultLevel).toBe(0);
    expect(normalizeOrganizationConfig({ currentOrganizationDefaultLevel: 3 }).workflowDepartmentDisplayLevel).toBe(0);
    expect(normalizeOrganizationConfig({ workflowDepartmentDisplayLevel: -1 }).workflowDepartmentDisplayLevel).toBe(0);
  });
});