test: refs #7058 betaCard
This commit is contained in:
parent
94c9e1e84a
commit
b8856194c4
|
@ -23,6 +23,7 @@ vi.mock('src/router/modules', () => ({
|
|||
{
|
||||
path: '',
|
||||
name: 'CustomerMain',
|
||||
meta: { menu: 'Customer' },
|
||||
children: [
|
||||
{
|
||||
path: 'list',
|
||||
|
@ -46,7 +47,50 @@ vi.mock('src/router/modules', () => ({
|
|||
},
|
||||
],
|
||||
}));
|
||||
|
||||
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
|
||||
matched: [
|
||||
{
|
||||
path: '/',
|
||||
redirect: {
|
||||
name: 'Dashboard',
|
||||
},
|
||||
name: 'Main',
|
||||
meta: {},
|
||||
props: {
|
||||
default: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: 'Dashboard',
|
||||
meta: {
|
||||
title: 'dashboard',
|
||||
icon: 'dashboard',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/customer',
|
||||
redirect: {
|
||||
name: 'CustomerMain',
|
||||
},
|
||||
name: 'Customer',
|
||||
meta: {
|
||||
title: 'customers',
|
||||
icon: 'vn:client',
|
||||
moduleName: 'Customer',
|
||||
keyBinding: 'c',
|
||||
menu: 'customer',
|
||||
},
|
||||
},
|
||||
],
|
||||
query: {},
|
||||
params: {},
|
||||
meta: { moduleName: 'mockName' },
|
||||
path: 'mockName/1',
|
||||
name: 'Customer',
|
||||
});
|
||||
function mount(source) {
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: [],
|
||||
|
@ -104,61 +148,20 @@ describe('getRoutes', () => {
|
|||
expect(getCardRoutes).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('Leftmenu as card', () => {
|
||||
describe.skip('Leftmenu as card', () => {
|
||||
beforeAll(() => {
|
||||
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
|
||||
matched: [
|
||||
{
|
||||
path: '/',
|
||||
redirect: {
|
||||
name: 'Dashboard',
|
||||
},
|
||||
name: 'Main',
|
||||
meta: {},
|
||||
props: {
|
||||
default: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: 'Dashboard',
|
||||
meta: {
|
||||
title: 'dashboard',
|
||||
icon: 'dashboard',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/customer',
|
||||
redirect: {
|
||||
name: 'CustomerMain',
|
||||
},
|
||||
name: 'Customer',
|
||||
meta: {
|
||||
title: 'customers',
|
||||
icon: 'vn:client',
|
||||
moduleName: 'Customer',
|
||||
keyBinding: 'c',
|
||||
},
|
||||
},
|
||||
],
|
||||
query: {},
|
||||
params: {},
|
||||
meta: { moduleName: 'mockName' },
|
||||
path: 'mockName/1',
|
||||
name: 'Customer',
|
||||
vm = mount('main').vm;
|
||||
vi.spyOn(vm, 'getCardRoutes');
|
||||
vi.spyOn(vm, 'getMainRoutes');
|
||||
vm.getCardRoutes = vi.fn().mockReturnValue(vi.fn);
|
||||
});
|
||||
beforeEach(() => {
|
||||
vm.getMainRoutes = vi.fn();
|
||||
});
|
||||
|
||||
vm = mount('card').vm;
|
||||
vm.getCardRoutes = vi.fn().mockReturnValue(() => vi.fn);
|
||||
});
|
||||
|
||||
it('should get routes for card source', () => {
|
||||
const spyGetCardRoutes = vi.spyOn(vm, 'getCardRoutes');
|
||||
vm.getCardRoutes();
|
||||
console.log('spyGetCardRoutes', spyGetCardRoutes.mock.calls);
|
||||
expect(spyGetCardRoutes.mock.calls).toHaveLength(1);
|
||||
it('should get routes for card source', async () => {
|
||||
vm.getRoutes();
|
||||
expect(vm.getMainRoutes).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('Leftmenu as main', () => {
|
||||
|
@ -251,20 +254,14 @@ describe('Leftmenu as main', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should handle an empty matched array', () => {
|
||||
const result = vm.betaGetRoutes();
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it.skip('should handle a single matched route with a menu', () => {
|
||||
it('should handle a single matched route with a menu', () => {
|
||||
const route = {
|
||||
matched: [{ meta: { menu: 'menu1' } }],
|
||||
matched: [{ meta: { menu: 'customer' } }],
|
||||
};
|
||||
|
||||
const result = vm.betaGetRoutes();
|
||||
|
||||
expect(result).toEqual(route.matched[0]);
|
||||
expect(result.meta.menu).toEqual(route.matched[0].meta.menu);
|
||||
});
|
||||
it('should get routes for main source', () => {
|
||||
vm.props.source = 'main';
|
||||
|
@ -345,7 +342,7 @@ describe.skip('addChildren', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it.skip('should not add menu items if no matches are found', () => {
|
||||
it('should not add menu items if no matches are found', () => {
|
||||
const module = 'testModule';
|
||||
const route = {
|
||||
meta: { menu: 'child3' },
|
||||
|
|
Loading…
Reference in New Issue