Skip to content

Commit

Permalink
Refactors Workflow Editor tests
Browse files Browse the repository at this point in the history
Replaces 'any' type with 'Wrapper<Vue>' for better type safety
Removes redundant tests and properties
Drop the not possible old tests
  • Loading branch information
itisAliRH committed Jan 9, 2025
1 parent 5c0b8f9 commit a4f9022
Showing 1 changed file with 10 additions and 62 deletions.
72 changes: 10 additions & 62 deletions client/src/components/Workflow/Editor/Index.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -30,7 +32,7 @@ const mockLoadWorkflow = loadWorkflow as jest.Mocked<typeof loadWorkflow>;
const MockGetVersions = getVersions as jest.Mocked<typeof getVersions>;

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<Vue>;

beforeEach(() => {
const testingPinia = createTestingPinia();
Expand All @@ -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",
Expand All @@ -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 });
});
});

0 comments on commit a4f9022

Please sign in to comment.