From 5cefc2bf0d8a5d8653fdeaa1ceed71b56ec9f0e0 Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 18:02:59 +0000 Subject: [PATCH] store tests done --- app/static/tests/unit/store/fit/fit.test.ts | 8 +- .../tests/unit/store/model/actions.test.ts | 78 ++++---- .../tests/unit/store/model/getters.test.ts | 2 +- .../tests/unit/store/model/mutations.test.ts | 2 +- .../tests/unit/store/modelFit/actions.test.ts | 177 +++++++++--------- .../tests/unit/store/modelFit/getters.test.ts | 2 +- .../unit/store/modelFit/mutations.test.ts | 4 +- app/static/tests/unit/store/plugins.test.ts | 16 +- .../tests/unit/store/sessions/actions.test.ts | 74 ++++---- .../unit/store/sessions/mutations.test.ts | 2 +- .../unit/store/stochastic/stochastic.test.ts | 8 +- .../tests/unit/store/versions/actions.test.ts | 4 +- .../unit/store/versions/mutations.test.ts | 2 +- 13 files changed, 183 insertions(+), 196 deletions(-) diff --git a/app/static/tests/unit/store/fit/fit.test.ts b/app/static/tests/unit/store/fit/fit.test.ts index a3066d208..048971a67 100644 --- a/app/static/tests/unit/store/fit/fit.test.ts +++ b/app/static/tests/unit/store/fit/fit.test.ts @@ -1,14 +1,12 @@ -import { localStorageManager } from "../../../../src/app/localStorageManager"; - -jest.mock("../../../../src/app/utils", () => { +vi.mock("../../../../src/utils", () => { return { - newUid: jest.fn().mockReturnValue("12345") + newUid: vi.fn().mockReturnValue("12345") }; }); describe("fit", () => { it("generates and saves sessionId", async () => { - const { storeOptions } = await import("../../../../src/app/store/fit/fit"); + const { storeOptions } = await import("../../../../src/store/fit/fit"); const state = storeOptions.state as any; expect(state.sessionId).toBe("12345"); }); diff --git a/app/static/tests/unit/store/model/actions.test.ts b/app/static/tests/unit/store/model/actions.test.ts index 1e2c16c27..9fb3ff748 100644 --- a/app/static/tests/unit/store/model/actions.test.ts +++ b/app/static/tests/unit/store/model/actions.test.ts @@ -10,20 +10,20 @@ import { mockSuccess, mockFitState } from "../../../mocks"; -import { actions, ModelAction } from "../../../../src/app/store/model/actions"; -import { ModelMutation, mutations } from "../../../../src/app/store/model/mutations"; -import { BasicState } from "../../../../src/app/store/basic/state"; -import { AppType } from "../../../../src/app/store/appState/state"; -import { actions as runActions, RunAction } from "../../../../src/app/store/run/actions"; -import { FitDataAction } from "../../../../src/app/store/fitData/actions"; -import { ModelFitAction } from "../../../../src/app/store/modelFit/actions"; -import { RunMutation, mutations as runMutations } from "../../../../src/app/store/run/mutations"; -import { ModelFitMutation } from "../../../../src/app/store/modelFit/mutations"; -import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations"; -import { MultiSensitivityMutation } from "../../../../src/app/store/multiSensitivity/mutations"; -import { defaultSensitivityParamSettings } from "../../../../src/app/store/sensitivity/sensitivity"; -import { GraphsMutation } from "../../../../src/app/store/graphs/mutations"; -import { GraphsAction } from "../../../../src/app/store/graphs/actions"; +import { actions, ModelAction } from "../../../../src/store/model/actions"; +import { ModelMutation, mutations } from "../../../../src/store/model/mutations"; +import { BasicState } from "../../../../src/store/basic/state"; +import { AppType } from "../../../../src/store/appState/state"; +import { actions as runActions, RunAction } from "../../../../src/store/run/actions"; +import { FitDataAction } from "../../../../src/store/fitData/actions"; +import { ModelFitAction } from "../../../../src/store/modelFit/actions"; +import { RunMutation, mutations as runMutations } from "../../../../src/store/run/mutations"; +import { ModelFitMutation } from "../../../../src/store/modelFit/mutations"; +import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/store/sensitivity/mutations"; +import { MultiSensitivityMutation } from "../../../../src/store/multiSensitivity/mutations"; +import { defaultSensitivityParamSettings } from "../../../../src/store/sensitivity/sensitivity"; +import { GraphsMutation } from "../../../../src/store/graphs/mutations"; +import { GraphsAction } from "../../../../src/store/graphs/actions"; describe("Model actions", () => { beforeEach(() => { @@ -64,7 +64,7 @@ describe("Model actions", () => { const mockRunnerScript = '() => "runner"'; mockAxios.onGet("/odin/runner/ode").reply(200, mockSuccess(mockRunnerScript)); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdinRunner] as any)({ commit, rootState }); expect(commit.mock.calls.length).toBe(1); @@ -79,7 +79,7 @@ describe("Model actions", () => { mockAxios.onGet("/odin/runner/ode").reply(200, mockSuccess(mockRunnerOdeScript)); mockAxios.onGet("/odin/runner/discrete").reply(200, mockSuccess(mockRunnerDiscreteScript)); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdinRunner] as any)({ commit, rootState: stochasticRootState }); expect(commit.mock.calls.length).toBe(2); @@ -92,7 +92,7 @@ describe("Model actions", () => { it("commits error from fetch odin runner", async () => { mockAxios.onGet("/odin/runner/ode").reply(500, mockFailure("server error")); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdinRunner] as any)({ commit, rootState }); expect(commit.mock.calls[0][0]).toBe("errors/AddError"); @@ -103,7 +103,7 @@ describe("Model actions", () => { const testModel = { model: "test" }; mockAxios.onPost("/odin/model").reply(200, mockSuccess(testModel)); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdin] as any)({ commit, rootState }); const postData = JSON.parse(mockAxios.history.post[0].data); @@ -126,7 +126,7 @@ describe("Model actions", () => { mockAxios.onPost("/odin/model").reply(200, mockSuccess(testModel)); const stochasticRootState = { ...rootState, appType: AppType.Stochastic }; - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdin] as any)({ commit, rootState: stochasticRootState }); const postData = JSON.parse(mockAxios.history.post[0].data); @@ -143,7 +143,7 @@ describe("Model actions", () => { it("commits error from fetch odin model", async () => { mockAxios.onPost("/odin/model").reply(500, mockFailure("server error")); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[ModelAction.FetchOdin] as any)({ commit, rootState }); expect(commit.mock.calls[0][0]).toBe("errors/AddError"); @@ -168,8 +168,8 @@ describe("Model actions", () => { }; it("compiles model, sets parameter values and updates required action", () => { - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, dispatch, @@ -211,8 +211,8 @@ describe("Model actions", () => { }); it("does not set multi-sensitivity update required or parameter to vary when multiSensitivity not enabled", () => { - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const noMultiRootState = { config: { multiSensitivity: false }, sensitivity: { @@ -247,8 +247,8 @@ describe("Model actions", () => { multiSensitivity: undefined } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, dispatch, @@ -267,8 +267,8 @@ describe("Model actions", () => { paramSettings: [{ parameterToVary: "p1" }] } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, dispatch, @@ -307,8 +307,8 @@ describe("Model actions", () => { config: [{ selectedVariables: ["x", "y"], unselectedVariables: [] }] } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, dispatch, @@ -361,8 +361,8 @@ describe("Model actions", () => { parameterValues: { p2: 1, p3: 2 } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const testRootState = { ...rootState, sensitivity: { @@ -407,8 +407,8 @@ describe("Model actions", () => { } as any, compileRequired: false }); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, dispatch, state, rootState }); expect(commit.mock.calls.length).toBe(5); expect(commit.mock.calls[0][0]).toBe(ModelMutation.SetOdin); @@ -428,7 +428,7 @@ describe("Model actions", () => { it("compile model does nothing if no odin response", () => { const state = mockModelState(); - const commit = jest.fn(); + const commit = vi.fn(); (actions[ModelAction.CompileModel] as any)({ commit, state, rootState }); expect(commit.mock.calls.length).toBe(0); }); @@ -439,8 +439,8 @@ describe("Model actions", () => { model: "1+2" } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelAction.CompileModelOnRehydrate] as any)({ commit, state, rootState }); expect(commit.mock.calls.length).toBe(1); expect(commit.mock.calls[0][0]).toBe(ModelMutation.SetOdin); @@ -496,8 +496,8 @@ describe("Model actions", () => { }; mockAxios.onPost("/odin/model").reply(200, mockSuccess(testModel)); - const commit = jest.spyOn(store, "commit"); - const dispatch = jest.spyOn(store, "dispatch"); + const commit = vi.spyOn(store, "commit"); + const dispatch = vi.spyOn(store, "dispatch"); await store.dispatch(`model/${ModelAction.DefaultModel}`); diff --git a/app/static/tests/unit/store/model/getters.test.ts b/app/static/tests/unit/store/model/getters.test.ts index 960c6ec7a..34ddf751e 100644 --- a/app/static/tests/unit/store/model/getters.test.ts +++ b/app/static/tests/unit/store/model/getters.test.ts @@ -1,4 +1,4 @@ -import { ModelGetter, getters } from "../../../../src/app/store/model/getters"; +import { ModelGetter, getters } from "../../../../src/store/model/getters"; import { mockBasicState, mockModelState, mockStochasticState } from "../../../mocks"; describe("ModelGetters", () => { diff --git a/app/static/tests/unit/store/model/mutations.test.ts b/app/static/tests/unit/store/model/mutations.test.ts index 92d50851b..8babecdcc 100644 --- a/app/static/tests/unit/store/model/mutations.test.ts +++ b/app/static/tests/unit/store/model/mutations.test.ts @@ -1,4 +1,4 @@ -import { mutations } from "../../../../src/app/store/model/mutations"; +import { mutations } from "../../../../src/store/model/mutations"; import { mockError, mockModelState } from "../../../mocks"; describe("Model mutations", () => { diff --git a/app/static/tests/unit/store/modelFit/actions.test.ts b/app/static/tests/unit/store/modelFit/actions.test.ts index eb3f018fb..be59d556e 100644 --- a/app/static/tests/unit/store/modelFit/actions.test.ts +++ b/app/static/tests/unit/store/modelFit/actions.test.ts @@ -1,16 +1,16 @@ -import resetAllMocks = jest.resetAllMocks; -import { ModelFitMutation } from "../../../../src/app/store/modelFit/mutations"; +import { ModelFitMutation } from "../../../../src/store/modelFit/mutations"; import { mockFitDataState, mockModelFitState, mockModelState, mockRunState } from "../../../mocks"; -import { actions, ModelFitAction } from "../../../../src/app/store/modelFit/actions"; -import { RunMutation } from "../../../../src/app/store/run/mutations"; -import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations"; -import { AdvancedOptions } from "../../../../src/app/types/responseTypes"; -import { AdvancedComponentType } from "../../../../src/app/store/run/state"; +import { actions, ModelFitAction } from "../../../../src/store/modelFit/actions"; +import { RunMutation } from "../../../../src/store/run/mutations"; +import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/store/sensitivity/mutations"; +import { AdvancedOptions } from "../../../../src/types/responseTypes"; +import { AdvancedComponentType } from "../../../../src/store/run/state"; +import { nextTick } from "vue"; describe("ModelFit actions", () => { const mockSimplex = {} as any; - const mockWodinFit = jest.fn().mockReturnValue(mockSimplex); - const mockWodinFitValue = jest.fn().mockReturnValue(42); + const mockWodinFit = vi.fn().mockReturnValue(mockSimplex); + const mockWodinFitValue = vi.fn().mockReturnValue(42); const mockOdinRunner = { wodinFit: mockWodinFit, wodinFitValue: mockWodinFitValue @@ -64,7 +64,7 @@ describe("ModelFit actions", () => { }); afterEach(() => { - resetAllMocks(); + vi.resetAllMocks(); }); it("FitModel calls wodinFit and dispatches FitModelStep action", () => { @@ -74,8 +74,8 @@ describe("ModelFit actions", () => { "fitData/link": link, "fitData/dataEnd": 100 }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const expectedData = { time: [0, 1, 2], value: [10, 20, 30] @@ -127,8 +127,8 @@ describe("ModelFit actions", () => { it("FitModel does nothing if cannot fit model", () => { const getters = { fitRequirements: { hasData: false } }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelFitAction.FitModel] as any)({ commit, @@ -144,7 +144,7 @@ describe("ModelFit actions", () => { it("FitModel commits error thrown during wodinFit", () => { const runner = { - wodinFit: jest.fn().mockImplementation(() => { + wodinFit: vi.fn().mockImplementation(() => { throw new Error("TEST ERROR"); }), wodinFitValue: mockWodinFitValue @@ -162,8 +162,8 @@ describe("ModelFit actions", () => { "fitData/link": link, "fitData/dataEnd": 100 }; - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); (actions[ModelFitAction.FitModel] as any)({ commit, dispatch, @@ -182,7 +182,7 @@ describe("ModelFit actions", () => { expect(commit.mock.calls[2][1]).toBe(false); }); - it("FitModelStep commits expected changes and dispatches further step if not converged", (done) => { + it("FitModelStep commits expected changes and dispatches further step if not converged", async () => { const result = { converged: false, data: { @@ -192,7 +192,7 @@ describe("ModelFit actions", () => { } }; const simplex = { - step: jest.fn(), + step: vi.fn(), result: () => result } as any; @@ -200,8 +200,9 @@ describe("ModelFit actions", () => { fitting: true }); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); + vi.useFakeTimers(); (actions[ModelFitAction.FitModelStep] as any)( { commit, @@ -211,31 +212,29 @@ describe("ModelFit actions", () => { }, simplex ); - - setTimeout(() => { - expect(simplex.step).toHaveBeenCalledTimes(1); - expect(commit).toHaveBeenCalledTimes(4); - expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); - expect(commit.mock.calls[0][1]).toBe(result); - expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); - expect(commit.mock.calls[1][1]).toBe(result.data.pars); - expect(commit.mock.calls[1][2]).toStrictEqual({ root: true }); - expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); - expect(commit.mock.calls[2][1]).toStrictEqual({ - inputs: { endTime: 99, parameterValues: {} }, - solution: "solution", - error: null - }); - expect(commit.mock.calls[2][2]).toStrictEqual({ root: true }); - expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); - expect(commit.mock.calls[3][1]).toStrictEqual({ parameterValueChanged: true }); - expect(commit.mock.calls[3][2]).toStrictEqual({ root: true }); - - expect(dispatch).toHaveBeenCalledTimes(1); - expect(dispatch.mock.calls[0][0]).toBe(ModelFitAction.FitModelStep); - expect(dispatch.mock.calls[0][1]).toBe(simplex); - done(); + vi.advanceTimersByTime(1); + vi.useRealTimers(); + expect(simplex.step).toHaveBeenCalledTimes(1); + expect(commit).toHaveBeenCalledTimes(4); + expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); + expect(commit.mock.calls[0][1]).toBe(result); + expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); + expect(commit.mock.calls[1][1]).toBe(result.data.pars); + expect(commit.mock.calls[1][2]).toStrictEqual({ root: true }); + expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); + expect(commit.mock.calls[2][1]).toStrictEqual({ + inputs: { endTime: 99, parameterValues: {} }, + solution: "solution", + error: null }); + expect(commit.mock.calls[2][2]).toStrictEqual({ root: true }); + expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); + expect(commit.mock.calls[3][1]).toStrictEqual({ parameterValueChanged: true }); + expect(commit.mock.calls[3][2]).toStrictEqual({ root: true }); + + expect(dispatch).toHaveBeenCalledTimes(1); + expect(dispatch.mock.calls[0][0]).toBe(ModelFitAction.FitModelStep); + expect(dispatch.mock.calls[0][1]).toBe(simplex); }); const result = { @@ -245,13 +244,13 @@ describe("ModelFit actions", () => { } }; const simplex = { - step: jest.fn(), + step: vi.fn(), result: () => result } as any; - it("FitModelStep does not dispatch further step if converged", (done) => { - const commit = jest.fn(); - const dispatch = jest.fn(); + it("FitModelStep does not dispatch further step if converged", async () => { + const commit = vi.fn(); + const dispatch = vi.fn(); const testState = mockModelFitState({ fitting: true }); (actions[ModelFitAction.FitModelStep] as any)( { @@ -262,25 +261,22 @@ describe("ModelFit actions", () => { }, simplex ); + await nextTick(); + expect(simplex.step).toHaveBeenCalledTimes(1); + expect(commit).toHaveBeenCalledTimes(5); + expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); + expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); + expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); + expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); + expect(commit.mock.calls[4][0]).toBe(ModelFitMutation.SetFitting); + expect(commit.mock.calls[4][1]).toBe(false); - setTimeout(() => { - expect(simplex.step).toHaveBeenCalledTimes(1); - expect(commit).toHaveBeenCalledTimes(5); - expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); - expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); - expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); - expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); - expect(commit.mock.calls[4][0]).toBe(ModelFitMutation.SetFitting); - expect(commit.mock.calls[4][1]).toBe(false); - - expect(dispatch).not.toHaveBeenCalled(); - done(); - }); + expect(dispatch).not.toHaveBeenCalled(); }); - it("FitModelStep commits multiSensitivity SetUpdateRequired if multiSensitivity is enabled", (done) => { - const commit = jest.fn(); - const dispatch = jest.fn(); + it("FitModelStep commits multiSensitivity SetUpdateRequired if multiSensitivity is enabled", async () => { + const commit = vi.fn(); + const dispatch = vi.fn(); const testState = mockModelFitState({ fitting: true }); const testRootState = { config: { multiSensitivity: true } @@ -294,23 +290,20 @@ describe("ModelFit actions", () => { }, simplex ); + await nextTick(); + expect(simplex.step).toHaveBeenCalledTimes(1); + expect(commit).toHaveBeenCalledTimes(6); + expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); + expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); + expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); + const expectedReason = { parameterValueChanged: true }; + expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); + expect(commit.mock.calls[3][1]).toStrictEqual(expectedReason); + expect(commit.mock.calls[4][0]).toBe(`multiSensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); + expect(commit.mock.calls[4][1]).toStrictEqual(expectedReason); + expect(commit.mock.calls[5][0]).toBe(ModelFitMutation.SetFitting); - setTimeout(() => { - expect(simplex.step).toHaveBeenCalledTimes(1); - expect(commit).toHaveBeenCalledTimes(6); - expect(commit.mock.calls[0][0]).toBe(ModelFitMutation.SetResult); - expect(commit.mock.calls[1][0]).toBe(`run/${RunMutation.SetParameterValues}`); - expect(commit.mock.calls[2][0]).toBe(`run/${RunMutation.SetResultOde}`); - const expectedReason = { parameterValueChanged: true }; - expect(commit.mock.calls[3][0]).toBe(`sensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); - expect(commit.mock.calls[3][1]).toStrictEqual(expectedReason); - expect(commit.mock.calls[4][0]).toBe(`multiSensitivity/${BaseSensitivityMutation.SetUpdateRequired}`); - expect(commit.mock.calls[4][1]).toStrictEqual(expectedReason); - expect(commit.mock.calls[5][0]).toBe(ModelFitMutation.SetFitting); - - expect(dispatch).not.toHaveBeenCalled(); - done(); - }); + expect(dispatch).not.toHaveBeenCalled(); }); it("UpdateParamsToVary retains params to vary if possible", () => { @@ -318,7 +311,7 @@ describe("ModelFit actions", () => { paramsToVary: ["p1", "p3"] }; - const commit = jest.fn(); + const commit = vi.fn(); (actions[ModelFitAction.UpdateParamsToVary] as any)({ commit, state: modelFitState, rootState }); expect(commit).toHaveBeenCalledTimes(1); @@ -326,21 +319,19 @@ describe("ModelFit actions", () => { expect(commit.mock.calls[0][1]).toStrictEqual(["p1"]); }); - it("FitModelStep does nothing if not fitting", (done) => { - const commit = jest.fn(); - const dispatch = jest.fn(); + it("FitModelStep does nothing if not fitting", async () => { + const commit = vi.fn(); + const dispatch = vi.fn(); const testState = mockModelFitState({ fitting: false }); (actions[ModelFitAction.FitModelStep] as any)({ commit, dispatch, state: testState }, simplex); - setTimeout(() => { - expect(simplex.step).not.toHaveBeenCalled(); - expect(commit).not.toHaveBeenCalled(); - expect(dispatch).not.toHaveBeenCalled(); - done(); - }); + await nextTick(); + expect(simplex.step).not.toHaveBeenCalled(); + expect(commit).not.toHaveBeenCalled(); + expect(dispatch).not.toHaveBeenCalled(); }); it("UpdateSumOfSquares does nothing if fitting", () => { - const commit = jest.fn(); + const commit = vi.fn(); const testState = mockModelFitState({ fitting: true }); const rootGetters = null; const context = { @@ -355,7 +346,7 @@ describe("ModelFit actions", () => { it("UpdateSumOfSquares computes sum of squares if possible", () => { mockWodinFitValue.mockReturnValue(42); - const commit = jest.fn(); + const commit = vi.fn(); const testState = mockModelFitState({ fitting: false }); const link = { time: "t", data: "v", model: "S" }; const rootGetters = { diff --git a/app/static/tests/unit/store/modelFit/getters.test.ts b/app/static/tests/unit/store/modelFit/getters.test.ts index 2fb9d49a2..594909672 100644 --- a/app/static/tests/unit/store/modelFit/getters.test.ts +++ b/app/static/tests/unit/store/modelFit/getters.test.ts @@ -1,5 +1,5 @@ import { mockModelFitState } from "../../../mocks"; -import { getters, ModelFitGetter } from "../../../../src/app/store/modelFit/getters"; +import { getters, ModelFitGetter } from "../../../../src/store/modelFit/getters"; describe("ModelFit getters", () => { const model = { diff --git a/app/static/tests/unit/store/modelFit/mutations.test.ts b/app/static/tests/unit/store/modelFit/mutations.test.ts index cdab2d65b..809d90e3b 100644 --- a/app/static/tests/unit/store/modelFit/mutations.test.ts +++ b/app/static/tests/unit/store/modelFit/mutations.test.ts @@ -1,5 +1,5 @@ import { mockModelFitState } from "../../../mocks"; -import { mutations } from "../../../../src/app/store/modelFit/mutations"; +import { mutations } from "../../../../src/store/modelFit/mutations"; describe("ModelFit mutations", () => { const mockInputs = { @@ -45,7 +45,7 @@ describe("ModelFit mutations", () => { it("sets model fit result", () => { const state = mockModelFitState({ inputs: mockInputs }); - const solution = jest.fn(); + const solution = vi.fn(); const pars = { x: 1 }; const payload = { diff --git a/app/static/tests/unit/store/plugins.test.ts b/app/static/tests/unit/store/plugins.test.ts index 7c1138410..2b48f2e2f 100644 --- a/app/static/tests/unit/store/plugins.test.ts +++ b/app/static/tests/unit/store/plugins.test.ts @@ -1,12 +1,12 @@ import Vuex from "vuex"; -import { logMutations, persistState } from "../../../src/app/store/plugins"; -import { AppState } from "../../../src/app/store/appState/state"; -import { AppStateAction } from "../../../src/app/store/appState/actions"; -import { AppStateMutation } from "../../../src/app/store/appState/mutations"; +import { logMutations, persistState } from "../../../src/store/plugins"; +import { AppState } from "../../../src/store/appState/state"; +import { AppStateAction } from "../../../src/store/appState/actions"; +import { AppStateMutation } from "../../../src/store/appState/mutations"; describe("plugins", () => { it("logMutations logs mutations to console", () => { - const logSpy = jest.spyOn(console, "log"); + const logSpy = vi.spyOn(console, "log"); const store = new Vuex.Store({ mutations: { @@ -40,7 +40,7 @@ describe("plugins", () => { } } }); - const spyDispatch = jest.spyOn(store, "dispatch"); + const spyDispatch = vi.spyOn(store, "dispatch"); persistState(store); store.commit("testModule/test2"); expect(spyDispatch).toHaveBeenCalledWith(AppStateAction.QueueStateUpload); @@ -54,7 +54,7 @@ describe("plugins", () => { [AppStateMutation.SetStateUploadInProgress]: () => {} } }); - const spyDispatch = jest.spyOn(store, "dispatch"); + const spyDispatch = vi.spyOn(store, "dispatch"); persistState(store); store.commit(AppStateMutation.ClearQueuedStateUpload); @@ -74,7 +74,7 @@ describe("plugins", () => { } } }); - const spyDispatch = jest.spyOn(store, "dispatch"); + const spyDispatch = vi.spyOn(store, "dispatch"); persistState(store); store.commit("errors/addError"); diff --git a/app/static/tests/unit/store/sessions/actions.test.ts b/app/static/tests/unit/store/sessions/actions.test.ts index bb3551716..337b7ef0f 100644 --- a/app/static/tests/unit/store/sessions/actions.test.ts +++ b/app/static/tests/unit/store/sessions/actions.test.ts @@ -1,21 +1,21 @@ -import { actions, SessionsAction } from "../../../../src/app/store/sessions/actions"; +import { actions, SessionsAction } from "../../../../src/store/sessions/actions"; import { mockAxios, mockBasicState, mockFailure, mockSuccess, mockUserPreferences } from "../../../mocks"; -import { SessionsMutation } from "../../../../src/app/store/sessions/mutations"; -import { localStorageManager } from "../../../../src/app/localStorageManager"; -import { ErrorsMutation } from "../../../../src/app/store/errors/mutations"; -import { AppStateMutation } from "../../../../src/app/store/appState/mutations"; -import { ModelAction } from "../../../../src/app/store/model/actions"; -import { RunAction } from "../../../../src/app/store/run/actions"; -import { SensitivityAction } from "../../../../src/app/store/sensitivity/actions"; -import { AppStateGetter } from "../../../../src/app/store/appState/getters"; -import { MultiSensitivityAction } from "../../../../src/app/store/multiSensitivity/actions"; +import { SessionsMutation } from "../../../../src/store/sessions/mutations"; +import { localStorageManager } from "../../../../src/localStorageManager"; +import { ErrorsMutation } from "../../../../src/store/errors/mutations"; +import { AppStateMutation } from "../../../../src/store/appState/mutations"; +import { ModelAction } from "../../../../src/store/model/actions"; +import { RunAction } from "../../../../src/store/run/actions"; +import { SensitivityAction } from "../../../../src/store/sensitivity/actions"; +import { AppStateGetter } from "../../../../src/store/appState/getters"; +import { MultiSensitivityAction } from "../../../../src/store/multiSensitivity/actions"; describe("SessionsActions", () => { - const getSessionIdsSpy = jest.spyOn(localStorageManager, "getSessionIds").mockReturnValue(["123", "456"]); - const deleteSessionIdSpy = jest.spyOn(localStorageManager, "deleteSessionId"); + const getSessionIdsSpy = vi.spyOn(localStorageManager, "getSessionIds").mockReturnValue(["123", "456"]); + const deleteSessionIdSpy = vi.spyOn(localStorageManager, "deleteSessionId"); afterEach(() => { - jest.clearAllTimers(); + vi.clearAllTimers(); mockAxios.reset(); }); @@ -65,8 +65,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(true, false, !stochastic, stochastic, true, true); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -102,8 +102,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(false, false, true, false, true, false); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -119,8 +119,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(true, true, true, false, true, false); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -136,8 +136,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(true, false, false, false, true, false); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -159,8 +159,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(true, false, true, false, false, true); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -185,8 +185,8 @@ describe("SessionsActions", () => { const mockSessionData = getSessionData(true, false, true, false, true, false); mockAxios.onGet("/apps/testApp/sessions/1234").reply(200, mockSuccess(mockSessionData)); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any; await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234"); expect(rootState.code.currentCode).toStrictEqual(["some saved code"]); @@ -218,7 +218,7 @@ describe("SessionsActions", () => { const userPreferences = { ...mockUserPreferences(), showDuplicateSessions: false }; const rootState = mockBasicState({ appName: "test-app", appsPath: "apps", userPreferences }); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[SessionsAction.GetSessions] as any)({ commit, rootState, rootGetters }); expect(mockAxios.history.get[0].url).toBe(url); @@ -238,7 +238,7 @@ describe("SessionsActions", () => { const userPreferences = { ...mockUserPreferences(), showDuplicateSessions: true }; const rootState = mockBasicState({ appName: "test-app", appsPath: "apps", userPreferences }); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[SessionsAction.GetSessions] as any)({ commit, rootState, rootGetters }); expect(mockAxios.history.get[0].url).toBe(url); @@ -251,7 +251,7 @@ describe("SessionsActions", () => { const userPreferences = mockUserPreferences(); const rootState = mockBasicState({ appName: "test-app", appsPath: "apps", userPreferences }); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[SessionsAction.GetSessions] as any)({ commit, rootState, rootGetters }); expect(commit).toHaveBeenCalledTimes(1); @@ -268,8 +268,8 @@ describe("SessionsActions", () => { appsPath: "apps", sessionId: "testSessionId" }); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const payload = { id: "testSessionId", label: "newLabel" }; await (actions[SessionsAction.SaveSessionLabel] as any)({ commit, dispatch, rootState }, payload); @@ -295,8 +295,8 @@ describe("SessionsActions", () => { appsPath: "apps", sessionId: "testSessionId" }); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const payload = { id: "testSessionId", label: "newLabel" }; await (actions[SessionsAction.SaveSessionLabel] as any)({ commit, dispatch, rootState }, payload); @@ -319,8 +319,8 @@ describe("SessionsActions", () => { appsPath: "apps", sessionId: "anotherSessionId" }); - const commit = jest.fn(); - const dispatch = jest.fn(); + const commit = vi.fn(); + const dispatch = vi.fn(); const payload = { id: "testSessionId", label: "newLabel" }; await (actions[SessionsAction.SaveSessionLabel] as any)({ commit, dispatch, rootState }, payload); @@ -341,7 +341,7 @@ describe("SessionsActions", () => { appName: "testApp", appsPath: "apps" }); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[SessionsAction.GenerateFriendlyId] as any)({ commit, rootState }, "testSessionId"); expect(commit).toHaveBeenCalledTimes(1); @@ -356,7 +356,7 @@ describe("SessionsActions", () => { appName: "testApp", appsPath: "apps" }); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[SessionsAction.GenerateFriendlyId] as any)({ commit, rootState }, "testSessionId"); expect(commit).toHaveBeenCalledTimes(1); @@ -366,7 +366,7 @@ describe("SessionsActions", () => { }); it("DeleteSession removes from local storage and commits remove session id", async () => { - const commit = jest.fn(); + const commit = vi.fn(); const rootState = { appName: "testApp" }; await (actions[SessionsAction.DeleteSession] as any)({ commit, rootState, rootGetters }, "testSessionId"); expect(deleteSessionIdSpy).toHaveBeenCalledWith("testApp", "testInstance", "testSessionId"); diff --git a/app/static/tests/unit/store/sessions/mutations.test.ts b/app/static/tests/unit/store/sessions/mutations.test.ts index 0a4a5b78c..386ae988e 100644 --- a/app/static/tests/unit/store/sessions/mutations.test.ts +++ b/app/static/tests/unit/store/sessions/mutations.test.ts @@ -1,4 +1,4 @@ -import { SessionsMutation, mutations } from "../../../../src/app/store/sessions/mutations"; +import { SessionsMutation, mutations } from "../../../../src/store/sessions/mutations"; import { mockSessionsState } from "../../../mocks"; describe("Sessions mutations", () => { diff --git a/app/static/tests/unit/store/stochastic/stochastic.test.ts b/app/static/tests/unit/store/stochastic/stochastic.test.ts index c4a2e0fe7..103318192 100644 --- a/app/static/tests/unit/store/stochastic/stochastic.test.ts +++ b/app/static/tests/unit/store/stochastic/stochastic.test.ts @@ -1,14 +1,12 @@ -import { localStorageManager } from "../../../../src/app/localStorageManager"; - -jest.mock("../../../../src/app/utils", () => { +vi.mock("../../../../src/utils", () => { return { - newUid: jest.fn().mockReturnValue("12345") + newUid: vi.fn().mockReturnValue("12345") }; }); describe("stochasic", () => { it("generates and saves sessionId", async () => { - const { storeOptions } = await import("../../../../src/app/store/stochastic/stochastic"); + const { storeOptions } = await import("../../../../src/store/stochastic/stochastic"); const state = storeOptions.state as any; expect(state.sessionId).toBe("12345"); }); diff --git a/app/static/tests/unit/store/versions/actions.test.ts b/app/static/tests/unit/store/versions/actions.test.ts index b987cd6cf..7144348cd 100644 --- a/app/static/tests/unit/store/versions/actions.test.ts +++ b/app/static/tests/unit/store/versions/actions.test.ts @@ -1,4 +1,4 @@ -import { actions, VersionsAction } from "../../../../src/app/store/versions/actions"; +import { actions, VersionsAction } from "../../../../src/store/versions/actions"; import { mockAxios, mockSuccess } from "../../../mocks"; const versions = { @@ -12,7 +12,7 @@ describe("versions actions", () => { it("gets versions", async () => { mockAxios.onGet("/odin/versions").reply(200, mockSuccess(versions)); - const commit = jest.fn(); + const commit = vi.fn(); await (actions[VersionsAction.GetVersions] as any)({ commit, rootState: { baseUrl: "" } }); expect(mockAxios.history.get[0].url).toBe("/odin/versions"); expect(commit.mock.calls.length).toBe(1); diff --git a/app/static/tests/unit/store/versions/mutations.test.ts b/app/static/tests/unit/store/versions/mutations.test.ts index d957cc364..b2706b99e 100644 --- a/app/static/tests/unit/store/versions/mutations.test.ts +++ b/app/static/tests/unit/store/versions/mutations.test.ts @@ -1,4 +1,4 @@ -import { mutations, VersionsMutation } from "../../../../src/app/store/versions/mutations"; +import { mutations, VersionsMutation } from "../../../../src/store/versions/mutations"; describe("versions mutations", () => { it("can set versions", () => {