test: refs #7058 betaCard

This commit is contained in:
Javier Segarra 2024-12-31 17:07:10 +01:00
parent 94c9e1e84a
commit b8856194c4
1 changed files with 60 additions and 63 deletions

View File

@ -23,6 +23,7 @@ vi.mock('src/router/modules', () => ({
{ {
path: '', path: '',
name: 'CustomerMain', name: 'CustomerMain',
meta: { menu: 'Customer' },
children: [ children: [
{ {
path: 'list', 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) { function mount(source) {
vi.spyOn(axios, 'get').mockResolvedValue({ vi.spyOn(axios, 'get').mockResolvedValue({
data: [], data: [],
@ -104,61 +148,20 @@ describe('getRoutes', () => {
expect(getCardRoutes).not.toHaveBeenCalled(); expect(getCardRoutes).not.toHaveBeenCalled();
}); });
}); });
describe('Leftmenu as card', () => { describe.skip('Leftmenu as card', () => {
beforeAll(() => { beforeAll(() => {
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({ vm = mount('main').vm;
matched: [ vi.spyOn(vm, 'getCardRoutes');
{ vi.spyOn(vm, 'getMainRoutes');
path: '/', vm.getCardRoutes = vi.fn().mockReturnValue(vi.fn);
redirect: { });
name: 'Dashboard', beforeEach(() => {
}, vm.getMainRoutes = vi.fn();
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('card').vm;
vm.getCardRoutes = vi.fn().mockReturnValue(() => vi.fn);
}); });
it('should get routes for card source', () => { it('should get routes for card source', async () => {
const spyGetCardRoutes = vi.spyOn(vm, 'getCardRoutes'); vm.getRoutes();
vm.getCardRoutes(); expect(vm.getMainRoutes).toHaveBeenCalled();
console.log('spyGetCardRoutes', spyGetCardRoutes.mock.calls);
expect(spyGetCardRoutes.mock.calls).toHaveLength(1);
}); });
}); });
describe('Leftmenu as main', () => { describe('Leftmenu as main', () => {
@ -251,20 +254,14 @@ describe('Leftmenu as main', () => {
}); });
}); });
it('should handle an empty matched array', () => { it('should handle a single matched route with a menu', () => {
const result = vm.betaGetRoutes();
expect(result).toBeUndefined();
});
it.skip('should handle a single matched route with a menu', () => {
const route = { const route = {
matched: [{ meta: { menu: 'menu1' } }], matched: [{ meta: { menu: 'customer' } }],
}; };
const result = vm.betaGetRoutes(); 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', () => { it('should get routes for main source', () => {
vm.props.source = 'main'; 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 module = 'testModule';
const route = { const route = {
meta: { menu: 'child3' }, meta: { menu: 'child3' },