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..1b247f803fe0 100644 --- a/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js +++ b/client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js @@ -1,11 +1,12 @@ 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 +14,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 +28,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 +36,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 +59,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..6f58aa9052ce 100644 --- a/client/src/components/HistoryExport/Index.vue +++ b/client/src/components/HistoryExport/Index.vue @@ -3,6 +3,7 @@ import { BCard, BTab, BTabs } from "bootstrap-vue"; import { useFileSources } from "@/composables/fileSources"; +import LoadingSpan from "@/components/LoadingSpan.vue"; import ToLink from "./ToLink.vue"; import ToRemoteFile from "./ToRemoteFile.vue"; @@ -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 @@ + +