From b8856194c45f4fcb61942ebc4e168a17779b84d7 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 31 Dec 2024 17:07:10 +0100 Subject: [PATCH] test: refs #7058 betaCard --- src/components/__tests__/Leftmenu.spec.js | 123 +++++++++++----------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/src/components/__tests__/Leftmenu.spec.js b/src/components/__tests__/Leftmenu.spec.js index 33d5dc17c..7b93b4da2 100644 --- a/src/components/__tests__/Leftmenu.spec.js +++ b/src/components/__tests__/Leftmenu.spec.js @@ -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('card').vm; - vm.getCardRoutes = vi.fn().mockReturnValue(() => vi.fn); + vm = mount('main').vm; + vi.spyOn(vm, 'getCardRoutes'); + vi.spyOn(vm, 'getMainRoutes'); + vm.getCardRoutes = vi.fn().mockReturnValue(vi.fn); + }); + beforeEach(() => { + vm.getMainRoutes = 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' },