router-integration.test.mjs
4.84 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
import { beforeEach, describe, it, mock } from 'node:test'
import assert from 'node:assert/strict'
import { resolveRoute } from '../../router/routeAliases.js'
import { loadSourceExports } from './support/load-mini-program-source.mjs'
const NEW_ROUTES = [
'/packageEquityAI/pages/aiCheck/start/start',
'/packageEquityAI/pages/aiCheck/chat/chat',
'/packageEquityAI/pages/aiCheck/exercise/list/list',
'/packageDynamicForm/pages/staffDaily/staffDaily',
'/packageDynamicForm/pages/upgradeStaffDaily/upgradeStaffDaily',
'/packageDynamicForm/pages/supervisorDaily/supervisorDaily'
].map(url => ({
url,
name: url.split('/').pop(),
parent: 'packageEquityAI',
isTab: false
}))
let Router
let wxBridge
let currentApp
beforeEach(async () => {
globalThis.__wxConfig = {}
wxBridge = { onAppRoute() {} }
currentApp = { globalData: {} }
const exports = await loadSourceExports('router/router.js', {
resolveRoute,
util: {
showToast() {},
showLoading() {},
hideLoading() {},
isFullSucreen: () => false,
getUserInfo: () => null
},
wx: wxBridge,
getCurrentPages: () => [],
getApp: () => currentApp,
console
})
Router = exports.__defaultExport
})
function createWxNavigation() {
const emitted = []
const navigateTo = mock.fn(options => {
options.success?.({
eventChannel: {
emit(name, payload) {
emitted.push({ name, payload })
}
}
})
})
return {
emitted,
wx: Object.assign(wxBridge, {
onAppRoute() {},
navigateTo,
redirectTo: mock.fn(),
reLaunch: mock.fn(),
switchTab: mock.fn()
})
}
}
describe('Router subpackage compatibility integration', () => {
it('go resolves a legacy alias, preserves query and emits EventChannel data', () => {
const navigation = createWxNavigation()
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
const events = { marker: 'event-channel' }
router.go('packageEquity.list?staffid=7&name=a%2Fb', events)
assert.equal(
navigation.wx.navigateTo.mock.calls[0].arguments[0].url,
'/packageEquityAI/pages/aiCheck/exercise/list/list?staffid=7&name=a%2Fb'
)
assert.deepEqual(navigation.emitted, [{ name: 'getData', payload: events }])
})
it('go rewrites a legacy absolute path', () => {
const navigation = createWxNavigation()
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
router.go('/packageEquity/pages/aiCheck/chat/chat?id=7')
assert.equal(
navigation.wx.navigateTo.mock.calls[0].arguments[0].url,
'/packageEquityAI/pages/aiCheck/chat/chat?id=7'
)
})
it('redirectTo and reLaunch share the same resolver', () => {
const navigation = createWxNavigation()
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
router.redirectTo('packageEquity.start?stage=lead')
router.reLaunch('/packageEquity/pages/aiCheck/chat/chat?id=8')
assert.equal(
navigation.wx.redirectTo.mock.calls[0].arguments[0].url,
'/packageEquityAI/pages/aiCheck/start/start?stage=lead'
)
assert.equal(
navigation.wx.reLaunch.mock.calls[0].arguments[0].url,
'/packageEquityAI/pages/aiCheck/chat/chat?id=8'
)
})
it('_to rewrites physical paths without changing global route data', () => {
const navigation = createWxNavigation()
const app = { globalData: {} }
currentApp = app
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
const events = { source: 'inspection' }
router._to(
'/packageEquity/pages/aiCheck/chat/chat?stage=lead',
events,
'navigateTo'
)
assert.equal(
navigation.wx.navigateTo.mock.calls[0].arguments[0].url,
'/packageEquityAI/pages/aiCheck/chat/chat?stage=lead'
)
assert.equal(app.globalData.ROUTE_QUERY, events)
})
it('daily report legacy alias preserves query and EventChannel data', () => {
const navigation = createWxNavigation()
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
const events = { source: 'modal-queue', reportDate: '2026-09-10' }
router.go('tabWorkOrder.staffDaily?scene=0&merchantId=m%2F1', events)
assert.equal(
navigation.wx.navigateTo.mock.calls[0].arguments[0].url,
'/packageDynamicForm/pages/staffDaily/staffDaily?scene=0&merchantId=m%2F1'
)
assert.deepEqual(navigation.emitted, [{ name: 'getData', payload: events }])
})
it('daily report legacy physical path works through redirectTo and reLaunch', () => {
const navigation = createWxNavigation()
globalThis.wx = navigation.wx
const router = new Router(NEW_ROUTES)
router.redirectTo('/tabWorkOrder/pages/upgradeStaffDaily/upgradeStaffDaily?date=1')
router.reLaunch('/tabWorkOrder/pages/supervisorDaily/supervisorDaily?type=weekly')
assert.equal(
navigation.wx.redirectTo.mock.calls[0].arguments[0].url,
'/packageDynamicForm/pages/upgradeStaffDaily/upgradeStaffDaily?date=1'
)
assert.equal(
navigation.wx.reLaunch.mock.calls[0].arguments[0].url,
'/packageDynamicForm/pages/supervisorDaily/supervisorDaily?type=weekly'
)
})
})