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-5953 vitest pt 2 #220

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
18 changes: 9 additions & 9 deletions app/static/tests/unit/components/help/draggableDialog.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { mount, shallowMount } from "@vue/test-utils";
import VueFeather from "vue-feather";
import { nextTick } from "vue";
import DraggableDialog from "../../../../src/app/components/help/DraggableDialog.vue";
import DraggableDialog from "../../../../src/components/help/DraggableDialog.vue";

const docAddListenerSpy = jest.spyOn(document, "addEventListener");
const docRemoveListenerSpy = jest.spyOn(document, "removeEventListener");
const winAddListenerSpy = jest.spyOn(window, "addEventListener");
const docAddListenerSpy = vi.spyOn(document, "addEventListener");
const docRemoveListenerSpy = vi.spyOn(document, "removeEventListener");
const winAddListenerSpy = vi.spyOn(window, "addEventListener");

describe("DraggableDialog", () => {
const getWrapper = () => {
Expand All @@ -20,7 +20,7 @@ describe("DraggableDialog", () => {
};

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it("renders as expected", () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe("DraggableDialog", () => {
const moveEvent = {
clientX: moveTo.x,
clientY: moveTo.y,
preventDefault: jest.fn()
preventDefault: vi.fn()
};
moveHandler(moveEvent);
expect((wrapper.vm as any).position).toStrictEqual(expectedEndPosition);
Expand All @@ -64,7 +64,7 @@ describe("DraggableDialog", () => {
// End drag
const endHandlerIndex = touch ? 3 : 2; // touchend or mouseup
const mouseUpHandler = docAddListenerSpy.mock.calls[endHandlerIndex][1] as any;
const mouseUpEvent = { preventDefault: jest.fn() };
const mouseUpEvent = { preventDefault: vi.fn() };
mouseUpHandler(mouseUpEvent);
expect(docRemoveListenerSpy).toHaveBeenCalledTimes(4);
expect(docRemoveListenerSpy.mock.calls[0][0]).toBe("mousemove");
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("DraggableDialog", () => {
const moveEvent = {
clientX: resizeTo.x,
clientY: resizeTo.y,
preventDefault: jest.fn()
preventDefault: vi.fn()
};
moveHandler(moveEvent);
expect((wrapper.vm as any).resizedSize).toStrictEqual(expectedEndSize);
Expand All @@ -140,7 +140,7 @@ describe("DraggableDialog", () => {
// End resize
const endHandlerIndex = touch ? 3 : 2; // touchend or mouseup
const endHandler = docAddListenerSpy.mock.calls[endHandlerIndex][1] as any;
const endEvent = { preventDefault: jest.fn() };
const endEvent = { preventDefault: vi.fn() };
endHandler(endEvent);
expect(docRemoveListenerSpy).toHaveBeenCalledTimes(4);
expect(docRemoveListenerSpy.mock.calls[0][0]).toBe("mousemove");
Expand Down
8 changes: 4 additions & 4 deletions app/static/tests/unit/components/help/genericHelp.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mount } from "@vue/test-utils";
import VueFeather from "vue-feather";
import GenericHelp from "../../../../src/app/components/help/GenericHelp.vue";
import DraggableDialog from "../../../../src/app/components/help/DraggableDialog.vue";
import GenericHelp from "../../../../src/components/help/GenericHelp.vue";
import DraggableDialog from "../../../../src/components/help/DraggableDialog.vue";

const mockTooltipDirective = jest.fn();
const mockTooltipDirective = vi.fn();
describe("GenericHelp", () => {
const getWrapper = () => {
return mount(GenericHelp, {
Expand All @@ -23,7 +23,7 @@ describe("GenericHelp", () => {
};

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it("renders as expected", () => {
Expand Down
6 changes: 3 additions & 3 deletions app/static/tests/unit/components/help/helpTab.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { BasicState } from "../../../../src/app/store/basic/state";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState } from "../../../mocks";
import HelpTab from "../../../../src/app/components/help/HelpTab.vue";
import MarkdownPanel from "../../../../src/app/components/help/MarkdownPanel.vue";
import HelpTab from "../../../../src/components/help/HelpTab.vue";
import MarkdownPanel from "../../../../src/components/help/MarkdownPanel.vue";

describe("HelpTab", () => {
it("renders markdown panel with markdown from state", () => {
Expand Down
41 changes: 22 additions & 19 deletions app/static/tests/unit/components/help/markdownPanel.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Mock imports of third party packages so we can mock their methods before importing component
const mockMarkdownItMathjaxPlugin = {};
const mockRenderOutput = "<span>mockRenderOutput</span>";
const mockRender = jest.fn().mockReturnValue(mockRenderOutput);
const mockRender = vi.fn().mockReturnValue(mockRenderOutput);
const mockMarkdownIt = {
renderer: {
rules: {
Expand All @@ -10,25 +10,28 @@ const mockMarkdownIt = {
},
render: mockRender
} as any;
const mockMarkdownItUse = jest.fn().mockReturnValue(mockMarkdownIt);
jest.mock("markdown-it-mathjax", () => ({ __esModule: true, default: () => mockMarkdownItMathjaxPlugin }));
const mockMarkdownItUse = vi.fn().mockReturnValue(mockMarkdownIt);
vi.mock("markdown-it-mathjax", () => ({ __esModule: true, default: () => mockMarkdownItMathjaxPlugin }));

jest.mock("../../../../src/app/components/help/MarkdownItImport.ts", () => {
// mock constructor - this cannot be an arrow function, see
// https://stackoverflow.com/questions/47402005
// eslint-disable-next-line func-names
return function () {
return {
use: mockMarkdownItUse
};
};
vi.mock("../../../../src/components/help/MarkdownItImport.ts", () => {
class MarkDownItClass {
constructor() {
return {
use: mockMarkdownItUse
}
}
};
return {
default: {
default: MarkDownItClass
}
}
});

/* eslint-disable import/first */
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import MarkdownPanel from "../../../../src/app/components/help/MarkdownPanel.vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import MarkdownPanel from "../../../../src/components/help/MarkdownPanel.vue";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState } from "../../../mocks";

describe("MarkdownPanel", () => {
Expand All @@ -47,10 +50,10 @@ describe("MarkdownPanel", () => {
};

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
const testImageRewriteRule = (rule: Function, imgSrc: string, expectedOutputSrc: string) => {
const tokens = [
{
Expand All @@ -59,7 +62,7 @@ describe("MarkdownPanel", () => {
}
];
const idx = 0;
const mockRenderToken = jest.fn();
const mockRenderToken = vi.fn();
const slf = {
renderToken: mockRenderToken
};
Expand Down Expand Up @@ -101,7 +104,7 @@ describe("MarkdownPanel", () => {
});

it("calls Mathjax.typeset when mounted", () => {
const mockTypeset = jest.fn();
const mockTypeset = vi.fn();
(window as any).MathJax = {
typeset: mockTypeset
};
Expand Down
28 changes: 14 additions & 14 deletions app/static/tests/unit/components/mixins/baseSensitivity.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Vuex from "vuex";
import { ModelState } from "../../../../src/app/store/model/state";
import baseSensitivity, { BaseSensitivityMixin } from "../../../../src/app/components/mixins/baseSensitivity";
import { BaseSensitivityState } from "../../../../src/app/store/sensitivity/state";
import { noSensitivityUpdateRequired } from "../../../../src/app/store/sensitivity/sensitivity";
import { AppState } from "../../../../src/app/store/appState/state";
import { BaseSensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import { BaseSensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import { getters as graphGetters } from "../../../../src/app/store/graphs/getters";
import { ModelState } from "../../../../src/store/model/state";
import baseSensitivity, { BaseSensitivityMixin } from "../../../../src/components/mixins/baseSensitivity";
import { BaseSensitivityState } from "../../../../src/store/sensitivity/state";
import { noSensitivityUpdateRequired } from "../../../../src/store/sensitivity/sensitivity";
import { AppState } from "../../../../src/store/appState/state";
import { BaseSensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import { BaseSensitivityAction } from "../../../../src/store/sensitivity/actions";
import { getters as graphGetters } from "../../../../src/store/graphs/getters";
import { mockGraphsState } from "../../../mocks";
import { defaultGraphSettings } from "../../../../src/app/store/graphs/state";
import { defaultGraphSettings } from "../../../../src/store/graphs/state";

describe("baseSensitivity mixin", () => {
const mockSensSetUserSummaryDownloadFileName = jest.fn();
const mockMultiSensSetUserSummaryDownloadFileName = jest.fn();
const mockSensSetUserSummaryDownloadFileName = vi.fn();
const mockMultiSensSetUserSummaryDownloadFileName = vi.fn();

const mockSensDownloadSummary = jest.fn();
const mockMultiSensDownloadSummary = jest.fn();
const mockSensDownloadSummary = vi.fn();
const mockMultiSensDownloadSummary = vi.fn();

const getStore = (
hasRunner = true,
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("baseSensitivity mixin", () => {
};

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it("sensitivityPrerequisitesReady returns true when all prerequisites have been met", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vuex from "vuex";
import { BasicState } from "../../../../src/app/store/basic/state";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState } from "../../../mocks";
import includeConfiguredTabs from "../../../../src/app/components/mixins/includeConfiguredTabs";
import includeConfiguredTabs from "../../../../src/components/mixins/includeConfiguredTabs";

describe("includeConfiguredTabs mixin", () => {
const getStore = (helpConfig: any, multiSensitivity: boolean | undefined = undefined) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import MultiSensitivityTab from "../../../../src/app/components/multiSensitivity/MultiSensitivityTab.vue";
import { AppState, AppType } from "../../../../src/app/store/appState/state";
import LoadingButton from "../../../../src/app/components/LoadingButton.vue";
import { ModelState } from "../../../../src/app/store/model/state";
import { MultiSensitivityAction } from "../../../../src/app/store/multiSensitivity/actions";
import ActionRequiredMessage from "../../../../src/app/components/ActionRequiredMessage.vue";
import { MultiSensitivityState } from "../../../../src/app/store/multiSensitivity/state";
import ErrorInfo from "../../../../src/app/components/ErrorInfo.vue";
import SensitivitySummaryDownload from "../../../../src/app/components/sensitivity/SensitivitySummaryDownload.vue";
import { getters as graphsGetters } from "../../../../src/app/store/graphs/getters";
import MultiSensitivityTab from "../../../../src/components/multiSensitivity/MultiSensitivityTab.vue";
import { AppState, AppType } from "../../../../src/store/appState/state";
import LoadingButton from "../../../../src/components/LoadingButton.vue";
import { ModelState } from "../../../../src/store/model/state";
import { MultiSensitivityAction } from "../../../../src/store/multiSensitivity/actions";
import ActionRequiredMessage from "../../../../src/components/ActionRequiredMessage.vue";
import { MultiSensitivityState } from "../../../../src/store/multiSensitivity/state";
import ErrorInfo from "../../../../src/components/ErrorInfo.vue";
import SensitivitySummaryDownload from "../../../../src/components/sensitivity/SensitivitySummaryDownload.vue";
import { getters as graphsGetters } from "../../../../src/store/graphs/getters";

describe("MultiSensitivityTab", () => {
const mockRunMultiSensitivity = jest.fn();
const mockRunMultiSensitivity = vi.fn();

const getWrapper = (
running = false,
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("MultiSensitivityTab", () => {
};

beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it("renders loading button in loading state when multi-sensitivity is running", () => {
Expand Down
39 changes: 19 additions & 20 deletions app/static/tests/unit/components/run/runPlot.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// Mock plotly before import RunTab, which indirectly imports plotly via WodinPlot
jest.mock("plotly.js-basic-dist-min", () => {});
vi.mock("plotly.js-basic-dist-min", () => ({}));

/* eslint-disable import/first */
import { shallowMount, VueWrapper } from "@vue/test-utils";
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import RunPlot from "../../../../src/app/components/run/RunPlot.vue";
import WodinPlot from "../../../../src/app/components/WodinPlot.vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import { FitDataGetter } from "../../../../src/app/store/fitData/getters";
import { getters as runGetters } from "../../../../src/app/store/run/getters";
import RunPlot from "../../../../src/components/run/RunPlot.vue";
import WodinPlot from "../../../../src/components/WodinPlot.vue";
import { BasicState } from "../../../../src/store/basic/state";
import { FitDataGetter } from "../../../../src/store/fitData/getters";
import { getters as runGetters } from "../../../../src/store/run/getters";
import { mockGraphsState, mockModelState, mockRunState } from "../../../mocks";
import { defaultGraphSettings } from "../../../../src/app/store/graphs/state";
import { defaultGraphSettings } from "../../../../src/store/graphs/state";

describe("RunPlot", () => {
const mockSolution = jest.fn().mockReturnValue({
const mockSolution = vi.fn().mockReturnValue({
names: ["S", "I"],
x: [0, 1],
values: [
Expand All @@ -28,7 +27,7 @@ describe("RunPlot", () => {
error: null
} as any;

const mockParamSetSolution1 = jest.fn().mockReturnValue({
const mockParamSetSolution1 = vi.fn().mockReturnValue({
names: ["S", "I"],
x: [0, 1],
values: [
Expand All @@ -44,7 +43,7 @@ describe("RunPlot", () => {
error: null
};

const mockParamSetSolution2 = jest.fn().mockReturnValue({
const mockParamSetSolution2 = vi.fn().mockReturnValue({
names: ["S", "I"],
x: [0, 1],
values: [
Expand All @@ -60,7 +59,7 @@ describe("RunPlot", () => {
error: null
};

const mockParamSetSolution3 = jest.fn().mockReturnValue({
const mockParamSetSolution3 = vi.fn().mockReturnValue({
names: ["S", "I"],
x: [0, 1],
values: [
Expand Down Expand Up @@ -116,10 +115,10 @@ describe("RunPlot", () => {
selectedVariables,
unselectedVariables: [],
settings: defaultGraphSettings()
};
} as any;

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it("renders as expected when model has solution", () => {
Expand Down Expand Up @@ -276,7 +275,7 @@ describe("RunPlot", () => {
fadePlot: false,
graphIndex: 0,
graphConfig
},
} as any,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need these as anys - is this not providing all the props the RunPlot expects? I suppose could spread an empty props object here if so, but probably not worth it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

linkedXAxis was the issue in this one! yh just thought it wasnt worth it to add it cos we dont use linkedXAxis in most of these tests

global: {
plugins: [store]
}
Expand Down Expand Up @@ -415,7 +414,7 @@ describe("RunPlot", () => {
fadePlot: false,
graphConfig,
graphIndex: 0
},
} as any,
global: {
plugins: [store]
}
Expand Down Expand Up @@ -445,7 +444,7 @@ describe("RunPlot", () => {
props: {
fadePlot: true,
graphConfig
},
} as any,
global: {
plugins: [store]
}
Expand Down Expand Up @@ -505,7 +504,7 @@ describe("RunPlot", () => {
props: {
fadePlot: false,
graphConfig
},
} as any,
global: {
plugins: [store]
}
Expand Down Expand Up @@ -589,7 +588,7 @@ describe("RunPlot", () => {
props: {
fadePlot: true,
graphConfig: { ...graphConfig, selectedVariables: [] }
},
} as any,
global: {
plugins: [store]
}
Expand Down
Loading
Loading