staffDailyReportNavigation.test.mjs 2.41 KB
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'
		)
	})
})