Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Sep 1, 2023
1 parent 346d680 commit 1f79b29
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 22 deletions.
6 changes: 4 additions & 2 deletions app/static/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export const mockSensitivityState = (state: Partial<SensitivityState> = {}): Sen
parameterValueChanged: false,
endTimeChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
},
result: null,
parameterSetResults: {},
Expand Down Expand Up @@ -214,7 +215,8 @@ export const mockModelFitState = (state: Partial<ModelFitState> = {}): ModelFitS
dataChanged: false,
linkChanged: false,
parameterValueChanged: false,
parameterToVaryChanged: false
parameterToVaryChanged: false,
advancedSettingsChanged: false
},
iterations: null,
converged: null,
Expand Down
12 changes: 8 additions & 4 deletions app/static/tests/unit/components/fit/support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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}`);
});
});
48 changes: 46 additions & 2 deletions app/static/tests/unit/components/options/advancedSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
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,
state: mockRunState(),
mutations: {
[RunMutation.UpdateAdvancedSettings]: mockUpdateAdvancedSettings
}
},
modelFit: {
namespaced: true,
state: mockModelFitState(),
mutations: {
[ModelFitMutation.SetFitUpdateRequired]: mockSetFitUpdateRequired
}
},
sensitivity: {
namespaced: true,
state: mockSensitivityState(),
mutations: {
[SensitivityMutation.SetUpdateRequired]: mockSetSensitivityUpdateRequired
}
}
}
});
Expand Down Expand Up @@ -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);
});
});
12 changes: 8 additions & 4 deletions app/static/tests/unit/components/sensitivity/support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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}`);
});
});

Expand Down
12 changes: 8 additions & 4 deletions app/static/tests/unit/serialiser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ describe("serialise", () => {
parameterValueChanged: false,
endTimeChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
},
plotSettings: {
plotType: SensitivityPlotType.ValueAtTime,
Expand Down Expand Up @@ -228,7 +229,8 @@ describe("serialise", () => {
dataChanged: false,
linkChanged: true,
parameterValueChanged: false,
parameterToVaryChanged: false
parameterToVaryChanged: false,
advancedSettingsChanged: false
},
iterations: 28,
converged: true,
Expand Down Expand Up @@ -357,7 +359,8 @@ describe("serialise", () => {
parameterValueChanged: false,
endTimeChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
},
plotSettings: sensitivityState.plotSettings,
result: {
Expand Down Expand Up @@ -394,7 +397,8 @@ describe("serialise", () => {
dataChanged: false,
linkChanged: true,
parameterValueChanged: false,
parameterToVaryChanged: false
parameterToVaryChanged: false,
advancedSettingsChanged: false
},
iterations: 28,
converged: true,
Expand Down
3 changes: 2 additions & 1 deletion app/static/tests/unit/store/modelFit/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
12 changes: 8 additions & 4 deletions app/static/tests/unit/store/sensitivity/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ describe("Sensitivity actions", () => {
modelChanged: false,
parameterValueChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
});

expect(mockRunnerOde.batchRun).toHaveBeenCalledWith(
Expand Down Expand Up @@ -165,7 +166,8 @@ describe("Sensitivity actions", () => {
modelChanged: false,
parameterValueChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
});

expect(mockRunnerOde.batchRun).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -438,7 +440,8 @@ describe("Sensitivity actions", () => {
modelChanged: false,
parameterValueChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
});

expect(mockRunnerDiscrete.batchRunDiscrete)
Expand Down Expand Up @@ -518,7 +521,8 @@ describe("Sensitivity actions", () => {
modelChanged: false,
parameterValueChanged: false,
sensitivityOptionsChanged: false,
numberOfReplicatesChanged: false
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
});

expect(mockRunnerOde.batchRun).toHaveBeenCalledWith(
Expand Down
5 changes: 4 additions & 1 deletion app/static/tests/unit/store/sensitivity/getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit 1f79b29

Please sign in to comment.