feat(#142): group GoAuto admin navigation
This commit is contained in:
@@ -14,26 +14,52 @@ const modules = [
|
||||
['/ai-matching-settings', '/goauto/ai-matching-settings/index', 'GoAutoAiMatchingSettings', 'AI 规格匹配', 'setting']
|
||||
] as const
|
||||
|
||||
function menu(module: typeof modules[number]) {
|
||||
const menuGroups = [
|
||||
{
|
||||
path: '/collection-purchase',
|
||||
name: 'GoAutoCollectionPurchase',
|
||||
title: '采集采购',
|
||||
icon: 'shopping',
|
||||
modules: [modules[3], modules[5], modules[6], modules[2], modules[1], modules[8], modules[9]]
|
||||
},
|
||||
{
|
||||
path: '/collection-management',
|
||||
name: 'GoAutoCollectionManagement',
|
||||
title: '采采管理',
|
||||
icon: 'system',
|
||||
modules: [modules[4], modules[7], modules[0], modules[10]]
|
||||
}
|
||||
] as const
|
||||
|
||||
function childMenu(module: typeof modules[number]) {
|
||||
const [path, component, name, title, icon] = module
|
||||
return {
|
||||
path,
|
||||
component: 'Layout',
|
||||
path: `${path}/index`,
|
||||
component,
|
||||
visible: '0',
|
||||
menuName: `${name}Root`,
|
||||
menuName: name,
|
||||
title,
|
||||
icon,
|
||||
children: [{
|
||||
path: 'index',
|
||||
component,
|
||||
visible: '0',
|
||||
menuName: name,
|
||||
title,
|
||||
icon
|
||||
}]
|
||||
icon
|
||||
}
|
||||
}
|
||||
|
||||
function groupedMenus(visibleModules: typeof modules[number][]) {
|
||||
const allowed = new Set(visibleModules.map(module => module[2]))
|
||||
return menuGroups.flatMap(group => {
|
||||
const children = group.modules.filter(module => allowed.has(module[2])).map(childMenu)
|
||||
if (children.length === 0) return []
|
||||
return [{
|
||||
path: group.path,
|
||||
component: 'Layout',
|
||||
visible: '0',
|
||||
menuName: group.name,
|
||||
title: group.title,
|
||||
icon: group.icon,
|
||||
children
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
async function mockSession(page: any, role: 'admin' | 'purchaser', visibleModules: typeof modules[number][]) {
|
||||
await page.context().addCookies([{
|
||||
name: 'Admin-Token',
|
||||
@@ -48,28 +74,37 @@ async function mockSession(page: any, role: 'admin' | 'purchaser', visibleModule
|
||||
return route.fulfill({ json: { code: 200, data: { roles: [role], name: role, avatar: '', introduction: '', permissions: [] } } })
|
||||
}
|
||||
if (url.pathname.endsWith('/api/v1/menurole')) {
|
||||
return route.fulfill({ json: { code: 200, data: visibleModules.map(menu) } })
|
||||
return route.fulfill({ json: { code: 200, data: groupedMenus(visibleModules) } })
|
||||
}
|
||||
return route.fulfill({ json: { code: 200, data: [] } })
|
||||
})
|
||||
}
|
||||
|
||||
test('管理员菜单由服务端返回并包含全部 GoAuto 模块', async ({ page }) => {
|
||||
test('管理员深链接展开所属分组并保留全部 GoAuto 页面', async ({ page }) => {
|
||||
await mockSession(page, 'admin', [...modules])
|
||||
await page.goto('/#/dashboard')
|
||||
await page.goto('/#/pdd-products/index')
|
||||
|
||||
for (const module of modules) {
|
||||
await expect(page.locator('.sidebar-container').getByText(module[3], { exact: true }).first()).toBeVisible()
|
||||
}
|
||||
await expect(page).toHaveURL(/#\/pdd-products\/index$/)
|
||||
await expect(page.locator('.sidebar-container').getByText('采集采购', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('采采管理', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('PDD 商品', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container .is-active').getByText('PDD 商品', { exact: true })).toBeVisible()
|
||||
|
||||
await page.goto('/#/ai-matching-settings/index')
|
||||
await expect(page).toHaveURL(/#\/ai-matching-settings\/index$/)
|
||||
await expect(page.locator('.sidebar-container').getByText('AI 规格匹配', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container .is-active').getByText('AI 规格匹配', { exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('采购员只看到授权菜单且不能通过地址访问 AI 配置', async ({ page }) => {
|
||||
const purchaserModules = [modules[4], modules[9]]
|
||||
const purchaserModules = modules.filter(module => module[2] !== 'GoAutoAiMatchingSettings')
|
||||
await mockSession(page, 'purchaser', purchaserModules)
|
||||
await page.goto('/#/dashboard')
|
||||
await page.goto('/#/devices/index')
|
||||
|
||||
await expect(page.locator('.sidebar-container').getByText('采集采购', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('采采管理', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('SYB 店铺', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('采购管理', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('设备列表', { exact: true }).first()).toBeVisible()
|
||||
await expect(page.locator('.sidebar-container').getByText('AI 规格匹配', { exact: true })).toHaveCount(0)
|
||||
|
||||
await page.goto('/#/ai-matching-settings/index')
|
||||
|
||||
Reference in New Issue
Block a user