technicianSelect.helpers.test.mjs
2.92 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildSelectArr,
buildRatioMap,
mapArtificerList,
calcShowMainShareRatio,
buildConfirmPayload
} from '../components/TechnicianSelectPopup/technicianSelect.helpers.js'
describe('technicianSelect.helpers', () => {
it('TECH-01 technicianId 模式 selectArr', () => {
const arr = buildSelectArr(
[{ technicianId: 1, id: 10 }, { id: 20 }],
'technicianId'
)
assert.deepEqual(arr, [1, 20])
})
it('TECH-02 uuid 模式 selectArr', () => {
const arr = buildSelectArr([{ uuid: 'a' }, { uuid: 'b' }], 'uuid')
assert.deepEqual(arr, ['a', 'b'])
})
it('TECH-03 active 映射', () => {
const list = mapArtificerList(
[
{ id: 1, uuid: 'u1', staffName: 'A' },
{ id: 2, uuid: 'u2', staffName: 'B' }
],
{
artificerSelectObj: { id: 1, uuid: 'u1' },
selectArr: [1],
ratioMap: { 1: 30 },
idKey: 'technicianId',
disabledSelectObj: [],
deputyFlag: false
}
)
assert.equal(list[0].active, true)
assert.equal(list[0].shareRatio, 30)
assert.equal(list[1].active, false)
})
it('TECH-04 disabled 映射', () => {
const list = mapArtificerList(
[{ id: 1, uuid: 'u1' }, { id: 2, uuid: 'u2' }],
{
artificerSelectObj: null,
selectArr: [],
ratioMap: {},
idKey: 'technicianId',
disabledSelectObj: [{ uuid: 'u2' }],
deputyFlag: false
}
)
assert.equal(list[0].disabled, false)
assert.equal(list[1].disabled, true)
})
it('TECH-05 shareRatio 映射', () => {
const ratioMap = buildRatioMap([{ id: 5, shareRatio: 40 }], 'technicianId')
assert.equal(ratioMap[5], 40)
assert.equal(calcShowMainShareRatio([{ active: true, shareRatio: 40 }]), 60)
})
it('TECH-06 副手选满 2 个置灰', () => {
const list = mapArtificerList(
[
{ id: 1, uuid: 'u1' },
{ id: 2, uuid: 'u2' },
{ id: 3, uuid: 'u3' }
],
{
artificerSelectObj: [{ id: 1 }, { id: 2 }],
selectArr: [1, 2],
ratioMap: { 1: 30, 2: 20 },
idKey: 'technicianId',
disabledSelectObj: [],
deputyFlag: true
}
)
assert.equal(list[2].disabled, true)
})
it('TECH-07 confirm technicianId 含 technicianId 字段', () => {
const result = buildConfirmPayload({
artificerSelectObj: {},
activeArr: [{ uuid: 'u1', id: 99, staffName: 'T' }],
idKey: 'technicianId',
deputyFlag: false
})
assert.equal(result.ok, true)
assert.equal(result.payload.technicianId, 99)
})
it('TECH-08 confirm uuid 模式 deputy 空选放行', () => {
const result = buildConfirmPayload({
artificerSelectObj: { foo: 1 },
activeArr: [],
idKey: 'uuid',
deputyFlag: true
})
assert.equal(result.ok, true)
assert.equal(result.payload.technicianUuid, '')
})
})