From 1f79b298766cfa5d24db863cca97872ef74bca74 Mon Sep 17 00:00:00 2001 From: Mantra Date: Fri, 1 Sep 2023 12:39:29 +0100 Subject: [PATCH] tests --- app/static/tests/mocks.ts | 6 ++- .../tests/unit/components/fit/support.test.ts | 12 +++-- .../options/advancedSettings.test.ts | 48 ++++++++++++++++++- .../components/sensitivity/support.test.ts | 12 +++-- app/static/tests/unit/serialiser.test.ts | 12 +++-- .../unit/store/modelFit/mutations.test.ts | 3 +- .../unit/store/sensitivity/actions.test.ts | 12 +++-- .../unit/store/sensitivity/getters.test.ts | 5 +- 8 files changed, 88 insertions(+), 22 deletions(-) diff --git a/app/static/tests/mocks.ts b/app/static/tests/mocks.ts index a841935ea..af936b536 100644 --- a/app/static/tests/mocks.ts +++ b/app/static/tests/mocks.ts @@ -170,7 +170,8 @@ export const mockSensitivityState = (state: Partial = {}): Sen parameterValueChanged: false, endTimeChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }, result: null, parameterSetResults: {}, @@ -214,7 +215,8 @@ export const mockModelFitState = (state: Partial = {}): ModelFitS dataChanged: false, linkChanged: false, parameterValueChanged: false, - parameterToVaryChanged: false + parameterToVaryChanged: false, + advancedSettingsChanged: false }, iterations: null, converged: null, diff --git a/app/static/tests/unit/components/fit/support.test.ts b/app/static/tests/unit/components/fit/support.test.ts index dcb594dd1..9576516a4 100644 --- a/app/static/tests/unit/components/fit/support.test.ts +++ b/app/static/tests/unit/components/fit/support.test.ts @@ -57,7 +57,8 @@ describe("construct actionable fit update messages from fit state changes", () = dataChanged: false, linkChanged: false, parameterValueChanged: false, - parameterToVaryChanged: false + parameterToVaryChanged: false, + advancedSettingsChanged: false }; it("shows fallback when no reason can be found", () => { @@ -72,11 +73,12 @@ describe("construct actionable fit update messages from fit state changes", () = dataChanged: true, linkChanged: true, parameterValueChanged: true, - parameterToVaryChanged: true + parameterToVaryChanged: true, + advancedSettingsChanged: true }; expect(fitUpdateRequiredExplanation(everything)) - .toBe("Fit is out of date: model has been recompiled and data have been updated. " - + "Rerun fit to update."); + .toBe("Fit is out of date: model has been recompiled, data have been updated " + + "and advanced settings have been changed. Rerun fit to update."); }); it("gives specific messages when little has changed", () => { @@ -92,5 +94,7 @@ describe("construct actionable fit update messages from fit state changes", () = .toBe(`${prefix}: parameters have been updated. ${suffix}`); expect(fitUpdateRequiredExplanation({ ...base, parameterToVaryChanged: true })) .toBe(`${prefix}: parameters to vary have been updated. ${suffix}`); + expect(fitUpdateRequiredExplanation({ ...base, advancedSettingsChanged: true })) + .toBe(`${prefix}: advanced settings have been changed. ${suffix}`); }); }); diff --git a/app/static/tests/unit/components/options/advancedSettings.test.ts b/app/static/tests/unit/components/options/advancedSettings.test.ts index fa232bbc4..8c4959aed 100644 --- a/app/static/tests/unit/components/options/advancedSettings.test.ts +++ b/app/static/tests/unit/components/options/advancedSettings.test.ts @@ -1,18 +1,26 @@ import { VueWrapper, shallowMount } from "@vue/test-utils"; import Vuex from "vuex"; import AdvancedSettings from "../../../../src/app/components/options/AdvancedSettings.vue"; -import { mockRunState } from "../../../mocks"; +import { mockModelFitState, mockRunState, mockSensitivityState } from "../../../mocks"; import { RunMutation } from "../../../../src/app/store/run/mutations"; import NumericInput from "../../../../src/app/components/options/NumericInput.vue"; import StandardFormInput from "../../../../src/app/components/options/StandardFormInput.vue"; import { AdvancedOptions } from "../../../../src/app/types/responseTypes"; import TagInput from "../../../../src/app/components/options/TagInput.vue"; +import { ModelFitMutation } from "../../../../src/app/store/modelFit/mutations"; +import { SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations"; +import { AppType } from "../../../../src/app/store/appState/state"; describe("Advanced Settings", () => { const mockUpdateAdvancedSettings = jest.fn(); + const mockSetFitUpdateRequired = jest.fn(); + const mockSetSensitivityUpdateRequired = jest.fn(); - const getWrapper = () => { + const getWrapper = (isFit = false) => { const store = new Vuex.Store({ + state: { + appType: isFit ? AppType.Fit : AppType.Basic + }, modules: { run: { namespaced: true, @@ -20,6 +28,20 @@ describe("Advanced Settings", () => { mutations: { [RunMutation.UpdateAdvancedSettings]: mockUpdateAdvancedSettings } + }, + modelFit: { + namespaced: true, + state: mockModelFitState(), + mutations: { + [ModelFitMutation.SetFitUpdateRequired]: mockSetFitUpdateRequired + } + }, + sensitivity: { + namespaced: true, + state: mockSensitivityState(), + mutations: { + [SensitivityMutation.SetUpdateRequired]: mockSetSensitivityUpdateRequired + } } } }); @@ -88,4 +110,26 @@ describe("Advanced Settings", () => { expect(mockUpdateAdvancedSettings.mock.calls[0][1]) .toStrictEqual({ newVal: [2, 3], option: AdvancedOptions.tol }); }); + + it("commits update required to both fit and sensitivity when on fit app", () => { + const wrapper = getWrapper(true); + + const inputs = wrapper.findAllComponents(NumericInput); + inputs[0].vm.$emit("update", 2); + + expect(mockUpdateAdvancedSettings).toBeCalledTimes(1); + expect(mockSetFitUpdateRequired).toBeCalledTimes(1); + expect(mockSetSensitivityUpdateRequired).toBeCalledTimes(1); + }); + + it("commits update required to only sensitivity when not on fit app", () => { + const wrapper = getWrapper(); + + const inputs = wrapper.findAllComponents(NumericInput); + inputs[0].vm.$emit("update", 2); + + expect(mockUpdateAdvancedSettings).toBeCalledTimes(1); + expect(mockSetFitUpdateRequired).toBeCalledTimes(0); + expect(mockSetSensitivityUpdateRequired).toBeCalledTimes(1); + }); }); diff --git a/app/static/tests/unit/components/sensitivity/support.test.ts b/app/static/tests/unit/components/sensitivity/support.test.ts index 8d7addf58..26176ffdc 100644 --- a/app/static/tests/unit/components/sensitivity/support.test.ts +++ b/app/static/tests/unit/components/sensitivity/support.test.ts @@ -11,7 +11,8 @@ describe("construct actionable fit update messages from fit state changes", () = parameterValueChanged: false, endTimeChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }; it("shows fallback when no reason can be found", () => { @@ -26,11 +27,12 @@ describe("construct actionable fit update messages from fit state changes", () = parameterValueChanged: true, endTimeChanged: true, sensitivityOptionsChanged: true, - numberOfReplicatesChanged: true + numberOfReplicatesChanged: true, + advancedSettingsChanged: true }; expect(sensitivityUpdateRequiredExplanation(everything)) - .toBe("Plot is out of date: model code has been recompiled. " - + "Run sensitivity to update."); + .toBe("Plot is out of date: model code has been recompiled and advanced settings have been " + + "changed. Run sensitivity to update."); }); it("gives specific messages when little has changed", () => { @@ -46,6 +48,8 @@ describe("construct actionable fit update messages from fit state changes", () = .toBe(`${prefix}: sensitivity options have been changed. ${suffix}`); expect(sensitivityUpdateRequiredExplanation({ ...base, numberOfReplicatesChanged: true })) .toBe(`${prefix}: number of replicates has changed. ${suffix}`); + expect(sensitivityUpdateRequiredExplanation({ ...base, advancedSettingsChanged: true })) + .toBe(`${prefix}: advanced settings have been changed. ${suffix}`); }); }); diff --git a/app/static/tests/unit/serialiser.test.ts b/app/static/tests/unit/serialiser.test.ts index 2a9ae6500..65c6992db 100644 --- a/app/static/tests/unit/serialiser.test.ts +++ b/app/static/tests/unit/serialiser.test.ts @@ -168,7 +168,8 @@ describe("serialise", () => { parameterValueChanged: false, endTimeChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }, plotSettings: { plotType: SensitivityPlotType.ValueAtTime, @@ -228,7 +229,8 @@ describe("serialise", () => { dataChanged: false, linkChanged: true, parameterValueChanged: false, - parameterToVaryChanged: false + parameterToVaryChanged: false, + advancedSettingsChanged: false }, iterations: 28, converged: true, @@ -357,7 +359,8 @@ describe("serialise", () => { parameterValueChanged: false, endTimeChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }, plotSettings: sensitivityState.plotSettings, result: { @@ -394,7 +397,8 @@ describe("serialise", () => { dataChanged: false, linkChanged: true, parameterValueChanged: false, - parameterToVaryChanged: false + parameterToVaryChanged: false, + advancedSettingsChanged: false }, iterations: 28, converged: true, diff --git a/app/static/tests/unit/store/modelFit/mutations.test.ts b/app/static/tests/unit/store/modelFit/mutations.test.ts index e9fc1ca1a..ea6e0b5f2 100644 --- a/app/static/tests/unit/store/modelFit/mutations.test.ts +++ b/app/static/tests/unit/store/modelFit/mutations.test.ts @@ -68,7 +68,8 @@ describe("ModelFit mutations", () => { linkChanged: false, modelChanged: false, parameterValueChanged: false, - parameterToVaryChanged: false + parameterToVaryChanged: false, + advancedSettingsChanged: false }; expect(state.fitUpdateRequired).toEqual(base); mutations.SetFitUpdateRequired(state, { dataChanged: true }); diff --git a/app/static/tests/unit/store/sensitivity/actions.test.ts b/app/static/tests/unit/store/sensitivity/actions.test.ts index 9caa76409..c76c9c48e 100644 --- a/app/static/tests/unit/store/sensitivity/actions.test.ts +++ b/app/static/tests/unit/store/sensitivity/actions.test.ts @@ -98,7 +98,8 @@ describe("Sensitivity actions", () => { modelChanged: false, parameterValueChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }); expect(mockRunnerOde.batchRun).toHaveBeenCalledWith( @@ -165,7 +166,8 @@ describe("Sensitivity actions", () => { modelChanged: false, parameterValueChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }); expect(mockRunnerOde.batchRun).toHaveBeenCalledTimes(3); @@ -438,7 +440,8 @@ describe("Sensitivity actions", () => { modelChanged: false, parameterValueChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }); expect(mockRunnerDiscrete.batchRunDiscrete) @@ -518,7 +521,8 @@ describe("Sensitivity actions", () => { modelChanged: false, parameterValueChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }); expect(mockRunnerOde.batchRun).toHaveBeenCalledWith( diff --git a/app/static/tests/unit/store/sensitivity/getters.test.ts b/app/static/tests/unit/store/sensitivity/getters.test.ts index f462bfe7d..5d36c844b 100644 --- a/app/static/tests/unit/store/sensitivity/getters.test.ts +++ b/app/static/tests/unit/store/sensitivity/getters.test.ts @@ -86,7 +86,8 @@ describe("Sensitivity getters", () => { parameterValueChanged: false, endTimeChanged: false, sensitivityOptionsChanged: false, - numberOfReplicatesChanged: false + numberOfReplicatesChanged: false, + advancedSettingsChanged: false }; it("parameterSetSensitivityUpdateRequired is true if any reason except parameterValueChanged is true", () => { @@ -128,6 +129,8 @@ describe("Sensitivity getters", () => { expect(paramSetSensUpdateRequired(state, {}, rootState)).toBe(true); state = getStateWithUpdateRequiredReason("sensitivityOptionsChanged"); expect(paramSetSensUpdateRequired(state, {}, rootState)).toBe(true); + state = getStateWithUpdateRequiredReason("advancedSettingsChanged"); + expect(paramSetSensUpdateRequired(state, {}, rootState)).toBe(true); }); it("parameterSetSensitivityUpdateRequired returns false if no parameter sets", () => {