work-order-list-page.test.mjs
5.98 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
174
175
176
177
178
179
180
181
182
183
184
185
import assert from 'node:assert/strict'
import { generate } from '@babel/generator'
import { parse } from '@babel/parser'
import { readFile } from 'node:fs/promises'
import { describe, it } from 'node:test'
import { runInNewContext } from 'node:vm'
async function loadListPage() {
const pageSource = await readFile(
'pages/tabWorkOrder/pages/index/index.js',
'utf8'
)
const ast = parse(pageSource, { sourceType: 'module' })
ast.program.body = ast.program.body.filter(
node => node.type !== 'ImportDeclaration'
)
let pageConfig
const navigateBackCalls = []
const showTabBarCalls = []
runInNewContext(generate(ast).code, {
Page(config) {
pageConfig = config
},
order_mixins: {
data: {}
},
wx: {
navigateBack: options => navigateBackCalls.push(options),
showTabBar: options => showTabBarCalls.push(options)
},
console,
setTimeout,
clearTimeout
})
return { pageConfig, navigateBackCalls, showTabBarCalls }
}
function createPageContext(pageConfig, initialData) {
const context = {
...pageConfig,
data: {
...pageConfig.data,
...initialData
},
setData(patch) {
Object.assign(this.data, patch)
}
}
return context
}
describe('工单列表页面行为', () => {
it('筛选层打开时顶部返回只关闭筛选层', async () => {
const { pageConfig, navigateBackCalls, showTabBarCalls } =
await loadListPage()
assert.equal(typeof pageConfig.handleBack, 'function')
assert.equal(typeof pageConfig.closeFilter, 'function')
const context = createPageContext(pageConfig, { show_confirm: true })
pageConfig.handleBack.call(context)
assert.equal(context.data.show_confirm, false)
assert.equal(navigateBackCalls.length, 0)
assert.equal(showTabBarCalls.length, 1)
})
it('筛选层关闭时顶部返回上一页', async () => {
const { pageConfig, navigateBackCalls, showTabBarCalls } =
await loadListPage()
const context = createPageContext(pageConfig, { show_confirm: false })
pageConfig.handleBack.call(context)
assert.equal(navigateBackCalls.length, 1)
assert.equal(showTabBarCalls.length, 0)
})
it('列表页仅注册低价单新增流程,不恢复扫码旧流程', async () => {
const { pageConfig } = await loadListPage()
const pageJson = JSON.parse(
await readFile('pages/tabWorkOrder/pages/index/index.json', 'utf8')
)
for (const methodName of [
'scan',
'promptHandleConfirm',
'promptCancel',
'tipsEvent',
'closeSwitchPopup',
'onPageScroll'
]) {
assert.equal(pageConfig[methodName], undefined)
}
for (const stateName of [
'showIcon1',
'showIcon2',
'isScan',
'sceneObj',
'showPromptDialog'
]) {
assert.equal(pageConfig.data[stateName], undefined)
}
assert.equal(pageConfig.data.showLowPriceOrderPrompt, false)
assert.equal(pageConfig.data.showOrderpop, false)
assert.equal(typeof pageConfig.openLowPriceOrderPrompt, 'function')
assert.equal(typeof pageConfig.onLowPriceOrderPromptConfirm, 'function')
assert.equal(
pageJson.usingComponents['order-prompt-pop'],
'/components/orderPromptPop/orderPromptPop'
)
assert.equal(
pageJson.usingComponents['recording-order-popup'],
'/tabIndex/components/recordingOrderPopup/recordingOrderPopup'
)
})
it('列表模板固定显示返回和新建低价单,不渲染扫码或旧悬浮箭头', async () => {
const [template, style, createIcon] = await Promise.all([
readFile('pages/tabWorkOrder/pages/index/index.wxml', 'utf8'),
readFile('pages/tabWorkOrder/pages/index/index.sass', 'utf8'),
readFile('images/new-low-price-order.png')
])
assert.match(
template,
/<navigation-bar\b[^>]*showBack="\{\{\s*true\s*\}\}"[^>]*bindback="handleBack"/
)
assert.match(
template,
/<page-container\b[^>]*bind:afterleave="closeFilter"/
)
assert.doesNotMatch(template, /data-flag="new"/)
assert.doesNotMatch(template, /bindtap="scan"/)
assert.doesNotMatch(template, /class="arrowIcon"/)
assert.doesNotMatch(template, /<order-prompt-popup\b/)
assert.match(template, /class="low-price-create"/)
assert.match(
template,
/<image\s+src="\/images\/new-low-price-order\.png"\s*\/>/
)
assert.match(template, /<order-prompt-pop\b/)
assert.match(template, /<recording-order-popup\b/)
assert.match(template, /low-price-mode="\{\{\s*true\s*\}\}"/)
assert.doesNotMatch(style, /\.fixed-btns\b|\.arrowIcon\b/)
assert.deepEqual(
[...createIcon.subarray(0, 8)],
[137, 80, 78, 71, 13, 10, 26, 10]
)
assert.equal(createIcon.readUInt32BE(16), 56)
assert.equal(createIcon.readUInt32BE(20), 56)
})
it('低价提单列表使用关键词搜索和专属卡片且不显示筛选按钮', async () => {
const [pageSource, template, style] = await Promise.all([
readFile('pages/tabWorkOrder/pages/index/index.js', 'utf8'),
readFile('pages/tabWorkOrder/pages/index/index.wxml', 'utf8'),
readFile('pages/tabWorkOrder/pages/index/index.sass', 'utf8')
])
assert.match(template, />\s*低价提单\s*<\/navigation-bar>/)
assert.match(template, /placeholder="关键词"/)
assert.doesNotMatch(template, /bindtap="showConfirm"/)
assert.doesNotMatch(template, /class="search-filter"/)
assert.match(template, /class="low-price-card-header"/)
assert.match(template, /class="low-price-card-row"/)
assert.match(template, /class="low-price-view"/)
for (const label of [
'订单类型',
'销售顾问',
'转化人员',
'工单编号',
'工单时间'
]) {
assert.match(template, new RegExp(`>${label}<`))
}
assert.match(pageSource, /lowPriceOrderTypeText\s*=\s*'低价订单'/)
assert.match(pageSource, /salesConsultantText/)
assert.match(pageSource, /conversionStaffText/)
assert.match(style, /\.low-price-card\b/)
assert.match(style, /\.low-price-view\b/)
})
})