Skip to content

Commit

Permalink
Merge pull request #223 from mrc-ide/mrc-5956
Browse files Browse the repository at this point in the history
mrc-5956 vitest pt 5
  • Loading branch information
M-Kusumgar authored Nov 13, 2024
2 parents 9904eb8 + 4070205 commit 5272125
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallowMount } from "@vue/test-utils";
import ActionRequiredMessage from "../../../src/app/components/ActionRequiredMessage.vue";
import ActionRequiredMessage from "../../../src/components/ActionRequiredMessage.vue";

describe("ActionRequiredMessage", () => {
it("renders message in span if present", () => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/components/confirmModal.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from "@vue/test-utils";
import ConfirmModal from "../../../src/app/components/ConfirmModal.vue";
import ConfirmModal from "../../../src/components/ConfirmModal.vue";

describe("ConfirmModal", () => {
const getWrapper = (open = true, title = "Delete something", text = "Really?") => {
Expand Down
6 changes: 3 additions & 3 deletions app/static/tests/unit/components/downloadOutput.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { mockBasicState, mockRunState } from "../../mocks";
import { BasicState } from "../../../src/app/store/basic/state";
import DownloadOutput from "../../../src/app/components/DownloadOutput.vue";
import { BasicState } from "../../../src/store/basic/state";
import DownloadOutput from "../../../src/components/DownloadOutput.vue";

/* eslint-disable max-len */
const generatedFilenameRegex =
Expand Down Expand Up @@ -34,7 +34,7 @@ describe("DownloadOutput", () => {
};

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

it("renders as expected when not open", () => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/components/dropdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallowMount } from "@vue/test-utils";
import DropDown from "../../../src/app/components/DropDown.vue";
import DropDown from "../../../src/components/DropDown.vue";

describe("dropdown component", () => {
const itemList = " <li><span class='dropdown-item' style='cursor: default;'>test</span></li>";
Expand Down
4 changes: 2 additions & 2 deletions app/static/tests/unit/components/errorInfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallowMount } from "@vue/test-utils";
import ErrorInfo from "../../../src/app/components/ErrorInfo.vue";
import ErrorInfo from "../../../src/components/ErrorInfo.vue";

describe("ErrorInfo", () => {
it("renders as expected with error", () => {
Expand All @@ -10,7 +10,7 @@ describe("ErrorInfo", () => {
});

it("renders as expected with no error", () => {
const wrapper = shallowMount(ErrorInfo, { props: { error: null } });
const wrapper = shallowMount(ErrorInfo, { props: { error: undefined } });
expect(wrapper.find("div").text()).toBe("");
});
});
12 changes: 6 additions & 6 deletions app/static/tests/unit/components/errorsAlert.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { mockBasicState } from "../../mocks";
import { BasicState } from "../../../src/app/store/basic/state";
import ErrorsAlert from "../../../src/app/components/ErrorsAlert.vue";
import { WodinError } from "../../../src/app/types/responseTypes";
import { ErrorsMutation } from "../../../src/app/store/errors/mutations";
import { BasicState } from "../../../src/store/basic/state";
import ErrorsAlert from "../../../src/components/ErrorsAlert.vue";
import { WodinError } from "../../../src/types/responseTypes";
import { ErrorsMutation } from "../../../src/store/errors/mutations";

describe("ErrorsAlert", () => {
const getWrapper = (errors: WodinError[], dismissErrors = jest.fn()) => {
const getWrapper = (errors: WodinError[], dismissErrors = vi.fn()) => {
const store = new Vuex.Store<BasicState>({
state: mockBasicState,
modules: {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("ErrorsAlert", () => {
});

it("dismisses errors on close", async () => {
const mockDismissErrors = jest.fn();
const mockDismissErrors = vi.fn();
const wrapper = getWrapper([{ error: "TEST_CODE", detail: "Test Error Message" }], mockDismissErrors);
const closeButton = wrapper.find("button");
await closeButton.trigger("click");
Expand Down
22 changes: 11 additions & 11 deletions app/static/tests/unit/components/graphSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { BasicState } from "../../../src/app/store/basic/state";
import GraphSettings from "../../../src/app/components/GraphSettings.vue";
import { GraphsMutation } from "../../../src/app/store/graphs/mutations";
import { defaultGraphSettings } from "../../../src/app/store/graphs/state";
import { BasicState } from "../../../src/store/basic/state";
import GraphSettings from "../../../src/components/GraphSettings.vue";
import { GraphsMutation } from "../../../src/store/graphs/mutations";
import { defaultGraphSettings } from "../../../src/store/graphs/state";

describe("GraphSettings", () => {
const mockSetLogScaleYAxis = jest.fn();
const mockSetLockYAxis = jest.fn();
const mockSetLogScaleYAxis = vi.fn();
const mockSetLockYAxis = vi.fn();

const mockSetFitLogScaleYAxis = jest.fn();
const mockSetFitLockYAxis = jest.fn();
const mockSetFitLogScaleYAxis = vi.fn();
const mockSetFitLockYAxis = vi.fn();

const getWrapper = (
graphIndex: number | undefined = 1,
Expand Down Expand Up @@ -44,7 +44,7 @@ describe("GraphSettings", () => {
};

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

it("renders as expected when not fit plot", () => {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("GraphSettings", () => {
expect(mockSetLogScaleYAxis).not.toHaveBeenCalled();
});

it("commits change to log scale y axis setting, when not fit plot", async () => {
it("commits change to lock y axis setting, when not fit plot", async () => {
const wrapper = getWrapper(1, false);
const inputs = wrapper.findAll("input");
expect((inputs[1].element as HTMLInputElement).checked).toBe(false);
Expand All @@ -101,7 +101,7 @@ describe("GraphSettings", () => {
expect(mockSetFitLockYAxis).not.toHaveBeenCalled();
});

it("commits change to log scale y axis setting, when fit plot", async () => {
it("commits change to lock y axis setting, when fit plot", async () => {
const wrapper = getWrapper(undefined, true);
const inputs = wrapper.findAll("input");
expect((inputs[1].element as HTMLInputElement).checked).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/components/loadingButton.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from "@vue/test-utils";
import LoadingButton from "../../../src/app/components/LoadingButton.vue";
import LoadingButton from "../../../src/components/LoadingButton.vue";

describe("LoadingButton", () => {
const getWrapper = (loading = false, isDisabled = false) => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/components/loadingSpinner.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from "@vue/test-utils";
import LoadingSpinner from "../../../src/app/components/LoadingSpinner.vue";
import LoadingSpinner from "../../../src/components/LoadingSpinner.vue";

describe("LoadingSpinner", () => {
it("renders as expected", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shallowMount } from "@vue/test-utils";
import SessionInitialiseModal from "../../../src/app/components/SessionInitialiseModal.vue";
import SessionInitialiseModal from "../../../src/components/SessionInitialiseModal.vue";

describe("SessionInitialiseModal", () => {
const getWrapper = (open = true) => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/components/verticalCollapse.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shallowMount } from "@vue/test-utils";
import VueFeather from "vue-feather";
import VerticalCollapse from "../../../src/app/components/VerticalCollapse.vue";
import VerticalCollapse from "../../../src/components/VerticalCollapse.vue";

describe("VerticalCollapse", () => {
const getWrapper = (collapsedDefault = false) => {
Expand Down
24 changes: 12 additions & 12 deletions app/static/tests/unit/components/wodinApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import Vuex from "vuex";
import { mount } from "@vue/test-utils";
import { mockBasicState, mockSessionsState } from "../../mocks";
import { BasicState } from "../../../src/app/store/basic/state";
import LoadingSpinner from "../../../src/app/components/LoadingSpinner.vue";
import WodinPanels from "../../../src/app/components/WodinPanels.vue";
import ErrorsAlert from "../../../src/app/components/ErrorsAlert.vue";
import WodinApp from "../../../src/app/components/WodinApp.vue";
import { SessionsState } from "../../../src/app/store/sessions/state";
import SessionInitialiseModal from "../../../src/app/components/SessionInitialiseModal.vue";
import { AppStateAction } from "../../../src/app/store/appState/actions";
import { BasicState } from "../../../src/store/basic/state";
import LoadingSpinner from "../../../src/components/LoadingSpinner.vue";
import WodinPanels from "../../../src/components/WodinPanels.vue";
import ErrorsAlert from "../../../src/components/ErrorsAlert.vue";
import WodinApp from "../../../src/components/WodinApp.vue";
import { SessionsState } from "../../../src/store/sessions/state";
import SessionInitialiseModal from "../../../src/components/SessionInitialiseModal.vue";
import { AppStateAction } from "../../../src/store/appState/actions";

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("WodinApp", () => {
const mockInitialiseSession = jest.fn();
const mockInitialiseSession = vi.fn();
const getWrapper = (appState: Partial<BasicState> = {}, sessionsState: Partial<SessionsState> = {}) => {
const state = mockBasicState(appState);
const props = {
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("WodinApp", () => {
};

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

it("renders as expected when config is set", () => {
Expand Down
14 changes: 7 additions & 7 deletions app/static/tests/unit/components/wodinPanels.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { nextTick } from "vue";
import { shallowMount, VueWrapper } from "@vue/test-utils";
import WodinPanels from "../../../src/app/components/WodinPanels.vue";
import WodinPanels from "../../../src/components/WodinPanels.vue";

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

enum PanelsMode {
Left,
Expand All @@ -28,8 +28,8 @@ enum DragStart {
Edge
}

const mockObserve = jest.fn();
const mockDisconnect = jest.fn();
const mockObserve = vi.fn();
const mockDisconnect = vi.fn();
function mockResizeObserver(this: any) {
this.observe = mockObserve;
this.disconnect = mockDisconnect;
Expand All @@ -45,7 +45,7 @@ const windowBoundaryRight = windowWidth - widthToleranceRight;
const snapToleranceLeft = windowBoundaryLeft / 3;
const snapToleranceRight = windowWidth - widthToleranceRight / 3;

const mockPreventDefault = jest.fn();
const mockPreventDefault = vi.fn();

describe("WodinPanels", () => {
const getWrapper = () => {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("WodinPanels", () => {
};

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

it("has expected slot content", () => {
Expand Down
Loading

0 comments on commit 5272125

Please sign in to comment.