From 1caeda3dbdab4799a6c990c0d0345d0703cd895d Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 26 Mar 2024 17:55:44 -0500 Subject: [PATCH] fix `ToolPanel` jest failing due to `toolStore` not updating panel views --- .../src/components/Panels/ToolPanel.test.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/client/src/components/Panels/ToolPanel.test.js b/client/src/components/Panels/ToolPanel.test.js index 7b5575f251c9..c72dece594fe 100644 --- a/client/src/components/Panels/ToolPanel.test.js +++ b/client/src/components/Panels/ToolPanel.test.js @@ -1,12 +1,13 @@ import "jest-location-mock"; +import { createTestingPinia } from "@pinia/testing"; import { mount } from "@vue/test-utils"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import toolsList from "components/ToolsView/testData/toolsList"; import toolsListInPanel from "components/ToolsView/testData/toolsListInPanel"; import flushPromises from "flush-promises"; -import { createPinia } from "pinia"; +import { useToolStore } from "stores/toolStore"; import { getLocalVue } from "tests/jest/helpers"; import { useConfig } from "@/composables/config"; @@ -27,6 +28,22 @@ useConfig.mockReturnValue({ describe("ToolPanel", () => { it("test navigation of tool panel views menu", async () => { + const pinia = createTestingPinia(); + + const toolStore = useToolStore(); + toolStore.currentPanelView = "default"; + toolStore.panel["default"] = toolsListInPanel; + toolStore.panelViews = viewsList; + toolStore.toolsById = toolsList.reduce((acc, item) => { + acc[item.id] = item; + return acc; + }, {}); + + // mock implement setCurrentPanelView + toolStore.setCurrentPanelView = async (panelView) => { + toolStore.currentPanelView = panelView; + }; + const axiosMock = new MockAdapter(axios); axiosMock .onGet(/\/api\/tool_panels\/.*/) @@ -36,7 +53,6 @@ describe("ToolPanel", () => { .onGet(TEST_PANELS_URI) .reply(200, { default_panel_view: "default", views: viewsList }); - const pinia = createPinia(); const wrapper = mount(ToolPanel, { propsData: { workflow: false,