20260913231607
This commit is contained in:
1 parent
f3ad727f1c
commit
c31329d387
179 files changed
+10846
-2684
No files matched your search
@@ -10,40 +10,33 @@ vi.mock('@/services/api', () => ({
|
||||
|
||||
import { loadDataApi } from '@/services/api'
|
||||
|
||||
// 模块中心等系统管理员专用页面不进 s_menu(入口固定在 AppSidebar、路由层 adminOnly 拦截),
|
||||
// 因此这里用业务菜单构造数据,验证菜单 store 本身无任何编码/账号特判。
|
||||
const mockMenus = [
|
||||
{
|
||||
b_id: '1',
|
||||
b_code: 'sys',
|
||||
b_name: '系统',
|
||||
b_code: 'base',
|
||||
b_name: '基础数据',
|
||||
b_menu_type: 'directory',
|
||||
b_parent_id: null,
|
||||
b_canuse: 1,
|
||||
},
|
||||
{
|
||||
b_id: '2',
|
||||
b_code: 'module',
|
||||
b_name: '模块管理',
|
||||
b_code: 'contact',
|
||||
b_name: '往来单位',
|
||||
b_menu_type: 'page',
|
||||
b_parent_id: '1',
|
||||
b_route: '/module/module-management',
|
||||
b_route: '/base/contact',
|
||||
b_canuse: 1,
|
||||
},
|
||||
{
|
||||
// 没有任何子项的目录:可见性裁剪后不应渲染
|
||||
b_id: '3',
|
||||
b_code: 'menu',
|
||||
b_name: '菜单管理',
|
||||
b_menu_type: 'page',
|
||||
b_parent_id: '1',
|
||||
b_route: '/module/menu-management',
|
||||
b_canuse: 1,
|
||||
},
|
||||
{
|
||||
b_id: '4',
|
||||
b_code: 'i18n',
|
||||
b_name: '多语言类型',
|
||||
b_menu_type: 'page',
|
||||
b_parent_id: '1',
|
||||
b_route: '/module/i18n-type',
|
||||
b_code: 'empty-dir',
|
||||
b_name: '空目录',
|
||||
b_menu_type: 'directory',
|
||||
b_parent_id: null,
|
||||
b_canuse: 1,
|
||||
},
|
||||
]
|
||||
@@ -81,7 +74,7 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('menus store(s_menu 动态菜单)', () => {
|
||||
it('普通用户:隐藏编码 module 的菜单(含空目录剪枝)', async () => {
|
||||
it('普通用户:全部启用菜单按树渲染,空目录剪枝(无编码特判)', async () => {
|
||||
mockSModuleData(mockMenus)
|
||||
setUser('u1', 123)
|
||||
await flush()
|
||||
@@ -89,32 +82,24 @@ describe('menus store(s_menu 动态菜单)', () => {
|
||||
await menus.load()
|
||||
|
||||
const codes = collectCodes(menus.visibleMenus)
|
||||
expect(codes).toContain('sys')
|
||||
expect(codes).toContain('menu')
|
||||
expect(codes).toContain('i18n')
|
||||
expect(codes).not.toContain('module')
|
||||
expect(codes).toContain('base')
|
||||
expect(codes).toContain('contact')
|
||||
// 目录没有可见子菜单时不渲染
|
||||
expect(codes).not.toContain('empty-dir')
|
||||
})
|
||||
|
||||
it('普通用户:目录下仅剩 module 子项时,目录整体不渲染', async () => {
|
||||
// 系统目录下只有「模块管理」这一个可用子菜单
|
||||
mockSModuleData(mockMenus.filter((m) => m.b_code !== 'menu' && m.b_code !== 'i18n'))
|
||||
setUser('u1', 123)
|
||||
await flush()
|
||||
const menus = useMenuStore()
|
||||
await menus.load()
|
||||
|
||||
expect(menus.visibleMenus).toEqual([])
|
||||
})
|
||||
|
||||
it('g3soft:module 菜单可见', async () => {
|
||||
it('管理员特判不在菜单 store:g3soft 与普通用户渲染一致', async () => {
|
||||
// 模块中心的管控在路由守卫(meta.adminOnly)与侧栏渲染(仅 g3soft 追加固定入口),
|
||||
// 菜单 store 对所有登录主体一视同仁
|
||||
mockSModuleData(mockMenus)
|
||||
setUser('g3soft', 1)
|
||||
await flush()
|
||||
const menus = useMenuStore()
|
||||
await menus.load()
|
||||
|
||||
expect(menus.isG3soft).toBe(true)
|
||||
expect(collectCodes(menus.visibleMenus)).toContain('module')
|
||||
const codes = collectCodes(menus.visibleMenus)
|
||||
expect(codes).toHaveLength(2)
|
||||
expect(codes).toEqual(expect.arrayContaining(['base', 'contact']))
|
||||
})
|
||||
|
||||
it('同一主体重复 load 不重复发请求', async () => {
|
||||
|
||||
Reference in new issue
Block a user