Skip to content

Commit a72bbed

Browse files
authored
Merge pull request #21288 from guerler/update_last_queue
Update last queue process handler
2 parents 235878a + 019cd67 commit a72bbed

File tree

6 files changed

+386
-110
lines changed

6 files changed

+386
-110
lines changed

client/src/components/Dataset/DatasetView.test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const mockDataset = {
4141
genome_build: "hg38",
4242
misc_blurb: "100 lines",
4343
misc_info: "Additional info",
44+
peek: "Needs a peek",
4445
};
4546

4647
const errorDataset = { ...mockDataset, state: "error" };
@@ -102,7 +103,7 @@ async function mountDatasetView(tab = "preview", options = {}) {
102103
attachTo: document.createElement("div"),
103104
stubs: {
104105
// Only shallow stub certain components
105-
"font-awesome-icon": true,
106+
FontAwesomeIcon: true,
106107
Heading: {
107108
template: "<div><slot></slot></div>",
108109
props: ["h1", "separator"],
@@ -183,10 +184,20 @@ async function mountLoadingDatasetView() {
183184

184185
describe("DatasetView", () => {
185186
beforeEach(() => {
187+
class IO {
188+
constructor() {}
189+
observe() {}
190+
unobserve() {}
191+
disconnect() {}
192+
}
193+
global.IntersectionObserver = IO;
194+
global.MutationObserver = IO;
186195
server.use(
187196
http.get("/api/datasets/:dataset_id", ({ response }) => {
188197
return response(200).json(mockDataset);
189198
}),
199+
http.get("/api/configuration", ({ response }) => response(200).json({})),
200+
http.get("/api/plugins", ({ response }) => response(200).json([])),
190201
);
191202
});
192203

@@ -201,8 +212,8 @@ describe("DatasetView", () => {
201212
it("shows loading message when dataset is loading", async () => {
202213
const wrapper = await mountLoadingDatasetView();
203214
expect(wrapper.find(".loading-message").exists()).toBe(true);
204-
expect(wrapper.find(".loading-message").text()).toBe("Loading dataset details...");
205-
expect(wrapper.find(".dataset-view").exists()).toBe(false);
215+
expect(wrapper.find(".loading-message").text()).toBe("Loading...");
216+
expect(wrapper.find(".dataset-view").exists()).toBe(true);
206217
});
207218

208219
it("renders dataset information", async () => {

client/src/components/Markdown/Sections/Elements/HistoryDatasetDisplay.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe("History Tabular Dataset Display", () => {
3030
extension: "tabular",
3131
name: "someName",
3232
state: "ok",
33+
peek: "needs a peek",
3334
};
3435
const tabularTableDataCounts = tabularMetaData.metadata_columns * tabularMetaData.metadata_data_lines;
3536

@@ -58,7 +59,7 @@ describe("History Text Dataset Display", () => {
5859
let wrapper;
5960
const datasetId = "otherId";
6061
const text = { item_data: "some text" };
61-
const textMetaData = { extension: "txt", name: "someName", state: "ok" };
62+
const textMetaData = { extension: "txt", name: "someName", state: "ok", peek: "needs a peek" };
6263

6364
async function mountTarget() {
6465
server.resetHandlers();

client/src/components/Workflow/List/WorkflowList.test.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ import flushPromises from "flush-promises";
66
import { setActivePinia } from "pinia";
77
import VueRouter from "vue-router";
88

9-
import { HttpResponse, useServerMock } from "@/api/client/__mocks__";
9+
import { loadWorkflows } from "@/api/workflows";
1010
import { useUserStore } from "@/stores/userStore";
1111

1212
import { generateRandomWorkflowList } from "../testUtils";
1313

1414
import WorkflowList from "./WorkflowList.vue";
1515

16+
jest.mock("@/api/workflows", () => ({
17+
loadWorkflows: jest.fn(),
18+
}));
19+
20+
const mockedLoadWorkflows = loadWorkflows as jest.Mock;
21+
1622
const localVue = getLocalVue();
1723
localVue.use(VueRouter);
1824
const router = new VueRouter();
1925

20-
const { server, http } = useServerMock();
21-
2226
const FAKE_USER_ID = "fake_user_id";
2327
const FAKE_USERNAME = "fake_username";
2428
const FAKE_USER_EMAIL = "fake_user_email";
@@ -48,23 +52,12 @@ async function mountWorkflowList() {
4852

4953
describe("WorkflowList", () => {
5054
beforeEach(() => {
51-
server.use(
52-
http.get("/api/workflows/{workflow_id}/counts", ({ response }) => {
53-
return response(200).json({});
54-
}),
55-
);
56-
57-
// The use of the tool tip in statelesstag without a real dom is causing issues
5855
suppressBootstrapVueWarnings();
56+
jest.clearAllMocks();
5957
});
6058

6159
it("render empty workflow list", async () => {
62-
server.use(
63-
http.get("/api/workflows", ({ response }) => {
64-
return response(200).json([]);
65-
}),
66-
);
67-
60+
mockedLoadWorkflows.mockResolvedValue({ data: [], totalMatches: 0 });
6861
const wrapper = await mountWorkflowList();
6962

7063
expect(wrapper.findAll(".workflow-card")).toHaveLength(0);
@@ -73,14 +66,7 @@ describe("WorkflowList", () => {
7366

7467
it("render workflow list", async () => {
7568
const FAKE_WORKFLOWS = generateRandomWorkflowList(FAKE_USERNAME, 10);
76-
77-
server.use(
78-
http.get("/api/workflows", ({ response }) => {
79-
// TODO: We use untyped here because the response is not yet defined in the schema
80-
return response.untyped(HttpResponse.json(FAKE_WORKFLOWS));
81-
}),
82-
);
83-
69+
mockedLoadWorkflows.mockResolvedValue({ data: FAKE_WORKFLOWS, totalMatches: 10 });
8470
const wrapper = await mountWorkflowList();
8571

8672
expect(wrapper.findAll(".workflow-card")).toHaveLength(10);
@@ -93,14 +79,7 @@ describe("WorkflowList", () => {
9379
it("toggle show deleted workflows", async () => {
9480
const FAKE_WORKFLOWS = generateRandomWorkflowList(FAKE_USERNAME, 10);
9581
FAKE_WORKFLOWS.forEach((w) => (w.deleted = true));
96-
97-
server.use(
98-
http.get("/api/workflows", ({ response }) => {
99-
// TODO: We use untyped here because the response is not yet defined in the schema
100-
return response.untyped(HttpResponse.json(FAKE_WORKFLOWS));
101-
}),
102-
);
103-
82+
mockedLoadWorkflows.mockResolvedValue({ data: FAKE_WORKFLOWS, totalMatches: 10 });
10483
const wrapper = await mountWorkflowList();
10584

10685
expect((wrapper.find("#workflow-list-filter input").element as HTMLInputElement).value).toBe("");

client/src/composables/keyedCache.test.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("useKeyedCache", () => {
3535
await flushPromises();
3636
expect(isLoadingItem.value(id)).toBeFalsy();
3737
expect(storedItems.value[id]).toEqual(item);
38-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
38+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
3939
});
4040

4141
it("should not fetch the item if it is already stored", async () => {
@@ -96,7 +96,7 @@ describe("useKeyedCache", () => {
9696
await flushPromises();
9797
expect(isLoadingItem.value(id)).toBeFalsy();
9898
expect(storedItems.value[id]).toEqual(item);
99-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
99+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
100100
expect(shouldFetch).toHaveBeenCalled();
101101
});
102102

@@ -119,7 +119,7 @@ describe("useKeyedCache", () => {
119119
expect(isLoadingItem.value(id)).toBeFalsy();
120120
expect(storedItems.value[id]).toEqual(item);
121121
expect(fetchItem).toHaveBeenCalledTimes(1);
122-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
122+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
123123
});
124124

125125
it("should not fetch the item if it is already being fetched, even if shouldFetch returns true", async () => {
@@ -142,7 +142,7 @@ describe("useKeyedCache", () => {
142142
expect(isLoadingItem.value(id)).toBeFalsy();
143143
expect(storedItems.value[id]).toEqual(item);
144144
expect(fetchItem).toHaveBeenCalledTimes(1);
145-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
145+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
146146
expect(shouldFetch).toHaveBeenCalled();
147147
});
148148

@@ -165,7 +165,7 @@ describe("useKeyedCache", () => {
165165
await flushPromises();
166166
expect(isLoadingItem.value(id)).toBeFalsy();
167167
expect(storedItems.value[id]).toEqual(item);
168-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
168+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
169169
});
170170

171171
it("should accept a computed for shouldFetch", async () => {
@@ -188,7 +188,26 @@ describe("useKeyedCache", () => {
188188
await flushPromises();
189189
expect(isLoadingItem.value(id)).toBeFalsy();
190190
expect(storedItems.value[id]).toEqual(item);
191-
expect(fetchItem).toHaveBeenCalledWith(fetchParams);
191+
expect(fetchItem).toHaveBeenCalledWith(fetchParams, expect.anything());
192192
expect(shouldFetch).toHaveBeenCalled();
193193
});
194+
195+
it("should handle fake timers without hanging when advanced manually", async () => {
196+
jest.useFakeTimers();
197+
const id = "1";
198+
const item = { id, name: "Item 1" };
199+
fetchItem.mockImplementation(() => {
200+
return new Promise((resolve) => {
201+
setTimeout(() => resolve(item), 10);
202+
});
203+
});
204+
const { getItemById } = useKeyedCache<ItemData>(fetchItem);
205+
getItemById.value(id);
206+
getItemById.value(id);
207+
getItemById.value(id);
208+
await flushPromises();
209+
jest.runOnlyPendingTimers();
210+
await flushPromises();
211+
expect(true).toBe(true);
212+
});
194213
});

0 commit comments

Comments
 (0)