customerDailyFields.integration.test.mjs
4.67 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
)
let pageConfig
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.require = specifier => {
if (specifier === '~/utils/timeFormat/time-utils.js') {
return { getTodayDateStr: () => '2026-08-26' }
}
throw new Error(`Unexpected CommonJS dependency in page test: ${specifier}`)
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getDeviceInfo: () => ({ platform: 'devtools' }),
getWindowInfo: () => ({ screenWidth: 375, windowWidth: 375 }),
getAppBaseInfo: () => ({ host: { env: '' }, SDKVersion: 'test' }),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
getUserInfo: () => ({}),
showLoading() {}
}
}
await import(`../createOrder.js?customer-daily-fields=${Date.now()}`)
function createPage(currentMerchantId, cachedBrandMerchantId = currentMerchantId) {
return {
...pageConfig,
data: {
...structuredClone(pageConfig.data),
orderObj: {
merchantId: currentMerchantId,
baseSceneCode: 100101,
baseSceneName: '1.1 轻改场景',
customer: {
customerSex: 1,
experienceFlag: 'N',
salesType: 0
}
},
customerDailyFieldMerchantBrands: [
{
id: 2978,
name: '鸿蒙智行',
childs: [{ id: 3454, name: 'AITO 问界' }]
}
],
customerDailyFieldBrandMerchantId: cachedBrandMerchantId,
showActualDeliveryDate: false
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
loadBoutiqueCustomerTagOptions() {},
echoCustomerProfileIfNeeded: async () => {},
getSelectOrderGoodsList() {}
}
}
function createSelectedCustomer(merchantId) {
return {
merchantId,
merchantName: `门店-${merchantId}`,
remark: '已有备注',
customer: {
customerSex: 1,
experienceFlag: 'N',
salesType: 3,
standNo: 'LSVAA4182E2123456',
carSeriesName: '问界M5',
actualDeliveryDate: ''
}
}
}
test('IT-WO-DAILY-020: customer profile immediately reuses brands only for the same merchant', () => {
const sameMerchantPage = createPage(10001)
pageConfig.setOrderObj.call(sameMerchantPage, createSelectedCustomer(10001))
assert.equal(sameMerchantPage.data.orderObj.customer.salesType, 3)
assert.equal(sameMerchantPage.data.showActualDeliveryDate, true)
const changedMerchantPage = createPage(10001)
pageConfig.setOrderObj.call(
changedMerchantPage,
createSelectedCustomer(20002)
)
assert.equal(changedMerchantPage.data.orderObj.customer.salesType, 3)
assert.equal(changedMerchantPage.data.showActualDeliveryDate, false)
const pendingBrandPage = createPage(20002, 10001)
pageConfig.setOrderObj.call(
pendingBrandPage,
createSelectedCustomer(20002)
)
assert.equal(pendingBrandPage.data.orderObj.customer.salesType, 3)
assert.equal(pendingBrandPage.data.showActualDeliveryDate, false)
})
test('IT-WO-DAILY-021: resolved brand context records its merchant provenance', async () => {
globalThis.__WORK_ORDER_MOCK_API__ = {
getMerchantCarBrandList: () => ({
code: 0,
data: {
data: [
{
carBrandList: [
{
id: 2978,
name: '鸿蒙智行',
childs: [{ id: 3454, name: 'AITO 问界' }]
}
]
}
]
}
})
}
const page = createPage(10001, '')
page.loadBoutiqueCustomerTagOptions =
pageConfig.loadBoutiqueCustomerTagOptions
try {
await page.loadBoutiqueCustomerTagOptions(10001)
assert.equal(page.data.customerDailyFieldBrandMerchantId, 10001)
} finally {
delete globalThis.__WORK_ORDER_MOCK_API__
}
})
test('IT-WO-DAILY-022: opening customer source picker selects the current source', () => {
const page = createPage(10001)
page.data.orderObj.customer.salesType = 3
pageConfig.toSelectCustomerSource.call(page)
assert.equal(page.data.showSource, true)
assert.equal(page.data.customerSourcePickerIndex, 1)
pageConfig.onCloseSource.call(page)
page.data.orderObj.customer.salesType = '1'
pageConfig.toSelectCustomerSource.call(page)
assert.equal(page.data.customerSourcePickerIndex, 2)
pageConfig.onCloseSource.call(page)
page.data.orderObj.customer.salesType = 99
pageConfig.toSelectCustomerSource.call(page)
assert.equal(page.data.customerSourcePickerIndex, 0)
})