/** * 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: '
', setup(_: unknown, { expose }: { expose: (api: Record) => void }) { expose({ reload: vi.fn(), saveAll: vi.fn().mockResolvedValue(true) }) }, } const BUTTON_STUBS = { ApiSecretSettingsPanel: panelStub } /** vitest 配置不挂 ElementPlusResolver ⇒ `` 是未知元素、命名插槽不渲染;弹窗用例本地挂替身。 */ const dialogStub = { props: ['modelValue', 'appendToBody'], template: '
', } 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: '' }, 'router-link': { template: '' }, ...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('代理设置') }) })