Files
crawler-plugin/frontend-vue/tests/mount/jd-console-permission.mount.test.ts
T
huangzd1997 6a52e24eb9 feat(web): 京东工具台三页头部加密钥设置入口(2026-11-22 用户口径「这边也要加密钥设置」,京东上架 AI 补值要读登录用户 LLM 密钥)
- BrandApiSecretSettingsButton 加可选 showProxy(默认 true,亚马逊侧现有调用零变化);透传面板既有 showProxy(708/771 行已按它条件保存/余额);副标题按 showProxy 派生(隐藏代理时不再提「代理设置保存在当前客户端」)
- JdConsolePage/JdCollectTab/JdPublishTab 头部 .top-right(铃铛与用户名之间)各插 <BrandApiSecretSettingsButton variant="topbar" :show-proxy="false"/>——京东特性无代理消费方,隐藏代理区防「没配代理影响京东采集吗」误判(铁律 27 同款)
- 弹窗/保存/检测/余额走既有 /newApi/api/user-secrets 链,零新端点零新权限 key
- 判据:jd-secret-entry.test.ts(三页头部精确匹配+按钮四钉)+jd-secret-entry.mount.test.ts(top-right 触发钮/showProxy 透传/副标题三用例);四支既有 JD mount 补 ApiSecretSettingsPanel stub 防真发 fetch(31 绿+mount 59 绿零噪声+vue-tsc rc=0)

随下一 app-web 窗上线
2026-11-22 21:51:45 +08:00

89 lines
3.5 KiB
TypeScript

/**
* 京东工作台卡片按 app 菜单权限(V209)显隐的挂载用例。
*
* 四态判据,与 AmazonConsolePage 同形:
* ① 组键 jd_tools 命中 ⇒ 两张卡都在(V209 预授权授的就是组行,线上默认形态);
* ② 只授 jd-collect ⇒ 只剩采集卡(上架占位同样受控,转正后行为不变);
* ③ 权限集与京东无关 ⇒ 两张卡都隐藏;
* ④ 权限接口异常 ⇒ 展示全部(现用人不因接口抖动丢功能)。
*
* 跑法:cd frontend-vue && npx vitest run tests/mount/jd-console-permission.mount.test.ts
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { mount, type VueWrapper } from '@vue/test-utils'
vi.mock('@/shared/api/permission', () => ({
getCurrentUserAppColumnKeys: vi.fn(),
}))
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
let wrapper: VueWrapper | null = null
const mockKeys = (keys: string[]) =>
vi.mocked(getCurrentUserAppColumnKeys).mockResolvedValue(keys)
async function mountConsole() {
wrapper = mount(JdConsolePage, {
global: {
stubs: {
NotificationBell: true,
// 2026-11-22 JD 页头部挂了密钥设置按钮:面板替身化,别在挂载用例里真发 /user-secrets fetch
ApiSecretSettingsPanel: true,
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
},
},
})
// onMounted 里权限是异步 await,等过滤落地后再断言
await vi.waitFor(() => {
expect(vi.mocked(getCurrentUserAppColumnKeys).mock.calls.length).toBeGreaterThan(0)
})
return wrapper
}
describe('京东工作台按菜单权限显隐(V209)', () => {
beforeEach(() => {
window.localStorage.setItem('username', 'admin')
vi.mocked(getCurrentUserAppColumnKeys).mockReset()
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
window.localStorage.clear()
})
it('组键命中 ⇒ 两张卡都在', async () => {
mockKeys(['jd_tools', 'jd-tools'])
const w = await mountConsole()
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(2))
})
it('只授 jd-collect ⇒ 只剩获取店铺数据卡', async () => {
mockKeys(['jd-collect'])
const w = await mountConsole()
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(1))
// 断言圈在卡片节点上:hero 文案("店铺采集 · 商品上架")与计数是页面静态区,
// 不参与权限过滤,拿整页 text() 判"商品上架消失"会误红。
const cards = w.findAll('.tool-card')
expect(cards[0].text()).toContain('获取店铺数据')
expect(cards.every((card) => !card.classes().includes('tool-card--pending'))).toBe(true)
expect(w.find('.group-count').text()).toContain('1 个工具')
})
it('权限集与京东无关 ⇒ 两张卡都隐藏', async () => {
mockKeys(['wb', 'collect-data'])
const w = await mountConsole()
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(0))
expect(w.findAll('.tool-card').length).toBe(0)
})
it('权限接口异常 ⇒ 展示全部(兜底不让现用人丢入口)', async () => {
vi.mocked(getCurrentUserAppColumnKeys).mockRejectedValue(new Error('获取菜单权限失败'))
const w = await mountConsole()
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(2))
})
})