123 lines
3.0 KiB
TypeScript
123 lines
3.0 KiB
TypeScript
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',
|
|
},
|
|
{
|
|
name: 'QqBot',
|
|
path: '/qqbot',
|
|
children: [
|
|
{
|
|
name: 'QqBotAccount',
|
|
path: '/qqbot/account',
|
|
component: '/qqbot/account/list',
|
|
children: [
|
|
{
|
|
name: 'QqBotAccountWebUI',
|
|
authCode: 'QqBot:Account:WebUI',
|
|
type: 'button',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'QqBotAccountNapcatWebui',
|
|
path: '/qqbot/account/:accountId/napcat-webui',
|
|
component: '/qqbot/account/napcat-webui/index',
|
|
meta: {
|
|
activePath: '/qqbot/account',
|
|
hideInMenu: true,
|
|
title: 'NapCat WebUI',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
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',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'QqBot',
|
|
path: '/qqbot',
|
|
children: [
|
|
{
|
|
name: 'QqBotAccount',
|
|
path: '/qqbot/account',
|
|
component: '/qqbot/account/list',
|
|
children: [
|
|
{
|
|
name: 'QqBotAccountWebUI',
|
|
authCode: 'QqBot:Account:WebUI',
|
|
type: 'button',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'QqBotAccountNapcatWebui',
|
|
path: '/qqbot/account/:accountId/napcat-webui',
|
|
component: '/qqbot/account/napcat-webui/index',
|
|
meta: {
|
|
activePath: '/qqbot/account',
|
|
hideInMenu: true,
|
|
title: 'NapCat WebUI',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
});
|