lowPriceGoodsValidation.integration.test.mjs
5.07 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
import { readFileSync } from 'node:fs'
import { register } from 'node:module'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
const pageSource = readFileSync(
new URL('../createOrder.js', import.meta.url),
'utf8'
)
const pageTemplate = readFileSync(
new URL('../createOrder.wxml', import.meta.url),
'utf8'
)
const rowComponentSource = readFileSync(
new URL('../components/OrderGoodsRow/order-goods-row.js', import.meta.url),
'utf8'
)
const rowComponentTemplate = readFileSync(
new URL('../components/OrderGoodsRow/order-goods-row.wxml', import.meta.url),
'utf8'
)
const chooseGoodsStart = pageSource.indexOf(' chooseGoods(e) {')
const chooseGoodsEnd = pageSource.indexOf('\n isLowPriceOrder()', chooseGoodsStart)
const chooseGoodsSource = pageSource.slice(chooseGoodsStart, chooseGoodsEnd)
describe('createOrder low-price goods integration', () => {
it('IT-WO-LPG-008: selection only syncs state while live price input enables the reminder', () => {
assert.match(
pageSource,
/LOW_PRICE_NOT_TRIGGERED_MESSAGE[\s\S]*applyLowPriceGoodsValidation/
)
assert.match(
pageSource,
/Number\(this\.data\.orderObj\?\.lowPriceFlag\) === 1/
)
assert.match(chooseGoodsSource, /applyLowPriceGoodsRules\(selectedGoodsList\)/)
assert.doesNotMatch(chooseGoodsSource, /notify:\s*true/)
assert.match(
pageSource,
/changeMealPrice\(e\)[\s\S]*applyLowPriceGoodsRules\(goodsList,\s*\{\s*notify:\s*true\s*\}\)/
)
assert.match(
pageSource,
/changePrice\(e\)[\s\S]*applyLowPriceGoodsRules\(goodsList,\s*\{\s*notify:\s*true\s*\}\)/
)
assert.match(
pageSource,
/wx\.\$util\.showToast\(LOW_PRICE_NOT_TRIGGERED_MESSAGE\)/
)
})
it('IT-WO-LPG-009: revalidates the full goods list before building the submit payload', () => {
assert.match(
pageSource,
/checkGoods\(save, subOrderList, priceDisabled, goodsList, orderObj\)[\s\S]*Number\(orderObj\?\.lowPriceFlag\) === 1[\s\S]*applyLowPriceGoodsValidation\(goodsList\)[\s\S]*LOW_PRICE_NOT_TRIGGERED_MESSAGE/
)
})
it('IT-WO-LPG-010: passes lowPriceFlag to every selected-goods row and renders the minimum-price echo only for low-price orders', () => {
const rowTags = [
...pageTemplate.matchAll(/<order-goods-row[\s\S]*?\/>/g)
].map(match => match[0])
assert.ok(rowTags.length > 0)
rowTags.forEach(tag => {
assert.match(tag, /lowPriceFlag="\{\{ orderObj\.lowPriceFlag \}\}"/)
})
assert.match(rowComponentSource, /lowPriceFlag:\s*\{[\s\S]*type:\s*Number/)
assert.match(
rowComponentTemplate,
/class="low-price-minimum"\s+wx:if="\{\{ lowPriceFlag == 1 \}\}">\{\{product\.lowPriceMinPriceText\}\}/
)
})
it('IT-WO-LPG-011: selection stays silent, live input warns, and submit blocks invalid low-price goods', async () => {
let pageConfig
const toastMessages = []
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
getUserInfo: () => ({}),
showToast: message => toastMessages.push(message)
}
}
await import(`../createOrder.js?low-price-goods=${Date.now()}`)
const lowPriceGoods = {
validMinSellPrice: 'N',
minSellPrice: 100,
sellPrice: 80
}
const lowPriceGoodsList = [{ goodsFlag: 1, goods: lowPriceGoods }]
const lowPricePage = {
...pageConfig,
data: {
orderObj: { lowPriceFlag: 1 },
goodsList: lowPriceGoodsList
},
setData(patch) {
Object.assign(this.data, patch)
}
}
lowPricePage.chooseGoods({ detail: lowPriceGoodsList })
assert.equal(lowPriceGoods.lowPriceMinPriceText, '最低价:未开启')
assert.deepEqual(toastMessages, [])
const liveResult = lowPricePage.applyLowPriceGoodsRules(
lowPriceGoodsList,
{ notify: true }
)
const submitMessage = lowPricePage.checkGoods(
false,
[],
true,
lowPriceGoodsList,
lowPricePage.data.orderObj
)
assert.equal(liveResult.valid, false)
assert.equal(lowPriceGoods.errorTarget, true)
assert.deepEqual(toastMessages, [
'价格未触发最低价,其他正常单请到生意助手侧录单'
])
assert.equal(
submitMessage,
'价格未触发最低价,其他正常单请到生意助手侧录单'
)
const normalGoods = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80
}
const normalPage = {
...pageConfig,
data: {
orderObj: { lowPriceFlag: 0 },
goodsList: [{ goodsFlag: 1, goods: normalGoods }]
}
}
assert.equal(normalPage.applyLowPriceGoodsRules().valid, true)
assert.equal(normalGoods.lowPriceMinPriceText, undefined)
})
})