Files
order_site/apps/frontend/tests/admin-worker-platform-tabs.test.ts
T

54 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict'
import test from 'node:test'
import {
WORKER_PLATFORM_NON_TAB_QUERY_KEYS,
WORKER_PLATFORM_TAB_KEYS,
WORKER_PLATFORM_TAB_QUERY_KEYS,
isWorkerPlatformTab,
} from '../src/utils/admin-worker-platform-tabs.ts'
/**
* 这组用例守住一个「不报错、不白屏,只是点了没反应」的坑:
* changeTab() 在 isWorkerPlatformTab() 返回 false 时直接 return,
* 于是 tab 渲染得出来却永远切不过去。生产上风控 tab 就这样失效过一次。
*/
test('风控 tab 必须被 isWorkerPlatformTab 接受(漏登记会导致点击无反应)', () => {
assert.equal(isWorkerPlatformTab('risk-control'), true)
})
test('对接客服 tab 必须被 isWorkerPlatformTab 接受,并登记切页刷新缓存', () => {
assert.equal(isWorkerPlatformTab('consignment-contacts'), true)
assert.deepEqual(WORKER_PLATFORM_TAB_QUERY_KEYS['consignment-contacts'], [
['admin-consignment-contacts'],
])
})
test('每个登记了切页缓存的 tab 都必须在合法 tab 名单里', () => {
const nonTabs = new Set(WORKER_PLATFORM_NON_TAB_QUERY_KEYS)
for (const key of Object.keys(WORKER_PLATFORM_TAB_QUERY_KEYS)) {
if (nonTabs.has(key)) continue
assert.ok(
isWorkerPlatformTab(key),
`"${key}" 登记了 WORKER_PLATFORM_TAB_QUERY_KEYS 却不在 WORKER_PLATFORM_TAB_KEYS 中 —— changeTab() 会直接 return,表现为点了没反应`,
)
}
})
test('合法 tab 名单无重复项', () => {
assert.equal(new Set(WORKER_PLATFORM_TAB_KEYS).size, WORKER_PLATFORM_TAB_KEYS.length)
})
test('非法 tab key 一律被拒(含 null 与空串)', () => {
for (const bad of ['', null, 'nope', 'riskcontrol', 'risk_control', 'hall-config']) {
assert.equal(isWorkerPlatformTab(bad), false, `${String(bad)} 不应被当作合法 tab`)
}
})
test('名单里的每个 key 都能被自身校验通过', () => {
for (const key of WORKER_PLATFORM_TAB_KEYS) {
assert.equal(isWorkerPlatformTab(key), true, `${key} 应可通过校验`)
}
})