navigation-baseline.test.mjs
5.04 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
import { describe, it, mock } from 'node:test'
import assert from 'node:assert/strict'
import {
loadMiniProgramDefinition,
loadSourceExports
} from './support/load-mini-program-source.mjs'
globalThis.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'release' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
getWindowInfo: () => ({
windowWidth: 375,
windowHeight: 667,
statusBarHeight: 20,
pixelRatio: 2,
screenWidth: 375,
screenHeight: 667,
safeArea: { top: 20, bottom: 667, height: 647 }
}),
getAppBaseInfo: () => ({
SDKVersion: '3.0.0',
host: 'WeChat',
version: '8.0.0',
language: 'zh_CN'
}),
$hasPermission: {
isSuper: () => false,
isNotMentor: () => true,
canSelectMultiStore: () => false,
canSelectMultiStoreForStaffDaily: () => false,
canViewMentorship: () => false,
canViewRecruit: () => false,
canViewViolation: () => false
}
}
globalThis.getApp = () => ({ globalData: { isStaff: true } })
const { resolveLegacyStaffDailyRoute } = await import('../../utils/staffDailyReportNavigation.js')
const {
AI_ROUTES,
AI_ROUTE_PATHS,
LEGACY_DAILY_REPORT_PATHS
} = await import('../../router/routeAliases.js')
const { EQUITY_MENU_REGISTRY, ASYNC_MENU_REGISTRY: EQUITY_ASYNC_MENUS } =
await import('../../packageEquity/menu/registry.js')
const { MENU_REGISTRY } = await import('../../tabIndex/menu/registry.js')
function findById(items, id) {
const item = items.find(candidate => candidate.id === id)
assert.ok(item, `menu not found: ${id}`)
return item
}
describe('subpackage split navigation baseline', () => {
it('keeps legacy staff report route selection by scene type', () => {
assert.deepEqual(resolveLegacyStaffDailyRoute({ sceneType: 0 }), {
type: 'router',
route: 'tabWorkOrder.staffDaily',
params: { scene: 0 }
})
assert.deepEqual(resolveLegacyStaffDailyRoute({ sceneType: 1 }), {
type: 'router',
route: 'tabWorkOrder.upgradeStaffDaily',
params: {}
})
})
for (const [source, menus] of [
['equity', EQUITY_MENU_REGISTRY],
['home', MENU_REGISTRY]
]) {
it(`${source} work report menus preserve type and reportTypeAttr`, () => {
const expected = [
['work_daily_report', 'daily', '1'],
['work_weekly_report', 'weekly', '2'],
['work_monthly_report', 'monthly', '3']
]
for (const [id, reportTypeAttr, reportTypeVal] of expected) {
const item = findById(menus, id)
assert.equal(item.action.type, 'workReport')
assert.equal(item.action.target, 'tabWorkOrder.supervisorDaily')
assert.equal(item.reportTypeAttr, reportTypeAttr)
assert.equal(item.reportTypeVal, reportTypeVal)
}
})
}
it('AI menu enters the current start alias', () => {
const item = findById(EQUITY_ASYNC_MENUS, 'ai_fun_practice')
assert.deepEqual(item.action, {
type: 'router',
target: 'packageEquityAI.aiCheckStart'
})
})
it('AI task reminder preserves staff and task query values', async () => {
const go = mock.fn()
const wxMock = {
getStorageSync: () => undefined,
setStorageSync: mock.fn(),
$util: { getUserInfo: () => ({ merchantId: 'merchant-1' }) },
$hasPermission: { canSelectMultiStore: () => false },
$router: { go },
__HAS_NOTLOGIN_MODAL: false
}
class TestDate extends Date {
format() { return '2026-09-04' }
}
const definition = await loadMiniProgramDefinition(
'packageEquity/pages/TabBar/equityPage.js',
{
wx: wxMock,
getApp: () => ({ globalData: { isStaff: true } }),
require: () => ({}),
Date: TestDate,
IMG_URL: 'https://static.example/',
carLifeApi: {
getSparringPage: async () => ({
data: {
list: [{
task: { aiType: 7, promptOnOff: true },
staff: { id: 'staff-9', tryCount: 1 }
}]
}
})
},
AI_ROUTES
}
)
await definition.checkTask.call({
addModalToQueue(_title, _content, _confirmText, _showCancel, _priority, callback) {
callback({ confirm: true })
}
})
assert.equal(
go.mock.calls[0].arguments[0],
'packageEquityAI.exerciseList?staffid=staff-9&tryCount=1&roleType=7&promptOnOff=true'
)
})
it('H5 scene mapping keeps report allowlist and AI login requirement', async () => {
const wxMock = {
$util: { getStorageSync: () => undefined },
$SCENE: null
}
const { checkScene } = await loadSourceExports('store/index.js', {
wx: wxMock,
console: { log() {}, error() {}, warn() {} },
getApp: () => ({ globalData: {} }),
api: {},
envIndex: 0,
removeSystemStorage: () => {},
util: { removeStorage: () => {} },
getSystemInfo: () => ({}),
AI_ROUTE_PATHS,
LEGACY_DAILY_REPORT_PATHS
})
for (const [page, path] of [
['staffDaily', 'packageDynamicForm/pages/staffDaily/staffDaily'],
['upgradeStaffDaily', 'packageDynamicForm/pages/upgradeStaffDaily/upgradeStaffDaily']
]) {
const options = { query: { page } }
assert.equal(checkScene(options), undefined)
assert.equal(options.path, path)
}
const aiOptions = { query: { page: 'aiDetail' } }
assert.equal(checkScene(aiOptions), '未登录,请登录。')
assert.equal(aiOptions.path, 'packageEquityAI/pages/aiCheck/exercise/ai/ai')
})
})