forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkflowAnnotation.test.ts
More file actions
171 lines (147 loc) · 6.36 KB
/
WorkflowAnnotation.test.ts
File metadata and controls
171 lines (147 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { createTestingPinia } from "@pinia/testing";
import { getFakeRegisteredUser } from "@tests/test-data";
import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";
import { useServerMock } from "@/api/client/__mocks__";
import { useHistoryStore } from "@/stores/historyStore";
import { useUserStore } from "@/stores/userStore";
import WorkflowAnnotation from "./WorkflowAnnotation.vue";
// Constants
const WORKFLOW_OWNER = "test-user";
const OTHER_USER = "other-user";
const WORKFLOW_UPDATE_TIME = "2023-01-01T00:00:00.000Z";
const INVOCATION_TIME = "2024-01-01T00:00:00.000Z";
const SAMPLE_WORKFLOW = {
id: "workflow-id",
name: "workflow-name",
owner: WORKFLOW_OWNER,
version: 1,
update_time: WORKFLOW_UPDATE_TIME,
};
const OTHER_USER_WORKFLOW_ID = "other-user-workflow-id";
const SAMPLE_RUN_COUNT = 100;
const TEST_HISTORY_ID = "test-history-id";
const TEST_HISTORY = {
id: TEST_HISTORY_ID,
genome_build: "?",
name: "fake-history-name",
};
const SELECTORS = {
RUN_COUNT: ".workflow-invocations-count",
INDICATORS_LINK: '[data-description="published owner badge"]',
SWITCH_TO_HISTORY_LINK: "[data-description='switch to history link']",
TIME_INFO: '[data-description="workflow annotation time info"]',
DATE: '[data-description="workflow annotation date"]',
};
// Mock the workflow store to return the sample workflow
jest.mock("@/stores/workflowStore", () => {
const originalModule = jest.requireActual("@/stores/workflowStore");
return {
...originalModule,
useWorkflowStore: () => ({
...originalModule.useWorkflowStore(),
getStoredWorkflowByInstanceId: jest.fn().mockImplementation((id: string) => {
if (id === OTHER_USER_WORKFLOW_ID) {
return { ...SAMPLE_WORKFLOW, id: OTHER_USER_WORKFLOW_ID, published: true };
}
return SAMPLE_WORKFLOW;
}),
}),
};
});
(jest.mock("@/stores/historyStore"),
() => {
const originalModule = jest.requireActual("@/stores/historyStore");
return {
...originalModule,
useHistoryStore: () => ({
...originalModule.useHistoryStore(),
getHistoryById: jest.fn().mockImplementation(() => TEST_HISTORY),
}),
};
});
const localVue = getLocalVue();
const { server, http } = useServerMock();
/**
* Mounts the WorkflowAnnotation component with props/stores adjusted given the parameters
* @param version The version of the component to mount (`run_form` or `invocation` view)
* @param ownsWorkflow Whether the user owns the workflow
* @returns The wrapper object
*/
async function mountWorkflowAnnotation(version: "run_form" | "invocation", ownsWorkflow = true) {
server.use(
http.get("/api/histories/{history_id}", ({ response }) => {
return response(200).json(TEST_HISTORY);
}),
);
server.use(
http.get("/api/workflows/{workflow_id}/counts", ({ response }) => {
return response(200).json({ scheduled: SAMPLE_RUN_COUNT });
}),
);
const wrapper = mount(WorkflowAnnotation as object, {
propsData: {
workflowId: ownsWorkflow ? SAMPLE_WORKFLOW.id : OTHER_USER_WORKFLOW_ID,
historyId: TEST_HISTORY_ID,
invocationUpdateTime: version === "invocation" ? INVOCATION_TIME : undefined,
showDetails: version === "run_form",
},
localVue,
pinia: createTestingPinia(),
stubs: {
FontAwesomeIcon: true,
},
});
const historyStore = useHistoryStore();
historyStore.setCurrentHistoryId(TEST_HISTORY_ID);
const userStore = useUserStore();
userStore.currentUser = getFakeRegisteredUser({
username: ownsWorkflow ? WORKFLOW_OWNER : OTHER_USER,
});
await flushPromises();
return { wrapper };
}
describe("WorkflowAnnotation renders", () => {
it("the run count and history, not indicators if owned not published", async () => {
async function checkHasRunCount(version: "run_form" | "invocation") {
const { wrapper } = await mountWorkflowAnnotation(version);
const runCount = wrapper.find(SELECTORS.RUN_COUNT);
expect(runCount.text()).toContain("workflow runs:");
expect(runCount.text()).toContain(SAMPLE_RUN_COUNT.toString());
if (version === "run_form") {
expect(wrapper.find(SELECTORS.SWITCH_TO_HISTORY_LINK).exists()).toBe(false);
} else {
expect(wrapper.find(SELECTORS.SWITCH_TO_HISTORY_LINK).text()).toContain(TEST_HISTORY.name);
}
// Since this is the user's own workflow, the indicators link
// (to view all published workflows by the owner) should not be present
expect(wrapper.find(SELECTORS.INDICATORS_LINK).exists()).toBe(false);
}
await checkHasRunCount("run_form");
await checkHasRunCount("invocation");
});
it("workflow indicators if the user does not own the workflow", async () => {
// we assume it is another user's published workflow in this case
async function checkHasIndicators(version: "run_form" | "invocation") {
const { wrapper } = await mountWorkflowAnnotation(version, false);
const indicatorsLink = wrapper.find(SELECTORS.INDICATORS_LINK);
expect(indicatorsLink.text()).toBe(WORKFLOW_OWNER);
expect(indicatorsLink.attributes("title")).toContain(`Published by '${WORKFLOW_OWNER}'`);
}
await checkHasIndicators("run_form");
await checkHasIndicators("invocation");
});
it("renders time since edit if run form view", async () => {
const { wrapper } = await mountWorkflowAnnotation("run_form");
const timeInfo = wrapper.find(SELECTORS.TIME_INFO);
expect(timeInfo.text()).toContain("edited");
expect(timeInfo.find(SELECTORS.DATE).attributes("title")).toBe(WORKFLOW_UPDATE_TIME);
});
it("renders time since invocation if invocation view", async () => {
const { wrapper } = await mountWorkflowAnnotation("invocation");
const timeInfo = wrapper.find(SELECTORS.TIME_INFO);
expect(timeInfo.text()).toContain("invoked");
expect(timeInfo.find(SELECTORS.DATE).attributes("title")).toBe(INVOCATION_TIME);
});
});