Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate WorkflowEditor to TypeScript #19246

Draft
wants to merge 10 commits into
base: dev
Choose a base branch
from
7 changes: 3 additions & 4 deletions client/src/components/License/LicenseSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@ import License from "@/components/License/License.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";

const defaultLicense: LicenseType = {
licenseId: null,
name: "*Do not specify a license.*",
};

type LicenseMetadataModel = components["schemas"]["LicenseMetadataModel"];
type LicenseType = {
licenseId: string | null;
licenseId?: string;
name: string;
};

interface Props {
inputLicense: string;
inputLicense?: string;
}

const props = defineProps<Props>();

const emit = defineEmits<{
(e: "onLicense", license: string | null): void;
(e: "onLicense", license?: string): void;
}>();

const licensesLoading = ref(false);
Expand Down
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 });
});
});
Loading
Loading