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-5955 vitest pt 4 #222

Merged
merged 2 commits 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
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Vuex from "vuex";
import { shallowMount, VueWrapper } from "@vue/test-utils";
import { nextTick } from "vue";
import DownloadOutput from "../../../../src/app/components/DownloadOutput.vue";
import { AppState } from "../../../../src/app/store/appState/state";
import DownloadOutput from "../../../../src/components/DownloadOutput.vue";
import { AppState } from "../../../../src/store/appState/state";
import {
BaseSensitivityState,
SensitivityPlotType,
SensitivityState
} from "../../../../src/app/store/sensitivity/state";
import SensitivitySummaryDownload from "../../../../src/app/components/sensitivity/SensitivitySummaryDownload.vue";
import { BaseSensitivityAction, SensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import LoadingSpinner from "../../../../src/app/components/LoadingSpinner.vue";
import { ModelGetter } from "../../../../src/app/store/model/getters";
import { getters as graphsGetters } from "../../../../src/app/store/graphs/getters";
} from "../../../../src/store/sensitivity/state";
import SensitivitySummaryDownload from "../../../../src/components/sensitivity/SensitivitySummaryDownload.vue";
import { BaseSensitivityAction } from "../../../../src/store/sensitivity/actions";
import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import LoadingSpinner from "../../../../src/components/LoadingSpinner.vue";
import { ModelGetter } from "../../../../src/store/model/getters";
import { getters as graphsGetters } 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("SensitivitySummaryDownload", () => {
const mockSetUserSummaryDownloadFileName = jest.fn();
const mockDownloadSummary = jest.fn();
const mockSetPlotTime = jest.fn();
const mockSetUserSummaryDownloadFileName = vi.fn();
const mockDownloadSummary = vi.fn();
const mockSetPlotTime = vi.fn();

const getWrapper = (multiSens = false, state: Partial<BaseSensitivityState> = {}) => {
const plotSettings = {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("SensitivitySummaryDownload", () => {
},
mutations: {
[BaseSensitivityMutation.SetUserSummaryDownloadFileName]: mockSetUserSummaryDownloadFileName,
[SensitivityMutation.SetPlotTime]: multiSens ? jest.fn() : mockSetPlotTime
[SensitivityMutation.SetPlotTime]: multiSens ? vi.fn() : mockSetPlotTime
}
};
const minimalSensitivity = {
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("SensitivitySummaryDownload", () => {
) => {
let wrapper = getWrapper(false, state);
test(wrapper, false);
jest.clearAllMocks();
vi.clearAllMocks();
wrapper = getWrapper(true, state);
test(wrapper, true);
};
Expand All @@ -127,13 +127,13 @@ describe("SensitivitySummaryDownload", () => {
) => {
let wrapper = getWrapper(false, state);
await test(wrapper, false);
jest.clearAllMocks();
vi.clearAllMocks();
wrapper = getWrapper(true, state);
await test(wrapper, true);
};

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

it("enables download button when expected", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ import Vuex, { Store } from "vuex";
import { shallowMount, VueWrapper } from "@vue/test-utils";
import * as plotly from "plotly.js-basic-dist-min";
import { nextTick } from "vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState } from "../../../mocks";
import {
SensitivityParameterSettings,
SensitivityPlotExtreme,
SensitivityPlotSettings,
SensitivityPlotType,
SensitivityScaleType
} from "../../../../src/app/store/sensitivity/state";
import { SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import SensitivitySummaryPlot from "../../../../src/app/components/sensitivity/SensitivitySummaryPlot.vue";
import { RunGetter } from "../../../../src/app/store/run/getters";
import WodinPlotDataSummary from "../../../../src/app/components/WodinPlotDataSummary.vue";
import { GraphConfig } from "../../../../src/app/store/graphs/state";

jest.mock("plotly.js-basic-dist-min", () => ({
newPlot: jest.fn(),
} from "../../../../src/store/sensitivity/state";
import { SensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import SensitivitySummaryPlot from "../../../../src/components/sensitivity/SensitivitySummaryPlot.vue";
import { RunGetter } from "../../../../src/store/run/getters";
import WodinPlotDataSummary from "../../../../src/components/WodinPlotDataSummary.vue";

vi.mock("plotly.js-basic-dist-min", () => ({
newPlot: vi.fn(),
Plots: {
resize: jest.fn()
resize: vi.fn()
}
}));

describe("SensitivitySummaryPlot", () => {
const mockPlotlyNewPlot = jest.spyOn(plotly, "newPlot");
const mockPlotlyNewPlot = vi.spyOn(plotly, "newPlot");

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;
}
(global.ResizeObserver as any) = mockResizeObserver;

const mockSetPlotTime = jest.fn();
const mockSetLoading = jest.fn();
const mockSetPlotTime = vi.fn();
const mockSetLoading = vi.fn();

const mockData = {
x: [{ beta: 1 }, { beta: 1.1 }],
Expand Down Expand Up @@ -75,26 +74,26 @@ describe("SensitivitySummaryPlot", () => {
]
};

const mockValueAtTime = jest.fn().mockReturnValue(mockData);
const mockExtreme = jest.fn().mockReturnValue(mockData);
const mockValueAtTime = vi.fn().mockReturnValue(mockData);
const mockExtreme = vi.fn().mockReturnValue(mockData);
const mockBatch = {
valueAtTime: mockValueAtTime,
extreme: mockExtreme
};

const mockBatchSet1 = {
valueAtTime: jest.fn().mockReturnValue(mockDataSet1),
extreme: jest.fn().mockReturnValue(mockDataSet1)
valueAtTime: vi.fn().mockReturnValue(mockDataSet1),
extreme: vi.fn().mockReturnValue(mockDataSet1)
};

const mockBatchSet2 = {
valueAtTime: jest.fn().mockReturnValue(mockDataSet2),
extreme: jest.fn().mockReturnValue(mockDataSet2)
valueAtTime: vi.fn().mockReturnValue(mockDataSet2),
extreme: vi.fn().mockReturnValue(mockDataSet2)
};

const mockBatchSet3 = {
valueAtTime: jest.fn().mockReturnValue(mockDataSet3),
extreme: jest.fn().mockReturnValue(mockDataSet3)
valueAtTime: vi.fn().mockReturnValue(mockDataSet3),
extreme: vi.fn().mockReturnValue(mockDataSet3)
};

let store: Store<BasicState> | null = null;
Expand Down Expand Up @@ -220,7 +219,7 @@ describe("SensitivitySummaryPlot", () => {
};

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

const expectDataToHaveBeenPlotted = (wrapper: VueWrapper<any>, layout: any = {}, includesParameterSets = false) => {
Expand Down Expand Up @@ -524,7 +523,7 @@ describe("SensitivitySummaryPlot", () => {

it("redraws plot if data changes", async () => {
// update store's time value to force re-compute of plotData, and then redraw
const wrapper = getWrapper();
getWrapper();
store!.state.sensitivity.plotSettings.time = 50;
await nextTick();
expect(mockPlotlyNewPlot).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -564,7 +563,7 @@ describe("SensitivitySummaryPlot", () => {
});

it("commits set loading when plotData is computed, if loading is true", async () => {
const wrapper = getWrapper(
getWrapper(
true,
defaultPlotSettings,
false,
Expand All @@ -582,7 +581,7 @@ describe("SensitivitySummaryPlot", () => {
});

it("does not commit set loading when plotData is computed, if loading is false", async () => {
const wrapper = getWrapper();
getWrapper();
store!.state.sensitivity.plotSettings.time = 50;
expect(mockSetLoading).not.toHaveBeenCalled();
});
Expand Down
42 changes: 21 additions & 21 deletions app/static/tests/unit/components/sensitivity/sensitivityTab.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import { ModelState } from "../../../../src/app/store/model/state";
import SensitivityTab from "../../../../src/app/components/sensitivity/SensitivityTab.vue";
import ActionRequiredMessage from "../../../../src/app/components/ActionRequiredMessage.vue";
import { BaseSensitivityGetter } from "../../../../src/app/store/sensitivity/getters";
import SensitivityTracesPlot from "../../../../src/app/components/sensitivity/SensitivityTracesPlot.vue";
import { SensitivityPlotType, SensitivityState } from "../../../../src/app/store/sensitivity/state";
import { SensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import SensitivitySummaryPlot from "../../../../src/app/components/sensitivity/SensitivitySummaryPlot.vue";
import ErrorInfo from "../../../../src/app/components/ErrorInfo.vue";
import { AppState, AppType } from "../../../../src/app/store/appState/state";
import { ModelGetter } from "../../../../src/app/store/model/getters";
import LoadingSpinner from "../../../../src/app/components/LoadingSpinner.vue";
import { SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import SensitivitySummaryDownload from "../../../../src/app/components/sensitivity/SensitivitySummaryDownload.vue";
import LoadingButton from "../../../../src/app/components/LoadingButton.vue";
import { getters as graphsGetters } from "../../../../src/app/store/graphs/getters";
import { ModelState } from "../../../../src/store/model/state";
import SensitivityTab from "../../../../src/components/sensitivity/SensitivityTab.vue";
import ActionRequiredMessage from "../../../../src/components/ActionRequiredMessage.vue";
import { BaseSensitivityGetter } from "../../../../src/store/sensitivity/getters";
import SensitivityTracesPlot from "../../../../src/components/sensitivity/SensitivityTracesPlot.vue";
import { SensitivityPlotType, SensitivityState } from "../../../../src/store/sensitivity/state";
import { SensitivityAction } from "../../../../src/store/sensitivity/actions";
import SensitivitySummaryPlot from "../../../../src/components/sensitivity/SensitivitySummaryPlot.vue";
import ErrorInfo from "../../../../src/components/ErrorInfo.vue";
import { AppState, AppType } from "../../../../src/store/appState/state";
import { ModelGetter } from "../../../../src/store/model/getters";
import LoadingSpinner from "../../../../src/components/LoadingSpinner.vue";
import { SensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import SensitivitySummaryDownload from "../../../../src/components/sensitivity/SensitivitySummaryDownload.vue";
import LoadingButton from "../../../../src/components/LoadingButton.vue";
import { getters as graphsGetters } from "../../../../src/store/graphs/getters";

jest.mock("plotly.js-basic-dist-min", () => {});
vi.mock("plotly.js-basic-dist-min", () => ({}));

describe("SensitivityTab", () => {
const mockRunSensitivity = jest.fn();
const mockSetLoading = jest.fn();
const mockSetPlotTime = jest.fn();
const mockRunSensitivity = vi.fn();
const mockSetLoading = vi.fn();
const mockSetPlotTime = vi.fn();

const getWrapper = (
appType = AppType.Basic,
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("SensitivityTab", () => {
};

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

it("renders as expected when Trace over Time", () => {
Expand Down
Loading
Loading