Skip to content

Commit e71ca71

Browse files
committed
Add mount helper to work around vuejs/vue-test-utils#1578
Workflow test conversion, they pass. A few chatty bits to clean up. Make unit test galaxy object access quieter.
1 parent 9642cf8 commit e71ca71

File tree

12 files changed

+64
-56
lines changed

12 files changed

+64
-56
lines changed

client/src/app/monitor.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { getGalaxyInstance, setGalaxyInstance } from "app";
66
import { getAppRoot } from "onload/loadConfig";
77
import { serverPath } from "utils/serverPath";
8+
import config from "config";
89

910
const galaxyStub = {
1011
root: getAppRoot(),
@@ -15,7 +16,9 @@ if (!window.Galaxy) {
1516
Object.defineProperty(window, "Galaxy", {
1617
enumerable: true,
1718
get: function () {
18-
console.warn("accessing (get) window.Galaxy", serverPath());
19+
if (!config.testBuild === true) {
20+
console.warn("accessing (get) window.Galaxy", serverPath());
21+
}
1922
return getGalaxyInstance() || galaxyStub;
2023
},
2124
set: function (newValue) {

client/src/components/DataDialog/DataDialog.test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Model } from "./model";
55
import { UrlTracker } from "./utilities";
66
import { Services } from "./services";
77
import { mount, createLocalVue } from "@vue/test-utils";
8+
import { getNewAttachNode } from "jest/helpers";
89

910
const mockOptions = {
1011
callback: () => {},
@@ -132,13 +133,9 @@ describe("DataDialog.vue", () => {
132133
"root";
133134
});
134135
const localVue = createLocalVue();
135-
const attachElement = document.createElement("div");
136-
if (document.body) {
137-
document.body.appendChild(attachElement);
138-
}
139136
wrapper = mount(DataDialog, {
140137
propsData: mockOptions,
141-
attachTo: attachElement,
138+
attachTo: getNewAttachNode(),
142139
localVue,
143140
});
144141
});

client/src/components/Masthead/Masthead.test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { default as Masthead, __RewireAPI__ as rewire } from "./Masthead.vue";
22
import { mount, createLocalVue } from "@vue/test-utils";
33
import Scratchbook from "layout/scratchbook";
4+
import { getNewAttachNode } from "jest/helpers";
45

56
describe("Masthead.vue", () => {
67
let wrapper;
@@ -75,18 +76,14 @@ describe("Masthead.vue", () => {
7576
frame: scratchbook,
7677
};
7778

78-
const attachElement = document.createElement("div");
79-
if (document.body) {
80-
document.body.appendChild(attachElement);
81-
}
8279
wrapper = mount(Masthead, {
8380
propsData: {
8481
mastheadState,
8582
activeTab,
8683
appRoot: "prefix/",
8784
},
8885
localVue,
89-
attachTo: attachElement,
86+
attachTo: getNewAttachNode(),
9087
});
9188
});
9289

client/src/components/Masthead/MastheadItem.test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MastheadItem from "./MastheadItem.vue";
22
import { mount, createLocalVue } from "@vue/test-utils";
3+
import { getNewAttachNode } from "jest/helpers";
34

45
describe("Masthead.vue", () => {
56
let wrapper;
@@ -17,18 +18,13 @@ describe("Masthead.vue", () => {
1718
menu: menu,
1819
};
1920

20-
const attachElement = document.createElement("div");
21-
if (document.body) {
22-
document.body.appendChild(attachElement);
23-
}
24-
2521
return mount(MastheadItem, {
2622
propsData: {
2723
tab,
2824
activeTab: active,
2925
},
3026
localVue,
31-
attachTo: attachElement,
27+
attachTo: getNewAttachNode(),
3228
});
3329
}
3430

client/src/components/Upload/testHelpers.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from "underscore";
22
import Backbone from "backbone";
33
import "utils/uploadbox";
44
import { mount, createLocalVue } from "@vue/test-utils";
5+
import { getNewAttachNode } from "jest/helpers";
56

67
export function mountWithApp(component, options = {}, propsData_ = {}) {
78
const app = _.defaults(options, {
@@ -33,14 +34,10 @@ export function mountWithApp(component, options = {}, propsData_ = {}) {
3334
});
3435
const propsData = _.defaults(propsData_, { app });
3536
const localVue = createLocalVue();
36-
const attachElement = document.createElement("div");
37-
if (document.body) {
38-
document.body.appendChild(attachElement);
39-
}
4037
const wrapper = mount(component, {
4138
propsData,
4239
localVue,
43-
attachTo: attachElement,
40+
attachTo: getNewAttachNode(),
4441
stubs: {
4542
select2: true,
4643
},

client/src/components/User/CloudAuth/CloudAuth.test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import BootstrapVue from "bootstrap-vue";
1111

1212
// test data
1313
import listCredentials from "./testdata/listCredentials.json";
14+
import { getNewAttachNode } from "jest/helpers";
1415

1516
const localVue = createLocalVue();
1617
localVue.use(BootstrapVue);
@@ -29,12 +30,7 @@ describe("CloudAuth component", () => {
2930
beforeEach(async () => {
3031
const creds = listCredentials.map(Credential.create);
3132
stub = sinon.stub(mockSvc, "listCredentials").resolves(creds);
32-
const attachElement = document.createElement("div");
33-
if (document.body) {
34-
document.body.appendChild(attachElement);
35-
}
36-
37-
wrapper = shallowMount(CloudAuth, { localVue, attachTo: attachElement });
33+
wrapper = shallowMount(CloudAuth, { localVue, attachTo: getNewAttachNode() });
3834
await flushPromises();
3935
});
4036

client/src/components/Workflow/Editor/Attributes.mocha.js renamed to client/src/components/Workflow/Editor/Attributes.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe("Attributes", () => {
2525
},
2626
});
2727
const name = wrapper.find("#workflow-name");
28-
expect(name.element.value).to.equal("workflow_name");
28+
expect(name.element.value).toBe("workflow_name");
2929
wrapper.setProps({ name: "new_workflow_name" });
3030
await Vue.nextTick();
31-
expect(name.element.value).to.equal("new_workflow_name");
31+
expect(name.element.value).toBe("new_workflow_name");
3232
const parameters = wrapper.findAll(".list-group-item");
33-
expect(parameters.length).to.equal(2);
34-
expect(parameters.at(0).text()).to.equal("1: workflow_parameter_0");
35-
expect(parameters.at(1).text()).to.equal("2: workflow_parameter_1");
33+
expect(parameters.length).toBe(2);
34+
expect(parameters.at(0).text()).toBe("1: workflow_parameter_0");
35+
expect(parameters.at(1).text()).toBe("2: workflow_parameter_1");
3636
});
3737
});
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import Vue from "vue";
22
import { mount } from "@vue/test-utils";
33
import Node from "./Node";
4+
import { setupTestGalaxy } from "qunit/test-app";
5+
import { getNewAttachNode } from "jest/helpers";
46

57
describe("Node", () => {
8+
beforeEach(() => {
9+
// TODO: Move setupTestGalaxy to a single pretest setup, mock, or fix all the test requiring it.
10+
setupTestGalaxy();
11+
});
12+
13+
setupTestGalaxy();
614
it("test attributes", async () => {
715
const wrapper = mount(Node, {
816
propsData: {
@@ -13,17 +21,18 @@ describe("Node", () => {
1321
getManager: () => {},
1422
getCanvasManager: () => {},
1523
},
24+
attachTo: getNewAttachNode(),
1625
});
1726
const icon = wrapper.findAll("i");
18-
expect(icon.at(2).classes()).to.contain("fa-wrench");
27+
expect(icon.at(2).classes()).toEqual(expect.arrayContaining(["fa-wrench"]));
1928
const toolLinks = wrapper.findAll("i");
20-
expect(toolLinks.length).to.equal(3);
29+
expect(toolLinks.length).toBe(3);
2130
wrapper.setProps({ type: "subworkflow" });
2231
await Vue.nextTick();
23-
expect(icon.at(2).classes()).to.contain("fa-sitemap");
32+
expect(icon.at(2).classes()).toEqual(expect.arrayContaining(["fa-sitemap"]));
2433
const subworkflowLinks = wrapper.findAll("i");
25-
expect(subworkflowLinks.length).to.equal(2);
34+
expect(subworkflowLinks.length).toBe(2);
2635
const workflowTitle = wrapper.find(".node-title");
27-
expect(workflowTitle.text()).to.equal("node-name");
36+
expect(workflowTitle.text()).toBe("node-name");
2837
});
2938
});
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import Vue from "vue";
22
import { mount } from "@vue/test-utils";
33
import ZoomControl from "./ZoomControl";
4+
import { getNewAttachNode } from "jest/helpers";
45

56
describe("ZoomControl", () => {
67
it("test zoom control", async () => {
78
const wrapper = mount(ZoomControl, {
89
propsData: {
910
zoomLevel: 10,
1011
},
12+
attachTo: getNewAttachNode(),
1113
});
1214
const buttons = wrapper.findAll("button");
13-
expect(buttons.length).to.equal(3);
15+
expect(buttons.length).toBe(3);
1416
buttons.at(0).trigger("click");
1517
await Vue.nextTick();
16-
expect(wrapper.emitted().onZoom[0][0]).to.equal(9);
18+
expect(wrapper.emitted().onZoom[0][0]).toBe(9);
1719
buttons.at(1).trigger("click");
1820
await Vue.nextTick();
19-
expect(wrapper.emitted().onZoom[1][0]).to.equal(10);
21+
expect(wrapper.emitted().onZoom[1][0]).toBe(10);
2022
buttons.at(2).trigger("click");
2123
await Vue.nextTick();
22-
expect(wrapper.emitted().onZoom[2][0]).to.equal(11);
24+
expect(wrapper.emitted().onZoom[2][0]).toBe(11);
2325
});
2426
});

client/src/components/Workflow/Run/WorkflowRun.mocha.js renamed to client/src/components/Workflow/Run/WorkflowRun.test.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { __RewireAPI__ as rewire } from "./WorkflowRun";
44
import WorkflowRun from "./WorkflowRun.vue";
55
import { mount, createLocalVue } from "@vue/test-utils";
66
import flushPromises from "flush-promises";
7+
import { setupTestGalaxy } from "qunit/test-app";
78

89
import sampleRunData1 from "./testdata/run1.json";
910

@@ -13,11 +14,11 @@ describe("WorkflowRun.vue", () => {
1314
let axiosMock;
1415
let wrapper;
1516
let localVue;
17+
setupTestGalaxy();
1618

1719
beforeEach(() => {
1820
axiosMock = new MockAdapter(axios);
1921
rewire.__Rewire__("getAppRoot", () => "/");
20-
2122
const propsData = { workflowId: run1WorkflowId };
2223
localVue = createLocalVue();
2324
axiosMock.onGet(`/api/workflows/${run1WorkflowId}/download?style=run`).reply(200, sampleRunData1);
@@ -32,19 +33,19 @@ describe("WorkflowRun.vue", () => {
3233
});
3334

3435
it("loads run data from API and parses it into a WorkflowRunModel object", async () => {
35-
expect(wrapper.vm.loading).to.equal(true);
36-
expect(wrapper.vm.error).to.equal(null);
37-
expect(wrapper.vm.model).to.equal(null);
36+
expect(wrapper.vm.loading).toBe(true);
37+
expect(wrapper.vm.error).toBeNull();
38+
expect(wrapper.vm.model).toBeNull();
3839
await flushPromises();
39-
expect(wrapper.vm.error).to.equal(null);
40-
expect(wrapper.vm.loading).to.equal(false);
40+
expect(wrapper.vm.error).toBeNull();
41+
expect(wrapper.vm.loading).toBe(false);
4142
const model = wrapper.vm.model;
42-
expect(model).to.not.equal(null);
43-
expect(model.workflowId).to.equal(run1WorkflowId);
44-
expect(model.name).to.equal("Cool Test Workflow");
45-
expect(model.historyId).to.equal("8f7a155755f10e73");
46-
expect(model.hasUpgradeMessages).to.equal(false);
47-
expect(model.hasStepVersionChanges).to.equal(false);
48-
expect(model.wpInputs.wf_param.label).to.equal("wf_param");
43+
expect(model).not.toBeNull();
44+
expect(model.workflowId).toBe(run1WorkflowId);
45+
expect(model.name).toBe("Cool Test Workflow");
46+
expect(model.historyId).toBe("8f7a155755f10e73");
47+
expect(model.hasUpgradeMessages).toBe(false);
48+
expect(model.hasStepVersionChanges).toBe(false);
49+
expect(model.wpInputs.wf_param.label).toBe("wf_param");
4950
});
5051
});

client/src/onload/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ export { getRootFromIndexLink } from "./getRootFromIndexLink";
1818

1919
// Client-side configuration variables (based on environment)
2020
import config from "config";
21-
console.log("Configs:", config.name, config);
21+
22+
if (!config.testBuild === true) {
23+
console.log("Configs:", config.name, config);
24+
}

client/tests/jest/helpers.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function getNewAttachNode() {
2+
const attachElement = document.createElement("div");
3+
if (document.body) {
4+
document.body.appendChild(attachElement);
5+
}
6+
return attachElement;
7+
}

0 commit comments

Comments
 (0)