staffDailyReportNavigation.test.mjs
2.41 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
import { describe, it, mock } from 'node:test'
import assert from 'node:assert/strict'
const wxMock = {
navigateTo: mock.fn(),
$router: { go: mock.fn() },
$util: { getUserInfo: () => ({ sceneType: 1, shopMerchantId: '100' }) },
$hasPermission: {
canSelectMultiStore: () => false,
canSelectMultiStoreForStaffDaily: () => false
}
}
global.wx = wxMock
global.getApp = () => ({ globalData: { isStaff: true } })
const gate = await import('../../utils/dailyReportNewVersionGate.js')
const nav = await import('../../utils/staffDailyReportNavigation.js')
describe('staffDailyReportNavigation', () => {
it('navigateToRequiredDailyReport uses store page when isNeed=true', async () => {
gate.clearDailyReportNewVersionCache()
gate.__setApiClientForTest({
dailyReportNewVersionIsNeed: async () => ({ code: 0, data: true })
})
wxMock.navigateTo.mock.resetCalls()
wxMock.$router.go.mock.resetCalls()
const result = await nav.navigateToRequiredDailyReport({
userInfo: { sceneType: 1, shopMerchantId: '100' },
reportDate: '2026-08-10'
})
assert.equal(wxMock.navigateTo.mock.calls.length, 1)
assert.match(result.url, /storeDailyReport/)
assert.match(result.url, /reportDate=2026-08-10/)
assert.equal(wxMock.$router.go.mock.calls.length, 0)
gate.__setApiClientForTest(null)
})
it('navigateToStaffDailyReport remains an alias for navigateToRequiredDailyReport', () => {
assert.equal(nav.navigateToStaffDailyReport, nav.navigateToRequiredDailyReport)
})
it('navigateToStaffDailyReport uses legacy route when isNeed=false', async () => {
gate.clearDailyReportNewVersionCache()
gate.__setApiClientForTest({
dailyReportNewVersionIsNeed: async () => ({ code: 0, data: false })
})
wxMock.navigateTo.mock.resetCalls()
wxMock.$router.go.mock.resetCalls()
await nav.navigateToStaffDailyReport({
userInfo: { sceneType: 0, shopMerchantId: '100' },
reportDate: '2026-06-14'
})
assert.equal(wxMock.$router.go.mock.calls.length, 1)
assert.equal(wxMock.$router.go.mock.calls[0].arguments[0], 'tabWorkOrder.staffDaily')
assert.equal(wxMock.navigateTo.mock.calls.length, 0)
gate.__setApiClientForTest(null)
})
it('resolveLegacyStaffDailyRoute branches by sceneType', () => {
assert.equal(
nav.resolveLegacyStaffDailyRoute({ sceneType: 0 }).route,
'tabWorkOrder.staffDaily'
)
assert.equal(
nav.resolveLegacyStaffDailyRoute({ sceneType: 1 }).route,
'tabWorkOrder.upgradeStaffDaily'
)
})
})