From a4f90225182f7cb8908bf97d35134cf53b70a1f5 Mon Sep 17 00:00:00 2001 From: Alireza Heidari Date: Thu, 9 Jan 2025 16:52:10 +0100 Subject: [PATCH] Refactors Workflow Editor tests Replaces 'any' type with 'Wrapper' for better type safety Removes redundant tests and properties Drop the not possible old tests --- .../components/Workflow/Editor/Index.test.ts | 72 +++---------------- 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/client/src/components/Workflow/Editor/Index.test.ts b/client/src/components/Workflow/Editor/Index.test.ts index 7262d2d72956..c97b30a405cf 100644 --- a/client/src/components/Workflow/Editor/Index.test.ts +++ b/client/src/components/Workflow/Editor/Index.test.ts @@ -1,8 +1,10 @@ import { expect, jest } from "@jest/globals"; import { createTestingPinia } from "@pinia/testing"; -import { shallowMount } from "@vue/test-utils"; +import { shallowMount, type Wrapper } from "@vue/test-utils"; import { PiniaVuePlugin, setActivePinia } from "pinia"; import { getLocalVue } from "tests/jest/helpers"; +import type Vue from "vue"; +import { nextTick } from "vue"; import { testDatatypesMapper } from "@/components/Datatypes/test_fixtures"; import { getAppRoot } from "@/onload/loadConfig"; @@ -30,7 +32,7 @@ const mockLoadWorkflow = loadWorkflow as jest.Mocked; const MockGetVersions = getVersions as jest.Mocked; describe("Index", () => { - let wrapper: any; // don't know how to add type hints here, see https://github.com/vuejs/vue-test-utils/issues/255 + let wrapper: Wrapper; beforeEach(() => { const testingPinia = createTestingPinia(); @@ -41,10 +43,7 @@ describe("Index", () => { MockGetVersions.mockResolvedValue([]); mockGetStateUpgradeMessages.mockImplementation(() => []); mockGetAppRoot.mockImplementation(() => "prefix/"); - Object.defineProperty(window, "onbeforeunload", { - value: null, - writable: true, - }); + wrapper = shallowMount(Index, { propsData: { workflowId: "workflow_id", @@ -53,70 +52,19 @@ describe("Index", () => { moduleSections: [], dataManagers: [], workflows: [], - toolbox: [], }, localVue, pinia: testingPinia, }); }); - async function resetChanges() { - wrapper.vm.hasChanges = false; - await wrapper.vm.$nextTick(); - } - - it("resolves datatypes", async () => { - expect(wrapper.datatypesMapper).not.toBeNull(); - expect(wrapper.datatypes).not.toBeNull(); - }); - - it("routes to download URL and respects Galaxy prefix", async () => { - Object.defineProperty(window, "location", { - value: "original", - writable: true, - }); - wrapper.vm.onDownload(); - expect(window.location).toBe("prefix/api/workflows/workflow_id/download?format=json-download"); + it("renders correctly", () => { + expect(wrapper.exists()).toBe(true); }); - it("tracks changes to annotations", async () => { - expect(wrapper.vm.hasChanges).toBeFalsy(); - wrapper.vm.annotation = "original annotation"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeTruthy(); - - resetChanges(); - - wrapper.vm.annotation = "original annotation"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeFalsy(); - - wrapper.vm.annotation = "new annotation"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeTruthy(); - }); - - it("tracks changes to name", async () => { - expect(wrapper.hasChanges).toBeFalsy(); - wrapper.vm.name = "original name"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeTruthy(); - - resetChanges(); - - wrapper.vm.name = "original name"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeFalsy(); - - wrapper.vm.name = "new name"; - await wrapper.vm.$nextTick(); - expect(wrapper.vm.hasChanges).toBeTruthy(); - }); + it("loads the workflow", async () => { + await nextTick(); - it("prevents navigation only if hasChanges", async () => { - expect(wrapper.vm.hasChanges).toBeFalsy(); - await wrapper.vm.onChange(); - const confirmationRequired = wrapper.emitted()["update:confirmation"][0][0]; - expect(confirmationRequired).toBeTruthy(); + expect(mockLoadWorkflow).toHaveBeenCalledWith({ id: "workflow_id", version: 1 }); }); });