From 6fc4b8b47c7e48ef6c2b5298ce3f0e765f986148 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 8 Feb 2024 09:10:06 -0500 Subject: [PATCH] Fixup unit tests. --- client/src/api/schema/__mocks__/fetcher.ts | 3 +- .../DatasetStorage/DatasetStorage.test.js | 30 ++++++++----------- .../Dataset/DatasetStorage/DatasetStorage.vue | 8 ++--- client/src/components/HistoryExport/Index.vue | 3 +- client/src/components/LoadingSpan.vue | 1 + .../ObjectStore/DescribeObjectStore.vue | 6 ++++ .../ShowSelectedObjectStore.test.js | 4 --- .../User/DiskUsage/DiskUsageSummary.test.ts | 14 +-------- 8 files changed, 29 insertions(+), 40 deletions(-) diff --git a/client/src/api/schema/__mocks__/fetcher.ts b/client/src/api/schema/__mocks__/fetcher.ts index 5af41cc7e146..56c8a56ed3ef 100644 --- a/client/src/api/schema/__mocks__/fetcher.ts +++ b/client/src/api/schema/__mocks__/fetcher.ts @@ -48,7 +48,8 @@ function getMockReturn(path: Path, method: Method, args: any[]) { } } - return null; + // if no mock has been setup, never resolve API request + return new Promise(() => {}); } function setMockReturn(path: Path | RegExp, method: Method, value: any) { diff --git a/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js b/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js index f8218abbe934..990b9a26871b 100644 --- a/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js +++ b/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js @@ -1,11 +1,13 @@ import { shallowMount } from "@vue/test-utils"; -import axios from "axios"; -import MockAdapter from "axios-mock-adapter"; import flushPromises from "flush-promises"; import { getLocalVue } from "tests/jest/helpers"; +import { mockFetcher } from "@/api/schema/__mocks__"; + import DatasetStorage from "./DatasetStorage"; +jest.mock("@/api/schema"); + const localVue = getLocalVue(); const TEST_STORAGE_API_RESPONSE_WITHOUT_ID = { @@ -13,17 +15,12 @@ const TEST_STORAGE_API_RESPONSE_WITHOUT_ID = { private: false, }; const TEST_DATASET_ID = "1"; -const TEST_STORAGE_URL = `/api/datasets/${TEST_DATASET_ID}/storage`; +const STORAGE_FETCH_URL = "/api/datasets/{dataset_id}/storage"; const TEST_ERROR_MESSAGE = "Opps all errors."; describe("DatasetStorage.vue", () => { - let axiosMock; let wrapper; - beforeEach(async () => { - axiosMock = new MockAdapter(axios); - }); - function mount() { wrapper = shallowMount(DatasetStorage, { propsData: { datasetId: TEST_DATASET_ID }, @@ -32,7 +29,7 @@ describe("DatasetStorage.vue", () => { } async function mountWithResponse(response) { - axiosMock.onGet(TEST_STORAGE_URL).reply(200, response); + mockFetcher.path(STORAGE_FETCH_URL).method("get").mock({ data: response }); mount(); await flushPromises(); } @@ -40,14 +37,18 @@ describe("DatasetStorage.vue", () => { it("test loading...", async () => { mount(); await wrapper.vm.$nextTick(); + console.log(wrapper.html()); expect(wrapper.findAll("loadingspan-stub").length).toBe(1); expect(wrapper.findAll("describeobjectstore-stub").length).toBe(0); }); it("test error rendering...", async () => { - axiosMock.onGet(TEST_STORAGE_URL).reply(400, { - err_msg: TEST_ERROR_MESSAGE, - }); + mockFetcher + .path(STORAGE_FETCH_URL) + .method("get") + .mock(() => { + throw Error(TEST_ERROR_MESSAGE); + }); mount(); await flushPromises(); expect(wrapper.findAll(".error").length).toBe(1); @@ -59,10 +60,5 @@ describe("DatasetStorage.vue", () => { await mountWithResponse(TEST_STORAGE_API_RESPONSE_WITHOUT_ID); expect(wrapper.findAll("loadingspan-stub").length).toBe(0); expect(wrapper.findAll("describeobjectstore-stub").length).toBe(1); - expect(wrapper.vm.storageInfo.private).toEqual(false); - }); - - afterEach(() => { - axiosMock.restore(); }); }); diff --git a/client/src/components/Dataset/DatasetStorage/DatasetStorage.vue b/client/src/components/Dataset/DatasetStorage/DatasetStorage.vue index 584f987f7ab1..90706afe28ea 100644 --- a/client/src/components/Dataset/DatasetStorage/DatasetStorage.vue +++ b/client/src/components/Dataset/DatasetStorage/DatasetStorage.vue @@ -10,8 +10,8 @@ import DescribeObjectStore from "@/components/ObjectStore/DescribeObjectStore.vu interface DatasetStorageProps { datasetId: string; - datasetType: "hda" | "ldda"; - includeTitle: boolean; + datasetType?: "hda" | "ldda"; + includeTitle?: boolean; } const props = withDefaults(defineProps(), { @@ -48,8 +48,8 @@ watch( const datasetId = props.datasetId; const datasetType = props.datasetType; try { - const { data } = await fetchDatasetStorage({ dataset_id: datasetId, hda_ldda: datasetType }); - storageInfo.value = data; + const response = await fetchDatasetStorage({ dataset_id: datasetId, hda_ldda: datasetType }); + storageInfo.value = response.data; } catch (error) { errorMessage.value = errorMessageAsString(error); } diff --git a/client/src/components/HistoryExport/Index.vue b/client/src/components/HistoryExport/Index.vue index dfbe79cf5dc9..2b1552006b54 100644 --- a/client/src/components/HistoryExport/Index.vue +++ b/client/src/components/HistoryExport/Index.vue @@ -5,6 +5,7 @@ import { useFileSources } from "@/composables/fileSources"; import ToLink from "./ToLink.vue"; import ToRemoteFile from "./ToRemoteFile.vue"; +import LoadingSpan from "@/components/LoadingSpan.vue"; const { isLoading: initializingFileSources, hasWritable: hasWritableFileSources } = useFileSources(); @@ -18,7 +19,7 @@ const props = defineProps();

Export history archive

- + diff --git a/client/src/components/LoadingSpan.vue b/client/src/components/LoadingSpan.vue index c4c3b9d26b5e..3babd0a618d7 100644 --- a/client/src/components/LoadingSpan.vue +++ b/client/src/components/LoadingSpan.vue @@ -6,6 +6,7 @@ + +