diff --git a/apps/web-antdv-next/src/api/core/menu.spec.ts b/apps/web-antdv-next/src/api/core/menu.spec.ts new file mode 100644 index 0000000..c770d6e --- /dev/null +++ b/apps/web-antdv-next/src/api/core/menu.spec.ts @@ -0,0 +1,66 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +const requestClientGet = vi.fn(); + +vi.mock('#/api/request', () => ({ + requestClient: { + get: requestClientGet, + }, +})); + +describe('core menu api', () => { + beforeEach(() => { + requestClientGet.mockReset(); + }); + + it('keeps supported dashboard routes from backend menus', async () => { + requestClientGet.mockResolvedValue([ + { + name: 'Dashboard', + path: '/dashboard', + redirect: '/analytics', + children: [ + { + name: 'Analytics', + path: '/analytics', + component: '/dashboard/analytics/index', + }, + { + name: 'Workspace', + path: '/workspace', + component: '/dashboard/workspace/index', + }, + ], + }, + { + name: 'Unsupported', + path: '/unsupported', + component: '/unsupported/index', + }, + ]); + + const { getAllMenusApi } = await import('./menu'); + const menus = await getAllMenusApi(); + + expect(requestClientGet).toHaveBeenCalledWith('/menu/all'); + expect(menus).toEqual([ + { + name: 'Dashboard', + path: '/dashboard', + redirect: '/analytics', + children: [ + { + name: 'Analytics', + path: '/analytics', + component: '/dashboard/analytics/index', + }, + { + name: 'Workspace', + path: '/workspace', + component: '/dashboard/workspace/index', + }, + ], + }, + ]); + }); +}); diff --git a/apps/web-antdv-next/src/api/core/menu.ts b/apps/web-antdv-next/src/api/core/menu.ts index 0783d4b..0b708e1 100644 --- a/apps/web-antdv-next/src/api/core/menu.ts +++ b/apps/web-antdv-next/src/api/core/menu.ts @@ -3,6 +3,7 @@ import type { RouteRecordStringComponent } from '@vben/types'; import { requestClient } from '#/api/request'; const SUPPORTED_ADMIN_MENU_NAMES = new Set([ + 'Analytics', 'Blog', 'BlogArticle', 'BlogArticleCreate', @@ -20,6 +21,7 @@ const SUPPORTED_ADMIN_MENU_NAMES = new Set([ 'BlogTheme', 'BlogThemeImport', 'BlogThemeSave', + 'Dashboard', 'Profile', 'QqBot', 'QqBotAccount', @@ -81,6 +83,7 @@ const SUPPORTED_ADMIN_MENU_NAMES = new Set([ 'SystemUserCreate', 'SystemUserDelete', 'SystemUserEdit', + 'Workspace', ]); export function isSupportedAdminMenuName(name?: null | string | symbol) {