feat(platform): 后管菜单平台隔离收窄+列表密度收口(2026-11-18 用户截图口径「密钥管理与密钥用量统计仅亚马逊侧;菜单配置展示树按当前平台先裁剪再展平分页」)——①双侧共用清单四件收窄:AdminMenuPlatformScope.BOTH_MENU_KEYS(后端唯一出处)与 admin platform-scope.ts BOTH_PLATFORM_MENU_KEYS 同源去掉 admin_user_secrets/admin_user_secret_usage,密钥两页京东侧不再下发也不可配;②菜单管理页:全树字典保留(授权数据不动),展示树与父级候选走 filterMenuTreeNodesByPlatform 先裁剪再展平分页,切平台清筛选回页1并关弹窗;③列表密度收口:顶栏 76→56、内容区留白 30/32→12/16、筛选行 flex 换行紧凑、表格行距 6px、按钮/输入 34px 同高,三档响应式断点(1440/820/560,窄屏菜单项不再整体隐藏);task-243 顶栏 56px 断言随行、task-244 新钉六条紧凑断言与「窄屏不许 display:none 菜单项」反向钉。判据:AdminMenuPlatformScopeTest 11+AdminConsoleCurrentUserMenusPlatformTest 3(后端点名绿)+vue-tsc rc0+node --test 35+npx vitest run 全量 188/188 rc0(新增 menu-manage-platform.mount 3 支:京东侧菜单配置页无亚马逊项、保留账号域四件与京东工具、密钥页归亚马逊)+快检 overall=pass 四面绿(2026-11-18 12:5x,Git PATH 前置壳)
This commit is contained in:
@@ -112,9 +112,10 @@ describe('AdminLayout × 平台锁定(2026-11-18)', () => {
|
||||
const texts = wrapper.findAll('.admin-menu .el-menu-item').map((item) => item.text())
|
||||
expect(texts).toContain('京东数据库')
|
||||
expect(texts).not.toContain('查询ASIN')
|
||||
// 双侧账号域照画(2026-11-18 扩双侧后含菜单权限配置/密钥管理/密钥用量统计)
|
||||
// 共用菜单配置保留,两个密钥入口仅亚马逊侧可见。
|
||||
expect(texts).toContain('菜单权限配置')
|
||||
expect(texts).toContain('密钥管理')
|
||||
expect(texts).not.toContain('密钥管理')
|
||||
expect(texts).not.toContain('密钥用量统计')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import ElementPlus from 'element-plus'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import MenusPage from '@/pages/account/MenusPage.vue'
|
||||
import type { MenuManageNode } from '@/pages/account/menu-manage-model'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
|
||||
const menuApi = vi.hoisted(() => ({
|
||||
loadMenuManageTree: vi.fn(),
|
||||
createMenu: vi.fn(),
|
||||
updateMenu: vi.fn(),
|
||||
deleteMenu: vi.fn(),
|
||||
reorderMenus: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/account/menu-manage-api', () => menuApi)
|
||||
|
||||
/** 同一次加载返回完整字典,平台隔离由真实页面完成。 */
|
||||
function mixedMenuTree(): MenuManageNode[] {
|
||||
let nextId = 1
|
||||
function node(
|
||||
columnKey: string,
|
||||
name: string,
|
||||
menuType: 'admin' | 'app',
|
||||
children: MenuManageNode[] = [],
|
||||
): MenuManageNode {
|
||||
const id = nextId++
|
||||
return {
|
||||
id, columnKey, name, menuType, parentId: null, routePath: '', sortOrder: id,
|
||||
children: children.map((child) => ({ ...child, parentId: id })),
|
||||
}
|
||||
}
|
||||
return [
|
||||
node('video_image', '视频图片', 'app'),
|
||||
node('admin_account', '账号与权限管理', 'admin', [
|
||||
node('admin_columns', '菜单权限管理', 'admin'),
|
||||
node('admin_users', '用户管理', 'admin'),
|
||||
node('admin_group_manage', '分组管理', 'admin'),
|
||||
node('admin_companies', '公司管理', 'admin'),
|
||||
node('admin_user_secrets', '密钥管理', 'admin'),
|
||||
node('admin_user_secret_usage', '密钥用量统计', 'admin'),
|
||||
]),
|
||||
node('admin_data', '数据管理', 'admin', [
|
||||
node('admin_shop_manage', '店铺管理', 'admin'),
|
||||
node('admin_appearance_patent', '外观专利管理', 'admin'),
|
||||
node('admin_similar_asin', '相似ASIN管理', 'admin'),
|
||||
node('admin_price_track', '跟价管理', 'admin'),
|
||||
node('admin_collect_data', '采集数据管理', 'admin'),
|
||||
node('admin_publish', '发布管理', 'admin'),
|
||||
node('admin_brand', '品牌管理', 'admin'),
|
||||
node('admin_records', '生成记录管理', 'admin'),
|
||||
node('admin_jd_database', '京东数据库', 'admin'),
|
||||
]),
|
||||
node('jd_tools', '京东工具台', 'app', [
|
||||
node('jd-collect', '京东店铺数据采集', 'app'),
|
||||
node('jd-publish', '京东商品上架', 'app'),
|
||||
]),
|
||||
]
|
||||
}
|
||||
|
||||
let pinia: Pinia
|
||||
let wrapper: VueWrapper<Element> | undefined
|
||||
let host: HTMLDivElement
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
window.localStorage.removeItem('admin-platform-tab')
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(7)
|
||||
menuApi.loadMenuManageTree.mockResolvedValue(mixedMenuTree())
|
||||
host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
host.remove()
|
||||
window.localStorage.removeItem('admin-platform-tab')
|
||||
})
|
||||
|
||||
async function mountMenus() {
|
||||
wrapper = mount(MenusPage, { attachTo: host, global: { plugins: [pinia, ElementPlus] } })
|
||||
await flushPromises()
|
||||
expect(menuApi.loadMenuManageTree).toHaveBeenCalledWith(7)
|
||||
return wrapper
|
||||
}
|
||||
|
||||
function visibleNames(page: VueWrapper<Element>) {
|
||||
return page.findAll('tbody .menu-name-text').map((cell) => cell.text())
|
||||
}
|
||||
|
||||
async function clickNextPage(page: VueWrapper<Element>) {
|
||||
const next = page.findAll('.old-pagination button').find((button) => button.text() === '下一页')
|
||||
expect(next).toBeTruthy()
|
||||
expect(next!.attributes('disabled')).toBeUndefined()
|
||||
await next!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 通过真实分页收齐表格行,避免只检查首屏而漏掉后页的跨平台菜单。 */
|
||||
async function allVisibleNames(page: VueWrapper<Element>) {
|
||||
const names = visibleNames(page)
|
||||
while (true) {
|
||||
const next = page.findAll('.old-pagination button').find((button) => button.text() === '下一页')
|
||||
if (!next || next.attributes('disabled') !== undefined) return names
|
||||
await clickNextPage(page)
|
||||
names.push(...visibleNames(page))
|
||||
}
|
||||
}
|
||||
|
||||
async function pickMenuType(page: VueWrapper<Element>, label: string) {
|
||||
const input = page.get('[aria-label="筛选菜单类型"]')
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const panel = contentId ? document.getElementById(contentId) : null
|
||||
expect(panel).toBeTruthy()
|
||||
const option = [...panel!.querySelectorAll('.el-select-dropdown__item')]
|
||||
.find((item) => !item.classList.contains('is-hidden') && item.textContent?.trim() === label)
|
||||
expect(option).toBeTruthy()
|
||||
await new DOMWrapper(option!).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('菜单权限配置页的平台隔离', () => {
|
||||
it('京东表格排除视频图片和密钥,保留账号基础菜单、数据管理祖先及京东工具', async () => {
|
||||
usePlatformTabStore().setActive('jd')
|
||||
const page = await mountMenus()
|
||||
|
||||
expect(await allVisibleNames(page)).toEqual([
|
||||
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
|
||||
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
|
||||
])
|
||||
const databaseRow = page.findAll('tbody tr')
|
||||
.find((row) => row.find('.menu-name-text').text() === '京东数据库')
|
||||
expect(databaseRow!.findAll('td')[4].text()).toBe('数据管理')
|
||||
expect(databaseRow!.find('.column-child-mark').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('从京东切回亚马逊,视频图片和密钥仍在,京东数据库及京东工具均消失', async () => {
|
||||
usePlatformTabStore().setActive('jd')
|
||||
const page = await mountMenus()
|
||||
usePlatformTabStore().setActive('amazon')
|
||||
await flushPromises()
|
||||
|
||||
expect(await allVisibleNames(page)).toEqual([
|
||||
'视频图片', '账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
|
||||
'密钥管理', '密钥用量统计', '数据管理', '店铺管理', '外观专利管理',
|
||||
'相似ASIN管理', '跟价管理', '采集数据管理', '发布管理', '品牌管理', '生成记录管理',
|
||||
])
|
||||
expect(menuApi.loadMenuManageTree).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('带名称和类型筛选进入第二页后切平台,回到第一页并清空两项筛选', async () => {
|
||||
const page = await mountMenus()
|
||||
const nameInput = page.get<HTMLInputElement>('input[placeholder="输入菜单名称"]')
|
||||
await nameInput.setValue('管理')
|
||||
await pickMenuType(page, '后台')
|
||||
expect(page.findAll('.menus-filter-row .el-select__selected-item').map((item) => item.text())).toContain('后台')
|
||||
expect(page.findAll('tbody .menu-type-text').every((cell) => cell.text() === '后台')).toBe(true)
|
||||
await clickNextPage(page)
|
||||
expect(page.get('.page-cur').text()).toBe('第 2 / 2 页')
|
||||
expect(visibleNames(page).length).toBeGreaterThan(0)
|
||||
expect(visibleNames(page).every((name) => name.includes('管理'))).toBe(true)
|
||||
|
||||
usePlatformTabStore().setActive('jd')
|
||||
await flushPromises()
|
||||
|
||||
expect(nameInput.element.value).toBe('')
|
||||
expect(page.findAll('.menus-filter-row .el-select__selected-item').map((item) => item.text())).toContain('全部')
|
||||
expect(page.get('.page-cur').text()).toBe('第 1 / 1 页')
|
||||
expect(page.get('.page-total').text()).toBe('共 10 条')
|
||||
expect(visibleNames(page)).toEqual([
|
||||
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
|
||||
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
|
||||
])
|
||||
expect(menuApi.loadMenuManageTree).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user