diff --git a/src/components/__tests__/Leftmenu.spec.js b/src/components/__tests__/Leftmenu.spec.js index 6adabedd5..33d5dc17c 100644 --- a/src/components/__tests__/Leftmenu.spec.js +++ b/src/components/__tests__/Leftmenu.spec.js @@ -1,4 +1,4 @@ -import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest'; +import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest'; import { createWrapper, axios } from 'app/test/vitest/helper'; import Leftmenu from 'components/LeftMenu.vue'; import * as vueRouter from 'vue-router'; @@ -72,6 +72,38 @@ function mount(source) { return wrapper; } +describe('getRoutes', () => { + afterEach(() => vi.clearAllMocks()); + const getRoutes = vi + .fn() + .mockImplementation((props, getMainRoutes, getCardRoutes) => { + const handleRoutes = { + main: getMainRoutes, + card: getCardRoutes, + }; + console.log(props.source); + handleRoutes[props.source](); + }); + + const getMainRoutes = vi.fn(); + const getCardRoutes = vi.fn(); + it('should call getCardRoutes when source is card', () => { + let props = { source: 'card' }; + + getRoutes(props, getMainRoutes, getCardRoutes); + + expect(getCardRoutes).toHaveBeenCalled(); + expect(getMainRoutes).not.toHaveBeenCalled(); + }); + it('should call getMainRoutes when source is main', () => { + let props = { source: 'main' }; + + getRoutes(props, getMainRoutes, getCardRoutes); + + expect(getMainRoutes).toHaveBeenCalled(); + expect(getCardRoutes).not.toHaveBeenCalled(); + }); +}); describe('Leftmenu as card', () => { beforeAll(() => { vi.spyOn(vueRouter, 'useRoute').mockReturnValue({ @@ -133,33 +165,7 @@ describe('Leftmenu as main', () => { beforeAll(() => { vm = mount('main').vm; }); - // WIP - it.skip('should call getMainRoutes when source is main', () => { - vm.getRoutes = vi - .fn() - .mockImplementation((props, getMainRoutes, getCardRoutes) => { - const handleRoutes = { - main: getMainRoutes, - card: getCardRoutes, - }; - console.log(props.source); - handleRoutes[props.source](); - }); - let props = { source: 'main' }; - const getMainRoutes = vi.fn(); - const getCardRoutes = vi.fn(); - vm.getRoutes(props, getMainRoutes, getCardRoutes); - - expect(getMainRoutes).toHaveBeenCalled(); - expect(getCardRoutes).not.toHaveBeenCalled(); - props = { source: 'card' }; - - vm.getRoutes(props, getMainRoutes, getCardRoutes); - - expect(getCardRoutes).toHaveBeenCalled(); - expect(getMainRoutes).not.toHaveBeenCalled(); - }); it('should return a proper formated object with two child items', async () => { const expectedMenuItem = [ {