Skip to content

Commit

Permalink
Merge pull request #19186 from jmchilton/testing_24.2_5
Browse files Browse the repository at this point in the history
Cleanup Jest Test Output (part 4)
  • Loading branch information
mvdbeek authored Nov 25, 2024
2 parents 9c486e4 + 47ce2db commit 2c5cd3b
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 28 deletions.
4 changes: 3 additions & 1 deletion client/src/app/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ if (!window.Galaxy) {
},
});
} else {
console.debug("Skipping, window.Galaxy already exists.", serverPath());
if (process.env.NODE_ENV != "test") {
console.debug("Skipping, window.Galaxy already exists.", serverPath());
}
}

export default window.Galaxy;
19 changes: 19 additions & 0 deletions client/src/components/Common/FilterMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { createTestingPinia } from "@pinia/testing";
import { getLocalVue } from "@tests/jest/helpers";
import { mount, type Wrapper } from "@vue/test-utils";

import { useServerMock } from "@/api/client/__mocks__";
import { HistoryFilters } from "@/components/History/HistoryFilters";
import { setupSelectableMock } from "@/components/ObjectStore/mockServices";
import { WorkflowFilters } from "@/components/Workflow/List/WorkflowFilters";
import Filtering, { compare, contains, equals, toBool, toDate } from "@/utils/filtering";

import FilterMenu from "./FilterMenu.vue";

const { server, http } = useServerMock();

setupSelectableMock();

const localVue = getLocalVue();
Expand Down Expand Up @@ -72,6 +75,22 @@ const TestFilters = new Filtering(validTestFilters, undefined);
describe("FilterMenu", () => {
let wrapper: Wrapper<Vue>;

beforeEach(() => {
server.use(
http.get("/api/users/{user_id}/usage", ({ response }) => {
return response(200).json([
{
quota: null,
quota_bytes: null,
quota_percent: null,
quota_source_label: null,
total_disk_usage: 4,
},
]);
})
);
});

function setUpWrapper(name: string, placeholder: string, filterClass: Filtering<unknown>) {
wrapper = mount(FilterMenu as object, {
propsData: {
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/Common/RDMDestinationSelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ describe("RDMDestinationSelector", () => {

const emitted = wrapper.emitted("onRecordSelected");

console.log("EMITTED", emitted);

expect(emitted).toBeTruthy();
expect(emitted?.at(0)[0]).toEqual(FAKE_ENTRY.uri);
});
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/ConfigTemplates/InstanceForm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe("InstanceForm", () => {
title: "MY FORM",
inputs: null,
submitTitle: SUBMIT_TITLE,
busy: false,
loadingMessage: "loading plugin instance",
},
localVue,
});
Expand All @@ -31,6 +33,8 @@ describe("InstanceForm", () => {
title: "MY FORM",
inputs: inputs,
submitTitle: SUBMIT_TITLE,
busy: false,
loadingMessage: "loading plugin instance",
},
localVue,
});
Expand Down
7 changes: 6 additions & 1 deletion client/src/components/ConfigTemplates/VaultSecret.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script setup lang="ts">
import { library } from "@fortawesome/fontawesome-svg-core";
import { faPen } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BButton, BFormInput, BInputGroup, BInputGroupAppend } from "bootstrap-vue";
import { computed, ref } from "vue";
import { markup } from "@/components/ObjectStore/configurationMarkdown";
library.add(faPen);
interface Props {
name: string;
label: string;
Expand Down Expand Up @@ -43,7 +48,7 @@ async function onOk() {
<BFormInput type="password" value="*****************************" disabled @click="onClick" />
<BInputGroupAppend>
<BButton @click="onClick">
<icon icon="edit" />
<FontAwesomeIcon :icon="faPen" />
Update
</BButton>
</BInputGroupAppend>
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/DataDialog/DataDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ describe("DataDialog.vue", () => {
wrapper = shallowMount(DataDialog, {
propsData: mockOptions,
localVue,
stubs: {
Icon: true,
},
});
expect(wrapper.findComponent(SelectionDialog).exists()).toBe(true);
// Cannot get nested slot templates to render into the wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ describe("DatasetInformation/DatasetInformation", () => {

// should contain 11 rows
expect(rows.length).toBe(11);

await flushPromises();
});

it("file size should be formatted", async () => {
Expand All @@ -88,6 +90,8 @@ describe("DatasetInformation/DatasetInformation", () => {
const formattedDate = format(parsedDate, "eeee MMM do H:mm:ss yyyy zz");

expect(date).toBe(formattedDate);

await flushPromises();
});

it("Table should render data accordingly", async () => {
Expand All @@ -108,5 +112,7 @@ describe("DatasetInformation/DatasetInformation", () => {
expect(renderedText).toBe(datasetResponse[entry.backend_key].toString());
}
});

await flushPromises();
});
});
7 changes: 6 additions & 1 deletion client/src/components/FilesDialog/FilesDialog.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTestingPinia } from "@pinia/testing";
import { mount, type Wrapper } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";
import { getLocalVue, suppressDebugConsole } from "tests/jest/helpers";

import { useServerMock } from "@/api/client/__mocks__";
import { SELECTION_STATES, type SelectionItem, type SelectionState } from "@/components/SelectionDialog/selectionTypes";
Expand Down Expand Up @@ -73,6 +73,7 @@ const mockedOkApiRoutesMap = new Map<string, RemoteFilesList>([
paramsToKey({ target: "gxfiles://pdb-gzip/directory1/subdirectory1", recursive: "false" }),
subsubdirectoryResponse,
],
[paramsToKey({ target: "gxftp://", recursive: "false" }), pdbResponse],
]);

const mockedErrorApiRoutesMap = new Map<string, RemoteFilesList>([
Expand Down Expand Up @@ -231,6 +232,8 @@ describe("FilesDialog, file mode", () => {
it("should show loading error and can return back when there is an error", async () => {
utils.expectNoErrorMessage();

suppressDebugConsole(); // expecting error message.

// open directory with error
await utils.openDirectoryById("empty-dir");
utils.expectErrorMessage();
Expand Down Expand Up @@ -274,6 +277,8 @@ describe("FilesDialog, directory mode", () => {
it("should show loading error and can return back when there is an error", async () => {
utils.expectNoErrorMessage();

suppressDebugConsole(); // expecting error message.

// open directory with error
await utils.openDirectoryById("empty-dir");
utils.expectErrorMessage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { shallowMount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { createPinia } from "pinia";
import { getLocalVue } from "tests/jest/helpers";
import { getLocalVue, suppressDebugConsole } from "tests/jest/helpers";
import { setupMockConfig } from "tests/jest/mockConfig";

import { useServerMock } from "@/api/client/__mocks__";

Expand Down Expand Up @@ -32,11 +33,7 @@ const getDeletedSelection = () => new Map([["FAKE_ID", { deleted: true }]]);
const getActiveSelection = () => new Map([["FAKE_ID", { deleted: false }]]);

async function mountSelectionOperationsWrapper(config) {
server.use(
http.get("/api/configuration", ({ response }) => {
return response(200).json(config);
})
);
setupMockConfig(config);

const pinia = createPinia();
const wrapper = shallowMount(SelectionOperations, {
Expand Down Expand Up @@ -269,6 +266,7 @@ describe("History Selection Operations", () => {
});

it("should update operation-running state to null when the operation fails", async () => {
suppressDebugConsole(); // expected error messages since we're testing errors.
server.use(
http.put("/api/histories/{history_id}/contents/bulk", ({ response }) => {
return response("4XX").json({ err_msg: "Error", err_code: 400 }, { status: 400 });
Expand All @@ -290,6 +288,8 @@ describe("History Selection Operations", () => {
});

it("should emit operation error event when the operation fails", async () => {
suppressDebugConsole(); // expected error messages since we're testing errors.

server.use(
http.put("/api/histories/{history_id}/contents/bulk", ({ response }) => {
return response("4XX").json({ err_msg: "Error", err_code: 400 }, { status: 400 });
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/History/Export/HistoryExport.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTestingPinia } from "@pinia/testing";
import { getLocalVue } from "@tests/jest/helpers";
import { getLocalVue, suppressDebugConsole } from "@tests/jest/helpers";
import { shallowMount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { setActivePinia } from "pinia";
Expand Down Expand Up @@ -164,6 +164,8 @@ describe("HistoryExport.vue", () => {
});

it("should not display a fatal error alert if the history is found and loaded", async () => {
suppressDebugConsole(); // we rightfully debug message the fact we don't have a history in this test

const wrapper = await mountHistoryExport();

expect(wrapper.find("#fatal-error-alert").exists()).toBe(false);
Expand Down
6 changes: 2 additions & 4 deletions client/src/components/History/HistoryView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { createPinia } from "pinia";
import { getLocalVue } from "tests/jest/helpers";
import { setupMockConfig } from "tests/jest/mockConfig";

import { useServerMock } from "@/api/client/__mocks__";
import { useHistoryStore } from "@/stores/historyStore";
Expand Down Expand Up @@ -70,11 +71,8 @@ async function createWrapper(localVue, currentUserId, history) {
setCurrentHistoryOnServer.mockResolvedValue(history);
const history_contents_result = create_datasets(history.id, history.count);

setupMockConfig({});
server.use(
http.get("/api/configuration", ({ response }) => {
return response(200).json({});
}),

http.get("/api/histories/{history_id}/contents", ({ response }) => {
return response(200).json(history_contents_result);
})
Expand Down
8 changes: 2 additions & 6 deletions client/src/components/Tool/ToolCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MockAdapter from "axios-mock-adapter";
import flushPromises from "flush-promises";
import { createPinia } from "pinia";
import { useUserStore } from "stores/userStore";
import { getLocalVue } from "tests/jest/helpers";
import { expectConfigurationRequest, getLocalVue } from "tests/jest/helpers";
import { setupMockConfig } from "tests/jest/mockConfig";

import { useServerMock } from "@/api/client/__mocks__";
Expand All @@ -29,11 +29,7 @@ describe("ToolCard", () => {
// some child component must be bypassing useConfig - so we need to explicitly
// stup the API endpoint also. If you can drop this without request problems in log,
// this hack can be removed.
server.use(
http.get("/api/configuration", ({ response }) => {
return response(200).json(config);
})
);
server.use(expectConfigurationRequest(http, {}));
axiosMock = new MockAdapter(axios);
axiosMock.onGet(`/api/webhooks`).reply(200, []);

Expand Down
7 changes: 7 additions & 0 deletions client/src/components/Workflow/Editor/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jest.mock("app");

const localVue = getLocalVue();

const MOCK_SCROLL = {
x: { value: 100 },
y: { value: 200 },
isScrolling: { value: true },
};

describe("Node", () => {
it("test attributes", async () => {
const testingPinia = createTestingPinia();
Expand All @@ -27,6 +33,7 @@ describe("Node", () => {
step: { type: "tool", inputs: [], outputs: [], position: { top: 0, left: 0 } },
datatypesMapper: testDatatypesMapper,
rootOffset: mockOffset,
scroll: MOCK_SCROLL,
},
localVue,
pinia: testingPinia,
Expand Down
12 changes: 12 additions & 0 deletions client/src/components/Workflow/Editor/modules/terminals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
InputParameterTerminal,
InputTerminal,
InvalidOutputTerminal,
NO_COLLECTION_TYPE_INFORMATION_MESSAGE,
OutputCollectionTerminal,
OutputParameterTerminal,
OutputTerminal,
Expand All @@ -50,6 +51,17 @@ function useStores(id = "mock-workflow") {
};
}

// Suppress debug messages about node configurations, we're testing esoteric things here -
// we might want these messages at runtime to help debug complex things but we don't need it
// during unit testing.
jest.spyOn(console, "debug").mockImplementation(
jest.fn((msg) => {
if (msg != NO_COLLECTION_TYPE_INFORMATION_MESSAGE) {
console.debug(msg);
}
})
);

function setupAdvanced() {
const terminals: { [index: string]: { [index: string]: ReturnType<typeof terminalFactory> } } = {};

Expand Down
5 changes: 4 additions & 1 deletion client/src/components/Workflow/Editor/modules/terminals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
NULL_COLLECTION_TYPE_DESCRIPTION,
} from "./collectionTypeDescription";

export const NO_COLLECTION_TYPE_INFORMATION_MESSAGE =
"No collection type or collection type source defined - this is fine but may lead to less intuitive connection logic.";

export class ConnectionAcceptable {
reason: string | null;
canAccept: boolean;
Expand Down Expand Up @@ -757,7 +760,7 @@ export class OutputCollectionTerminal extends BaseOutputTerminal {
} else {
this.collectionTypeSource = attr.collection_type_source;
if (!this.collectionTypeSource) {
console.log("Warning: No collection type or collection type source defined.");
console.debug(NO_COLLECTION_TYPE_INFORMATION_MESSAGE);
}
this.collectionType = this.getCollectionTypeFromInput() || ANY_COLLECTION_TYPE_DESCRIPTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jest.mock("axios", () => ({
post: jest.fn((_url, request) => {
lastPostRequest = request;
}),
isAxiosError: jest.fn(() => true),
}));

const localVue = getLocalVue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import flushPromises from "flush-promises";
import { setActivePinia } from "pinia";
import type Vue from "vue";

import { useServerMock } from "@/api/client/__mocks__";

import NotificationForm from "./NotificationForm.vue";

jest.mock("@/api/schema");
// Even though we don't use the API endpoints, this seems to prevent failure fetching
// openapi during jest testing.
useServerMock();

const SUBMIT_BUTTON_SELECTOR = "#notification-submit";

Expand Down Expand Up @@ -46,5 +50,7 @@ describe("NotificationForm.vue", () => {
const { wrapper } = await mountNotificationForm();

expectSubmitButton(wrapper, false);

await flushPromises();
});
});
5 changes: 5 additions & 0 deletions client/src/composables/shortTermStorageMonitor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import flushPromises from "flush-promises";
import { suppressDebugConsole } from "tests/jest/helpers";

import { useServerMock } from "@/api/client/__mocks__";
import { useShortTermStorageMonitor } from "@/composables/shortTermStorageMonitor";
Expand Down Expand Up @@ -52,6 +53,8 @@ describe("useShortTermStorageMonitor", () => {
});

it("should indicate the task status request failed when the request failed", async () => {
suppressDebugConsole(); // expected API failure

const { waitForTask, requestHasFailed, isRunning, isCompleted, taskStatus } = useShortTermStorageMonitor();

expect(requestHasFailed.value).toBe(false);
Expand Down Expand Up @@ -90,6 +93,8 @@ describe("useShortTermStorageMonitor", () => {
});

it("should indicate is final state when the task has failed", async () => {
suppressDebugConsole(); // expected API failure

const { waitForTask, isFinalState, isRunning, isCompleted, hasFailed, taskStatus } =
useShortTermStorageMonitor();

Expand Down
Loading

0 comments on commit 2c5cd3b

Please sign in to comment.