Skip to content

Commit

Permalink
Fixup unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Feb 8, 2024
1 parent d1c57e3 commit 5dcb1cb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 40 deletions.
3 changes: 2 additions & 1 deletion client/src/api/schema/__mocks__/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 55 in client/src/api/schema/__mocks__/fetcher.ts

View workflow job for this annotation

GitHub Actions / client-unit-test (18)

Unexpected any. Specify a different type
Expand Down
29 changes: 12 additions & 17 deletions client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import { shallowMount } from "@vue/test-utils";

Check failure on line 1 in client/src/components/Dataset/DatasetStorage/DatasetStorage.test.js

View workflow job for this annotation

GitHub Actions / client-unit-test (18)

Run autofix to sort these imports!
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 = {
object_store_id: null,
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 },
Expand All @@ -32,22 +28,26 @@ 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();
}

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);
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<DatasetStorageProps>(), {
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/HistoryExport/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,7 +19,7 @@ const props = defineProps<ExportHistoryProps>();
<span class="history-export-component">
<h1 class="h-lg">Export history archive</h1>
<span v-if="initializingFileSources">
<loading-span message="Loading file sources configuration from Galaxy server." />
<LoadingSpan message="Loading file sources configuration from Galaxy server." />
</span>
<span v-else-if="hasWritableFileSources">
<BCard no-body>
Expand Down
1 change: 1 addition & 0 deletions client/src/components/LoadingSpan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</template>
<script>
export default {
name: "LoadingSpan",
props: {
classes: {
type: String,
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/ObjectStore/DescribeObjectStore.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<script lang="ts">
export default {
name: "DescribeObjectStore",
};
</script>
<script setup lang="ts">
import { computed } from "vue";

Check failure on line 7 in client/src/components/ObjectStore/DescribeObjectStore.vue

View workflow job for this annotation

GitHub Actions / client-unit-test (18)

Import in body of module; reorder to top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ describe("ShowSelectedObjectStore", () => {
wrapper = mount(ShowSelectedObjectStore, {
propsData: { preferredObjectStoreId: TEST_OBJECT_ID, forWhat: "Data goes into..." },
localVue,
stubs: {
LoadingSpan: true,
DescribeObjectStore: true,
},
});
let loadingEl = wrapper.findComponent(LoadingSpan);
expect(loadingEl.exists()).toBeTruthy();
Expand Down
14 changes: 1 addition & 13 deletions client/src/components/User/DiskUsage/DiskUsageSummary.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { mount } from "@vue/test-utils";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import flushPromises from "flush-promises";
import { createPinia } from "pinia";
import { getLocalVue } from "tests/jest/helpers";
Expand Down Expand Up @@ -69,16 +67,6 @@ async function mountDiskUsageSummaryWrapper(enableQuotas: boolean) {
}

describe("DiskUsageSummary.vue", () => {
let axiosMock: MockAdapter;

beforeEach(async () => {
axiosMock = new MockAdapter(axios);
});

afterEach(async () => {
axiosMock.reset();
});

it("should display basic disk usage summary if quotas are NOT enabled", async () => {
const enableQuotasInConfig = false;
const wrapper = await mountDiskUsageSummaryWrapper(enableQuotasInConfig);
Expand Down Expand Up @@ -115,7 +103,7 @@ describe("DiskUsageSummary.vue", () => {
},
];
mockFetcher.path("/api/users/{user_id}/usage").method("get").mock({ data: updatedFakeQuotaUsages });
axiosMock.onGet(`/api/tasks/${FAKE_TASK_ID}/state`).reply(200, "SUCCESS");
mockFetcher.path("/api/tasks/{task_id}/state").method("get").mock({ data: "SUCCESS" });
const refreshButton = wrapper.find("#refresh-disk-usage");
await refreshButton.trigger("click");
const refreshingAlert = wrapper.find(".refreshing-alert");
Expand Down

0 comments on commit 5dcb1cb

Please sign in to comment.