storeSwitch.test.mjs 1.19 KB
/**
 * 精品切 4S 店 — 菜单/缓存补全单测
 *
 * 运行:npm run test:tabIndex
 * 用例前缀:IT-MENU-STORE-SWITCH-*
 */
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
import { invalidateSharedMenuApiCaches } from '../../utils/invalidateMenuApiCaches.js'
import {
	__setApiClientForTest,
	clearDailyReportNewVersionCache,
	fetchDailyReportNewVersionMenuVisible
} from '../../utils/dailyReportNewVersionGate.js'

describe('tabIndexStoreSwitch', () => {
	beforeEach(() => {
		clearDailyReportNewVersionCache()
	})

	afterEach(() => {
		clearDailyReportNewVersionCache()
		__setApiClientForTest(null)
	})

	it('IT-MENU-STORE-SWITCH-001: invalidateSharedMenuApiCaches clears daily report isNeed cache', async () => {
		let isNeedCalls = 0
		__setApiClientForTest({
			dailyReportNewVersionIsNeed: async () => {
				isNeedCalls++
				return { code: 0, data: true }
			}
		})
		await fetchDailyReportNewVersionMenuVisible('store-a')
		await fetchDailyReportNewVersionMenuVisible('store-a')
		assert.equal(isNeedCalls, 1)

		invalidateSharedMenuApiCaches()

		await fetchDailyReportNewVersionMenuVisible('store-a')
		assert.equal(isNeedCalls, 2)
	})
})