Files
crawler-plugin/frontend-vue/tests/mount/jd-secret-entry.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

98 lines
3.8 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.
/**
* 2026-11-22 京东工具台密钥设置入口的挂载契约:
* - JdConsolePage 头部 .top-right 真挂出「密钥设置」触发钮(头部不受权限过滤影响,恒在);
* - BrandApiSecretSettingsButton 把 showProxy=false 透传给面板(京东入口隐藏代理区)、
* 默认 true(亚马逊侧现有调用零变化)、隐藏代理时副标题不再提「代理设置」。
* 跑法:cd frontend-vue && npx vitest run tests/mount/jd-secret-entry.mount.test.ts
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
vi.mock('@/shared/api/permission', () => ({
getCurrentUserAppColumnKeys: vi.fn().mockResolvedValue(['jd_tools']),
}))
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue'
/** 面板替身:把收到的 showProxy 反到 DOM 上;expose 出按钮会调的 reload/saveAll。 */
const panelStub = {
props: ['showProxy'],
template: '<div class="panel-stub" :data-show-proxy="String(showProxy)" />',
setup(_: unknown, { expose }: { expose: (api: Record<string, unknown>) => void }) {
expose({ reload: vi.fn(), saveAll: vi.fn().mockResolvedValue(true) })
},
}
const BUTTON_STUBS = { ApiSecretSettingsPanel: panelStub }
/** vitest 配置不挂 ElementPlusResolver ⇒ `<el-dialog>` 是未知元素、命名插槽不渲染;弹窗用例本地挂替身。 */
const dialogStub = {
props: ['modelValue', 'appendToBody'],
template: '<div class="dialog-stub"><slot name="header" /><slot /><slot name="footer" /></div>',
}
let wrapper: VueWrapper | null = null
describe('京东工具台密钥设置入口(2026-11-22)', () => {
beforeEach(() => {
window.localStorage.setItem('username', 'admin')
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
window.localStorage.clear()
document.body.innerHTML = ''
})
it('JdConsolePage 头部 top-right 挂出触发钮(NotificationBell 与用户名之间)', async () => {
wrapper = mount(JdConsolePage, {
global: {
stubs: {
NotificationBell: true,
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
...BUTTON_STUBS,
},
},
})
await flushPromises()
const topRight = wrapper.find('.top-right')
expect(topRight.exists()).toBe(true)
expect(topRight.find('.secret-settings-trigger').exists()).toBe(true)
expect(topRight.text()).toContain('密钥设置')
})
it('按钮把 showProxy 透传给面板:京东入口 false、默认 true', () => {
const wFalse = mount(BrandApiSecretSettingsButton, {
props: { showProxy: false, variant: 'topbar' as const },
global: { stubs: { ...BUTTON_STUBS } },
})
expect(wFalse.find('.panel-stub').attributes('data-show-proxy')).toBe('false')
wFalse.unmount()
const wDefault = mount(BrandApiSecretSettingsButton, {
global: { stubs: { ...BUTTON_STUBS } },
})
expect(wDefault.find('.panel-stub').attributes('data-show-proxy')).toBe('true')
wDefault.unmount()
})
it('隐藏代理时副标题不再提「代理设置」', async () => {
wrapper = mount(BrandApiSecretSettingsButton, {
props: { showProxy: false },
global: {
components: { ElDialog: dialogStub },
stubs: { ...BUTTON_STUBS },
},
})
await wrapper.find('.secret-settings-trigger').trigger('click')
await flushPromises()
const subtitle = wrapper.find('.dialog-subtitle')
expect(subtitle.exists()).toBe(true)
expect(subtitle.text()).toContain('密钥保存在服务端并绑定当前账号')
expect(subtitle.text()).not.toContain('代理设置')
})
})