-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathDatasetCollectionDialog.test.js
More file actions
68 lines (55 loc) · 2.29 KB
/
DatasetCollectionDialog.test.js
File metadata and controls
68 lines (55 loc) · 2.29 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
import { createLocalVue, mount } from "@vue/test-utils";
import { BAlert, BTable } from "bootstrap-vue";
import flushPromises from "flush-promises";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { HttpResponse, useServerMock } from "@/api/client/__mocks__";
import DatasetCollectionDialog from "./DatasetCollectionDialog.vue";
import SelectionDialog from "./SelectionDialog.vue";
vi.mock("app");
const { server, http } = useServerMock();
const mockOptions = {
callback: () => {},
history: "f2db41e1fa331b3e",
};
describe("DatasetCollectionDialog.vue", () => {
let wrapper;
let localVue;
beforeEach(() => {
localVue = createLocalVue();
});
it("loads correctly in loading state, shows options when optionsShow becomes true", async () => {
// Initially in loading state.
const collectionsResponse = [{ id: "f2db41e1fa331b3e", name: "Awesome Collection", hid: 1 }];
server.use(
http.untyped.get(`/api/histories/${mockOptions.history}/contents`, ({ request }) => {
const url = new URL(request.url);
if (url.searchParams.get("type") === "dataset_collection") {
return HttpResponse.json(collectionsResponse);
}
return HttpResponse.json([]);
}),
);
wrapper = mount(DatasetCollectionDialog, {
propsData: mockOptions,
localVue: localVue,
});
expect(wrapper.findComponent(SelectionDialog).exists()).toBe(true);
expect(wrapper.findComponent(BTable).exists()).toBe(false);
await flushPromises();
expect(wrapper.findComponent(BAlert).exists()).toBe(false);
expect(wrapper.findComponent(BTable).exists()).toBe(true);
});
it("error message set on dataset collection fetch problems", async () => {
server.use(
http.untyped.get(`/api/histories/${mockOptions.history}/contents`, () => {
return HttpResponse.json({ err_msg: "Bad error" }, { status: 403 });
}),
);
wrapper = mount(DatasetCollectionDialog, {
propsData: mockOptions,
localVue: localVue,
});
await flushPromises();
expect(wrapper.findComponent(BAlert).text()).toBe("Bad error");
});
});