From 42f113ccf6029d1cdbec3608bd49d714ffb2d635 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 3 Jan 2025 15:48:53 +0100 Subject: [PATCH] test: refs #7058 getRoutes --- src/components/__tests__/Leftmenu.spec.js | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/components/__tests__/Leftmenu.spec.js b/src/components/__tests__/Leftmenu.spec.js index f38aec567..462a5cfd1 100644 --- a/src/components/__tests__/Leftmenu.spec.js +++ b/src/components/__tests__/Leftmenu.spec.js @@ -132,6 +132,48 @@ function mount(source) { return wrapper; } +describe('getRoutes', () => { + afterEach(() => vi.clearAllMocks()); + const getRoutes = vi.fn().mockImplementation((props, getMethodA, getMethodB) => { + const handleRoutes = { + methodA: getMethodA, + methodB: getMethodB, + }; + try { + handleRoutes[props.source](); + } catch (error) { + throw Error('Method not defined'); + } + }); + + const getMethodA = vi.fn(); + const getMethodB = vi.fn(); + const fn = (props) => getRoutes(props, getMethodA, getMethodB); + + it('should call getMethodB when source is card', () => { + let props = { source: 'methodB' }; + fn(props); + + expect(getMethodB).toHaveBeenCalled(); + expect(getMethodA).not.toHaveBeenCalled(); + }); + it('should call getMethodA when source is main', () => { + let props = { source: 'methodA' }; + fn(props); + + expect(getMethodA).toHaveBeenCalled(); + expect(getMethodB).not.toHaveBeenCalled(); + }); + //WIP + it('should call getMethodA when source is main', () => { + let props = { source: 'methodC' }; + expect(fn(props)).toThrowError('Method not defined'); + + expect(getMethodA).not.toHaveBeenCalled(); + expect(getMethodB).not.toHaveBeenCalled(); + }); +}); + describe('Leftmenu as card', () => { beforeAll(() => { vm = mount('card').vm; @@ -335,7 +377,7 @@ describe.only('addChildren', () => { expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); }); - it.only('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', menuChildren: [] },