Skip to content

Commit

Permalink
store tests
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Nov 5, 2024
1 parent 80b12d9 commit 6f4eb12
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 196 deletions.
10 changes: 5 additions & 5 deletions app/static/tests/unit/store/code/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CodeAction, actions } from "../../../../src/app/store/code/actions";
import { CodeMutation } from "../../../../src/app/store/code/mutations";
import { ModelAction } from "../../../../src/app/store/model/actions";
import { CodeAction, actions } from "../../../../src/store/code/actions";
import { CodeMutation } from "../../../../src/store/code/mutations";
import { ModelAction } from "../../../../src/store/model/actions";

describe("Code actions", () => {
it("UpdateCode commits new code and dispatches FetchOdin", () => {
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();
(actions[CodeAction.UpdateCode] as any)({ commit, dispatch }, ["new code"]);
expect(commit).toBeCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(CodeMutation.SetCurrentCode);
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/store/code/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockCodeState } from "../../../mocks";
import { mutations } from "../../../../src/app/store/code/mutations";
import { mutations } from "../../../../src/store/code/mutations";

describe("Code mutations", () => {
it("sets current code", () => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/store/errors/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mutations } from "../../../../src/app/store/errors/mutations";
import { mutations } from "../../../../src/store/errors/mutations";

describe("Errors mutations", () => {
it("adds error", () => {
Expand Down
233 changes: 111 additions & 122 deletions app/static/tests/unit/store/fitData/actions.test.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/static/tests/unit/store/fitData/getters.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FitDataGetter, getters } from "../../../../src/app/store/fitData/getters";
import { FitDataGetter, getters } from "../../../../src/store/fitData/getters";
import { mockFitDataState } from "../../../mocks";

describe("FitDataGetters", () => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/store/fitData/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mutations } from "../../../../src/app/store/fitData/mutations";
import { mutations } from "../../../../src/store/fitData/mutations";
import { mockFitDataState } from "../../../mocks";

describe("FitData mutations", () => {
Expand Down
20 changes: 10 additions & 10 deletions app/static/tests/unit/store/graphs/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mockAxios, mockFitState, mockModelState } from "../../../mocks";
import { actions, GraphsAction } from "../../../../src/app/store/graphs/actions";
import { GraphsMutation } from "../../../../src/app/store/graphs/mutations";
import { AppType } from "../../../../src/app/store/appState/state";
import { FitDataAction } from "../../../../src/app/store/fitData/actions";
import { defaultGraphSettings } from "../../../../src/app/store/graphs/state";
import { actions, GraphsAction } from "../../../../src/store/graphs/actions";
import { GraphsMutation } from "../../../../src/store/graphs/mutations";
import { AppType } from "../../../../src/store/appState/state";
import { FitDataAction } from "../../../../src/store/fitData/actions";
import { defaultGraphSettings } from "../../../../src/store/graphs/state";

describe("Graphs actions", () => {
const modelState = {
Expand All @@ -25,8 +25,8 @@ describe("Graphs actions", () => {

it("Updates selected variables commits selection only, if not fit model", () => {
const state = mockModelState();
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();

(actions[GraphsAction.UpdateSelectedVariables] as any)(
{
Expand All @@ -49,8 +49,8 @@ describe("Graphs actions", () => {

it("Updates selected variables commits selection and updates linked variables if fit app", () => {
const state = mockModelState();
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();
const fitRootState = mockFitState({
model: modelState
});
Expand All @@ -77,7 +77,7 @@ describe("Graphs actions", () => {
expect(dispatch.mock.calls[0][2]).toStrictEqual({ root: true });
});
it("NewGraph adds empty graph", () => {
const commit = jest.fn();
const commit = vi.fn();

(actions[GraphsAction.NewGraph] as any)({
commit,
Expand Down
4 changes: 2 additions & 2 deletions app/static/tests/unit/store/graphs/getters.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockGraphsState } from "../../../mocks";
import { getters, GraphsGetter } from "../../../../src/app/store/graphs/getters";
import { defaultGraphSettings } from "../../../../src/app/store/graphs/state";
import { getters, GraphsGetter } from "../../../../src/store/graphs/getters";
import { defaultGraphSettings } from "../../../../src/store/graphs/state";

describe("GraphsGetters", () => {
const settings = defaultGraphSettings();
Expand Down
8 changes: 4 additions & 4 deletions app/static/tests/unit/store/graphs/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mutations } from "../../../../src/app/store/graphs/mutations";
import { defaultGraphSettings, GraphsState } from "../../../../src/app/store/graphs/state";
import { mockGraphsState, mockModelState } from "../../../mocks";
import { mutations } from "../../../../src/store/graphs/mutations";
import { defaultGraphSettings, GraphsState } from "../../../../src/store/graphs/state";
import { mockGraphsState } from "../../../mocks";

describe("Graphs mutations", () => {
const state: GraphsState = mockGraphsState({
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("Graphs mutations", () => {
expect(state.fitGraphSettings.lockYAxis).toBe(true);
});

it("sets yAxisRange", () => {
it("sets fitYAxisRange", () => {
mutations.SetFitYAxisRange(state, [3, 4]);
expect(state.fitGraphSettings.yAxisRange).toStrictEqual([3, 4]);
});
Expand Down
88 changes: 43 additions & 45 deletions app/static/tests/unit/store/run/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Mock = jest.Mock;
import { RunMutation } from "../../../../src/app/store/run/mutations";
import { Mock } from "vitest";
import { RunMutation } from "../../../../src/store/run/mutations";
import { mockModelState, mockRunnerDiscrete, mockRunnerOde, mockRunState } from "../../../mocks";
import { WodinModelOutputDownload } from "../../../../src/app/excel/wodinModelOutputDownload";
import { actions, RunAction } from "../../../../src/app/store/run/actions";
import { AppType } from "../../../../src/app/store/appState/state";
import { ModelFitAction } from "../../../../src/app/store/modelFit/actions";
import { RunGetter } from "../../../../src/app/store/run/getters";
import { SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import { AdvancedOptions } from "../../../../src/app/types/responseTypes";
import { AdvancedComponentType } from "../../../../src/app/store/run/state";
import { WodinModelOutputDownload } from "../../../../src/excel/wodinModelOutputDownload";
import { actions, RunAction } from "../../../../src/store/run/actions";
import { AppType } from "../../../../src/store/appState/state";
import { ModelFitAction } from "../../../../src/store/modelFit/actions";
import { RunGetter } from "../../../../src/store/run/getters";
import { SensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import { AdvancedOptions } from "../../../../src/types/responseTypes";
import { AdvancedComponentType } from "../../../../src/store/run/state";

jest.mock("../../../../src/app/excel/wodinModelOutputDownload");
vi.mock("../../../../src/excel/wodinModelOutputDownload");

describe("Run actions", () => {
const mockDownloadModelOutput = jest.fn();
const mockDownloadModelOutput = vi.fn();
const mockWodinModelOutputDownload = WodinModelOutputDownload as any as Mock;
mockWodinModelOutputDownload.mockImplementation(() => ({ download: mockDownloadModelOutput }));

Expand Down Expand Up @@ -66,7 +66,7 @@ describe("Run actions", () => {
endTime: 99,
parameterSets
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -127,7 +127,7 @@ describe("Run actions", () => {
endTime: 99,
parameterSets
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("Run actions", () => {
[AdvancedOptions.tcrit]: { val: [0, "p1", "p2"], default: [], type: AdvancedComponentType.tag }
}
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -275,7 +275,7 @@ describe("Run actions", () => {
const testGetters = {
[RunGetter.runParameterSetsIsRequired]: true
} as any;
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -353,7 +353,7 @@ describe("Run actions", () => {
endTime: 99,
numberOfReplicates: 10
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -391,7 +391,7 @@ describe("Run actions", () => {
runRequired: runRequiredAll,
parameterValues: {}
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand All @@ -414,7 +414,7 @@ describe("Run actions", () => {
model: modelState
} as any;
const state = mockRunState();
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand All @@ -436,7 +436,7 @@ describe("Run actions", () => {
model: modelState
} as any;
const state = mockRunState();
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand All @@ -452,7 +452,7 @@ describe("Run actions", () => {
const testCommitsErrorOnRunModel = (stochastic: boolean) => {
const mockError = new Error("test");
const mockOdin = {} as any;
const mockRunMethod = jest.fn().mockImplementation(() => {
const mockRunMethod = vi.fn().mockImplementation(() => {
throw mockError;
});
const runner = {
Expand Down Expand Up @@ -481,8 +481,8 @@ describe("Run actions", () => {
parameterValues,
endTime: 99
});
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();

(actions[RunAction.RunModel] as any)({
commit,
Expand Down Expand Up @@ -563,8 +563,8 @@ describe("Run actions", () => {
resultOde: isStochastic ? null : result,
resultDiscrete: isStochastic ? result : null
});
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();

(actions[RunAction.RunModelOnRehydrate] as any)({
commit,
Expand Down Expand Up @@ -623,26 +623,24 @@ describe("Run actions", () => {
testRunModelOnRehydrate(AppType.Fit);
});

it("downloads output", (done) => {
const commit = jest.fn();
it("downloads output", async () => {
const commit = vi.fn();
const context = { commit };
const payload = { fileName: "myFile.xlsx", points: 101 };
(actions[RunAction.DownloadOutput] as any)(context, payload);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(RunMutation.SetDownloading);
expect(commit.mock.calls[0][1]).toBe(true);
setTimeout(() => {
expect(mockWodinModelOutputDownload).toHaveBeenCalledTimes(1); // expect download constructor
expect(mockWodinModelOutputDownload.mock.calls[0][0]).toBe(context);
expect(mockWodinModelOutputDownload.mock.calls[0][1]).toBe("myFile.xlsx");
expect(mockWodinModelOutputDownload.mock.calls[0][2]).toBe(101);
expect(mockDownloadModelOutput).toHaveBeenCalledTimes(1);

expect(commit).toHaveBeenCalledTimes(2);
expect(commit.mock.calls[1][0]).toBe(RunMutation.SetDownloading);
expect(commit.mock.calls[1][1]).toBe(false);
done();
}, 20);
await new Promise(res => setTimeout(res, 20));
expect(mockWodinModelOutputDownload).toHaveBeenCalledTimes(1); // expect download constructor
expect(mockWodinModelOutputDownload.mock.calls[0][0]).toBe(context);
expect(mockWodinModelOutputDownload.mock.calls[0][1]).toBe("myFile.xlsx");
expect(mockWodinModelOutputDownload.mock.calls[0][2]).toBe(101);
expect(mockDownloadModelOutput).toHaveBeenCalledTimes(1);

expect(commit).toHaveBeenCalledTimes(2);
expect(commit.mock.calls[1][0]).toBe(RunMutation.SetDownloading);
expect(commit.mock.calls[1][1]).toBe(false);
});

it("NewParameterSet commits parameter set and result", () => {
Expand All @@ -660,7 +658,7 @@ describe("Run actions", () => {
],
resultOde: { solution: "fake result" } as any
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.NewParameterSet] as any)({ state, getters, commit });
expect(commit).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -696,7 +694,7 @@ describe("Run actions", () => {
const testGetters = {
[RunGetter.runIsRequired]: true
};
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.NewParameterSet] as any)({ state, getters: testGetters, commit });
expect(commit).toHaveBeenCalledTimes(0);
Expand All @@ -717,7 +715,7 @@ describe("Run actions", () => {
],
resultOde: null
});
const commit = jest.fn();
const commit = vi.fn();

(actions[RunAction.NewParameterSet] as any)({ state, getters, commit });
expect(commit).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -751,7 +749,7 @@ describe("Run actions", () => {
resultOde: { solution: "fake result" } as any
});

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

const testGetters = {
[RunGetter.runIsRequired]: false
Expand Down Expand Up @@ -787,14 +785,14 @@ describe("Run actions", () => {
[RunGetter.runIsRequired]: true
};

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

(actions[RunAction.SwapParameterSet] as any)({ state, getters: testGetters, commit });
expect(commit).toHaveBeenCalledTimes(0);
});

it("DeleteParameterSet commits run and sensitivity mutations", () => {
const commit = jest.fn();
const commit = vi.fn();
(actions[RunAction.DeleteParameterSet] as any)({ commit }, "Set 1");
expect(commit).toHaveBeenCalledTimes(2);
expect(commit.mock.calls[0][0]).toBe(RunMutation.DeleteParameterSet);
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/unit/store/run/getters.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getters, RunGetter } from "../../../../src/app/store/run/getters";
import { getters, RunGetter } from "../../../../src/store/run/getters";
import { mockRunState } from "../../../mocks";

describe("Run getters", () => {
Expand Down
6 changes: 3 additions & 3 deletions app/static/tests/unit/store/run/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RunMutation, mutations } from "../../../../src/app/store/run/mutations";
import { AdvancedComponentType } from "../../../../src/app/store/run/state";
import { AdvancedOptions } from "../../../../src/app/types/responseTypes";
import { RunMutation, mutations } from "../../../../src/store/run/mutations";
import { AdvancedComponentType } from "../../../../src/store/run/state";
import { AdvancedOptions } from "../../../../src/types/responseTypes";
import { mockRunState } from "../../../mocks";

describe("Run mutations", () => {
Expand Down

0 comments on commit 6f4eb12

Please sign in to comment.