e139978f04
按需求摘掉 AmazonTopBar 的公司名胶囊,连带清掉随之死掉的 readCompanyIdentity import / companyName ref / onMounted 赋值与 .company-name 样式(留着会被 tests/dead-code-cleanup.test.ts 的 vue-tsc --noEmit 判红)。 公司身份机制与 companyName 载荷一律不动——那仍是登录/多租户判断的输入, 只是不再在顶栏显示。 补 tests/mount/amazon-topbar-no-company.mount.test.ts 三条真挂载用例: 公司名不进 DOM、同框用户名照旧出现(防"挂载失败"冒充"已摘掉")、 readCompanyIdentity 仍读得到。已做反向证伪:把胶囊塞回去第一条即红。 用户端实测:npm test 862 例 0 红;npx vitest run 19 例 0 红;vue-tsc --noEmit rc=0。
75 lines
3.1 KiB
TypeScript
75 lines
3.1 KiB
TypeScript
/**
|
||
* 亚马逊工具台顶栏的挂载用例:右上角不显示公司名(2026-10-17 需求「客户端的前端右上角不要显示公司」)。
|
||
*
|
||
* 三件事都要判,缺一条就是假绿:
|
||
* ① 公司名不进 DOM——localStorage 里明明有好端确认过的公司名,顶栏也不许渲染它;
|
||
* ② 正向对照——同一框里的用户名必须照旧出现。少了这条,"顶栏整个挂载失败"
|
||
* 与"公司名被摘掉了"在这支用例里同形,`.company-name` 查不到也能蒙过;
|
||
* ③ 身份机制没被拆——readCompanyIdentity 仍读得到那个值。公司名是登录/多租户判断的输入
|
||
* (check_login 与登录响应带下来,见 shared/auth/company-identity.ts),
|
||
* 本轮只是不再显示,不是不再持有。
|
||
*
|
||
* 跑法:cd frontend-vue && npx vitest run(tests/mount/** 由 vitest.config.ts 收,
|
||
* `npm test` 那支 node --test 的 glob 不递归,抓不到这里)。
|
||
*/
|
||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
|
||
import AmazonTopBar from '@/pages/amazon/components/AmazonTopBar.vue'
|
||
import { COMPANY_NAME_STORAGE_KEY, readCompanyIdentity } from '@/shared/auth/company-identity'
|
||
|
||
const permission = vi.hoisted(() => ({ getCurrentUserAppColumnKeys: vi.fn() }))
|
||
|
||
vi.mock('@/shared/api/permission', () => ({
|
||
getCurrentUserAppColumnKeys: permission.getCurrentUserAppColumnKeys,
|
||
}))
|
||
|
||
const COMPANY = '厦门米椿花'
|
||
const USER = '黄建新'
|
||
|
||
let wrapper: VueWrapper | null = null
|
||
|
||
async function mountTopBar() {
|
||
wrapper = mount(AmazonTopBar, {
|
||
global: {
|
||
// 顶栏右侧的铃铛与密钥入口各有自己的依赖树(轮询、面板),这里只关心顶栏本身的输出
|
||
stubs: { NotificationBell: true, BrandApiSecretSettingsButton: true, RouterLink: true, 'router-link': true },
|
||
},
|
||
})
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
describe('亚马逊工具台顶栏右上角', () => {
|
||
beforeEach(() => {
|
||
permission.getCurrentUserAppColumnKeys.mockResolvedValue([])
|
||
window.localStorage.setItem('username', USER)
|
||
window.localStorage.setItem(COMPANY_NAME_STORAGE_KEY, COMPANY)
|
||
})
|
||
|
||
afterEach(() => {
|
||
wrapper?.unmount()
|
||
wrapper = null
|
||
window.localStorage.clear()
|
||
})
|
||
|
||
it('localStorage 里有公司名时也不渲染公司名', async () => {
|
||
const w = await mountTopBar()
|
||
expect(w.find('.company-name').exists(), '公司名胶囊节点不得存在').toBe(false)
|
||
expect(w.text(), `顶栏文本里不应出现 ${COMPANY}`).not.toContain(COMPANY)
|
||
expect(w.html()).not.toContain('所属公司')
|
||
})
|
||
|
||
it('正向对照:同框的用户名照旧渲染(防"挂载失败"冒充"已摘掉")', async () => {
|
||
const w = await mountTopBar()
|
||
const adminName = w.find('.admin-name')
|
||
expect(adminName.exists(), '用户名节点必须还在,否则上一条的红/绿都无意义').toBe(true)
|
||
expect(adminName.text()).toBe(USER)
|
||
})
|
||
|
||
it('公司身份机制未被拆除:不显示但仍读得到', async () => {
|
||
await mountTopBar()
|
||
expect(readCompanyIdentity()).toBe(COMPANY)
|
||
})
|
||
})
|