lowPriceSubmitFlow.integration.test.mjs
4.51 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
168
169
170
171
172
173
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { beforeEach, describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
const mockApi = await import(
'../../../../tests/work-order-migration/shims/mock-api.mjs'
)
const { SubmitContext } = await import(`../submitStrategy.js?flow=${Date.now()}`)
function createPage(options = {}) {
const approvalItems = []
const patches = []
const page = {
data: {
submitStatus: false,
isErrorOrder: false,
orderCreateType: '',
scene: '',
total: 80,
goodsList: [
{
goodsFlag: 1,
count: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80,
goodsName: '测试商品'
}
}
],
orderObj: {
lowPriceFlag: options.lowPriceFlag ?? 1,
djOrderType: 1,
selectPayType: 1,
customer: {},
subOrderList: []
}
},
setData(patch) {
patches.push(patch)
Object.assign(this.data, patch)
},
checkPhoneUseConfig() {},
checkGoods() {},
checkRequired() {},
handleRequiredError() {},
openMinPriceApprovalSheet(items, save) {
approvalItems.push(...items)
this.data.minPriceApprovalSheet = { show: true, items }
this.data._pendingSubmitSave = !!save
}
}
return { page, approvalItems, patches }
}
describe('low-price approval submit flow', () => {
beforeEach(() => {
globalThis.__WORK_ORDER_MOCK_API__ = {}
globalThis.wx = {
disableAlertBeforeUnload() {},
hideLoading() {},
showModal() {},
$util: { refreshPageData() {} },
$router: {
back() {},
go() {},
redirectTo() {}
}
}
})
it('opens approval confirmation before calling the order API', async () => {
let apiCalls = 0
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => {
apiCalls += 1
return { code: 0, data: {} }
}
const { page, approvalItems } = createPage()
await new SubmitContext(page).execute({ currentTarget: { dataset: {} } })
assert.equal(apiCalls, 0)
assert.equal(page.data.minPriceApprovalSheet.show, true)
assert.equal(approvalItems.length, 1)
assert.equal(approvalItems[0].name, '测试商品')
})
it('submits once after approval and returns the source list to pending', async () => {
let apiCalls = 0
let redirectTarget = ''
let backCalls = 0
let sourcePatch
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => {
apiCalls += 1
return { code: 0, data: { orderCode: 'LP-1' } }
}
wx.$router.redirectTo = route => {
redirectTarget = route
}
wx.$router.back = () => {
backCalls += 1
}
wx.$router.getPageInstance = () => ({
__route__: 'pages/tabWorkOrder/pages/index/index',
setData(patch) {
sourcePatch = patch
}
})
const { page } = createPage()
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(apiCalls, 1)
assert.equal(redirectTarget, '')
assert.equal(backCalls, 1)
assert.deepEqual(sourcePatch, {
activeIndex: 1,
tabIndex: 1,
keyword: '',
searchObj: {}
})
})
it('keeps ordinary order success on confirmOrder', async () => {
let redirectTarget = ''
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => ({
code: 0,
data: { orderCode: 'NORMAL-1' }
})
wx.$router.redirectTo = route => {
redirectTarget = route
}
const { page } = createPage({ lowPriceFlag: 0 })
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(redirectTarget, 'confirmOrder')
})
it('falls back to the pending-list route when the source list is unavailable', async () => {
let fallbackRoute = ''
let backCalls = 0
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => ({
code: 0,
data: { orderCode: 'LP-FALLBACK' }
})
wx.$router.getPageInstance = () => ({
__route__: 'pages/tab/workspace/workspace',
setData() {}
})
wx.$router.back = () => {
backCalls += 1
}
wx.$router.go = route => {
fallbackRoute = route
}
const { page } = createPage()
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(
fallbackRoute,
'/pages/tabWorkOrder/pages/index/index?activeIndex=1'
)
assert.equal(backCalls, 0)
})
})