merchantStaffPicker.component.test.mjs
3.64 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import assert from 'node:assert/strict'
import { register } from 'node:module'
import test from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
function createComponentInstance(componentConfig, properties) {
const instance = {
properties: { ...properties },
data: structuredClone(componentConfig.data),
setData(patch) {
Object.assign(this.data, patch)
},
triggerEvent() {}
}
Object.entries(componentConfig.methods).forEach(([name, method]) => {
instance[name] = method.bind(instance)
})
return instance
}
test('同一次打开重复同步 show=true 时只加载一次人员数据', async () => {
let componentConfig
let employeeRequestCount = 0
globalThis.Component = config => {
componentConfig = config
}
globalThis.wx = {
$util: {
showToast() {}
}
}
globalThis.__WORK_ORDER_MOCK_API__ = {
getEmployeeList() {
employeeRequestCount += 1
return {
code: 0,
data: [{ userId: 'staff-1', name: '销售顾问一' }]
}
}
}
try {
await import(
`../components/merchant-staff-picker/merchant-staff-picker.js?single-open=${Date.now()}`
)
const instance = createComponentInstance(componentConfig, {
show: true,
mode: 'sales',
orderObj: {
lowPriceFlag: 1,
merchantId: 44210895,
merchantName: '当前下单门店'
},
userContext: {},
pointsMultiRole: 'Y',
orderCreateType: 'createdOrder'
})
const showObserver = componentConfig.properties.show.observer
showObserver.call(instance, true, false)
showObserver.call(instance, true, true)
await new Promise(resolve => setImmediate(resolve))
assert.equal(employeeRequestCount, 1)
assert.equal(instance.data.staffList[0].staffName, '销售顾问一')
instance.properties.show = false
showObserver.call(instance, false, true)
instance.properties.show = true
showObserver.call(instance, true, false)
await new Promise(resolve => setImmediate(resolve))
assert.equal(employeeRequestCount, 2)
} finally {
delete globalThis.__WORK_ORDER_MOCK_API__
delete globalThis.Component
}
})
test('默认选中的交付专员与销售顾问相同时确认也会拦截', async () => {
let componentConfig
const toastMessages = []
const confirmEvents = []
globalThis.Component = config => {
componentConfig = config
}
globalThis.wx = {
$util: {
showToast(message) {
toastMessages.push(message)
}
}
}
try {
await import(
`../components/merchant-staff-picker/merchant-staff-picker.js?confirm-conflict=${Date.now()}`
)
const instance = createComponentInstance(componentConfig, {
show: true,
mode: 'delivery',
orderObj: {
userId: 'staff-1',
userName: '秋椰0818'
},
userContext: {},
pointsMultiRole: 'Y',
orderCreateType: 'createdOrder'
})
instance.data.merchantTitle = '请选择合作门店'
instance.data.staffTitle = '请选择交付专员'
instance.data.merchantList = [
{ merchantId: 44210895, merchantName: '波波的单店门店', active: true }
]
instance.data.staffList = [
{ uuid: 'staff-1', staffName: '秋椰0818', active: true }
]
instance.triggerEvent = (name, detail) => {
confirmEvents.push({ name, detail })
}
instance.onConfirm()
assert.deepEqual(toastMessages, [
'销售顾问/录单员与交付专员不能选取同一人'
])
assert.deepEqual(confirmEvents, [])
} finally {
delete globalThis.Component
delete globalThis.wx
}
})