Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mrc-5952 vitest pt 1 #219

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 44 additions & 35 deletions app/static/tests/unit/components/basic/basicApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
// Mock the import of third party packages to prevent errors
jest.mock("plotly.js-basic-dist-min", () => ({}));
jest.mock("../../../../src/app/components/help/MarkdownItImport.ts", () => {
// eslint-disable-next-line func-names
return function () {
return {
use: jest.fn().mockReturnValue({
renderer: { rules: {} },
render: jest.fn()
})
};
};
vi.mock("plotly.js-basic-dist-min", () => {
return {
default: undefined,
update: undefined
}
});
vi.mock("../../../../src/components/help/MarkdownItImport.ts", () => {
class MarkDownItClass {
constructor() {
return {
use: vi.fn().mockReturnValue({
renderer: { rules: {} },
render: vi.fn()
})
}
}
};
return {
default: {
default: MarkDownItClass
}
}
});
Comment on lines +2 to 24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If some of these bits are going to pop up several times, I wonder if it would be worth importing them from a shared module?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a good idea im not sure if you actually can even extract out vi.mocks, they seem to care about hoisting and not capturing stuff from the env and so on but i think there must be some functionality in vitest! i have made a ticket: https://mrc-ide.myjetbrains.com/youtrack/issue/mrc-5980/vi.mock-in-shared-module will do it in a future pr


/* eslint-disable import/first */
import Vuex from "vuex";
import { mount } from "@vue/test-utils";
import { expectLeftWodinTabs, expectRightWodinTabs } from "../../../testUtils";
import HelpTab from "../../../../src/app/components/help/HelpTab.vue";
import BasicApp from "../../../../src/app/components/basic/BasicApp.vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import HelpTab from "../../../../src/components/help/HelpTab.vue";
import BasicApp from "../../../../src/components/basic/BasicApp.vue";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState, mockGraphsState, mockModelState, mockSensitivityState } from "../../../mocks";
import WodinApp from "../../../../src/app/components/WodinApp.vue";
import WodinPanels from "../../../../src/app/components/WodinPanels.vue";
import OptionsTab from "../../../../src/app/components/options/OptionsTab.vue";
import MultiSensitivityTab from "../../../../src/app/components/multiSensitivity/MultiSensitivityTab.vue";
import { ModelAction } from "../../../../src/app/store/model/actions";
import { VisualisationTab } from "../../../../src/app/store/appState/state";
import { AppStateMutation } from "../../../../src/app/store/appState/mutations";
import { AppConfig } from "../../../../src/app/types/responseTypes";
import { getters as graphsGetters } from "../../../../src/app/store/graphs/getters";

const mockTooltipDirective = jest.fn();
import WodinApp from "../../../../src/components/WodinApp.vue";
import WodinPanels from "../../../../src/components/WodinPanels.vue";
import OptionsTab from "../../../../src/components/options/OptionsTab.vue";
import MultiSensitivityTab from "../../../../src/components/multiSensitivity/MultiSensitivityTab.vue";
import { ModelAction } from "../../../../src/store/model/actions";
import { VisualisationTab } from "../../../../src/store/appState/state";
import { AppStateMutation } from "../../../../src/store/appState/mutations";
import { AppConfig } from "../../../../src/types/responseTypes";
import { getters as graphsGetters } from "../../../../src/store/graphs/getters";

const mockTooltipDirective = vi.fn();

function mockResizeObserver(this: any) {
this.observe = jest.fn();
this.disconnect = jest.fn();
this.observe = vi.fn();
this.disconnect = vi.fn();
}
(global.ResizeObserver as any) = mockResizeObserver;

describe("BasicApp", () => {
const getWrapper = (mockSetOpenVisualisationTab = jest.fn(), config: Partial<AppConfig> = {}) => {
const getWrapper = (mockSetOpenVisualisationTab = vi.fn(), config: Partial<AppConfig> = {}) => {
const state = mockBasicState({ config: config as any, configured: true });

const store = new Vuex.Store<BasicState>({
Expand All @@ -52,7 +62,7 @@ describe("BasicApp", () => {
namespaced: true,
state: mockModelState(),
actions: {
[ModelAction.FetchOdinRunner]: jest.fn()
[ModelAction.FetchOdinRunner]: vi.fn()
}
},
sensitivity: {
Expand Down Expand Up @@ -98,7 +108,6 @@ describe("BasicApp", () => {

expectRightWodinTabs(wrapper, ["Run", "Sensitivity"]);
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabs.find("div.mt-4 div.run-tab").exists()).toBe(true);
});

Expand All @@ -122,7 +131,7 @@ describe("BasicApp", () => {
});

it("commits change new right tab selected", async () => {
const mockSetOpenTab = jest.fn();
const mockSetOpenTab = vi.fn();
const wrapper = getWrapper(mockSetOpenTab);
const rightTabs = wrapper.findComponent("#right-tabs");
await rightTabs.findAll("li a").at(1)!.trigger("click"); // Click Sensitivity Tab
Expand All @@ -137,7 +146,7 @@ describe("BasicApp", () => {
tabName: "Help"
}
};
const wrapper = getWrapper(jest.fn(), helpConfig);
const wrapper = getWrapper(vi.fn(), helpConfig);
expectRightWodinTabs(wrapper, ["Help", "Run", "Sensitivity"]);

const rightTabs = wrapper.findComponent(WodinPanels).find(".wodin-right #right-tabs");
Expand All @@ -148,7 +157,7 @@ describe("BasicApp", () => {
const multiSensConfig = {
multiSensitivity: true
};
const wrapper = getWrapper(jest.fn(), multiSensConfig);
const wrapper = getWrapper(vi.fn(), multiSensConfig);
expectRightWodinTabs(wrapper, ["Run", "Sensitivity", "Multi-sensitivity"]);

const rightTabs = wrapper.findComponent(WodinPanels).find(".wodin-right #right-tabs");
Expand All @@ -166,7 +175,7 @@ describe("BasicApp", () => {
},
multiSensitivity: true
};
const wrapper = getWrapper(jest.fn(), bothConfig);
const wrapper = getWrapper(vi.fn(), bothConfig);
expectRightWodinTabs(wrapper, ["Help", "Run", "Sensitivity", "Multi-sensitivity"]);
});
});
Loading
Loading