workspace-source-contract.test.mjs
3.63 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
import assert from 'node:assert/strict'
import { generate } from '@babel/generator'
import { parse } from '@babel/parser'
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, it } from 'node:test'
import { runInNewContext } from 'node:vm'
const testDir = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(testDir, '../..')
async function loadWorkspacePage() {
const pageSource = await readFile(
path.join(projectRoot, 'pages/tab/workspace/workspace.js'),
'utf8'
)
const ast = parse(pageSource, { sourceType: 'module' })
ast.program.body = ast.program.body.filter(
node => node.type !== 'ImportDeclaration'
)
let pageConfig
const navigations = []
const tracks = []
runInNewContext(generate(ast).code, {
Page(config) {
pageConfig = config
},
wx: {
$util: {
getUserInfo: () => ({ sceneType: 1 })
},
$track: {
setTrackData: (...args) => tracks.push(args)
},
$router: {
go: () => assert.fail('本地 path 不应调用公共路由器')
},
navigateTo: options => navigations.push(options)
}
})
return { pageConfig, navigations, tracks }
}
describe('工作台精品工单入口契约', () => {
it('门店运营管理隐藏新增工单菜单', async () => {
const [{ pageConfig }, templateSource] = await Promise.all([
loadWorkspacePage(),
readFile(
path.join(projectRoot, 'pages/tab/workspace/workspace.wxml'),
'utf8'
)
])
assert.equal(
pageConfig.data.storeManagementMenus.some(
item => item.name === '新增工单' || item.action === 'openWorkOrderPrompt'
),
false
)
assert.match(templateSource, /<order-prompt-pop/)
})
it('低价提单作为门店运营管理首个工单入口并直达已迁移列表页', async () => {
const { pageConfig, navigations, tracks } = await loadWorkspacePage()
const menus = pageConfig.data.storeManagementMenus
const lowPriceOrderIndex = menus.findIndex(
item => item.name === '低价提单'
)
assert.equal(lowPriceOrderIndex, 0)
assert.deepEqual(
JSON.parse(JSON.stringify(menus[lowPriceOrderIndex])),
{
name: '低价提单',
path: '/tabWorkOrder/pages/index/index',
iconUrl: '/images/low-price-order.png',
trackingCode: 'regional-assistant-customer-work-order'
}
)
pageConfig.jumpTo({
currentTarget: {
dataset: {
target: menus[lowPriceOrderIndex]
}
}
})
assert.deepEqual(
JSON.parse(JSON.stringify(navigations)),
[{ url: '/tabWorkOrder/pages/index/index' }]
)
assert.equal(tracks[0][1], 'regional-assistant-customer-work-order')
const icon = await readFile(
path.join(projectRoot, 'images/low-price-order.png')
)
assert.deepEqual([...icon.subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10])
assert.equal(icon.readUInt32BE(16), 72)
assert.equal(icon.readUInt32BE(20), 72)
})
it('工作台刷新不查询订单待审核或异常数量', async () => {
const { pageConfig } = await loadWorkspacePage()
let orderAuditQueries = 0
const page = {
...pageConfig,
data: JSON.parse(JSON.stringify(pageConfig.data)),
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
getWaitAuditCount() {},
getWaitStaff() {},
getWaitAudit() {
orderAuditQueries += 1
},
async checkServiceNotice() {}
}
await pageConfig.onShow.call(page)
assert.equal(orderAuditQueries, 0)
})
})