Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Sep 8, 2023
1 parent 21ecc0c commit 9382fa1
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 69 deletions.
10 changes: 5 additions & 5 deletions app/static/src/app/components/mixins/baseSensitivity.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Store} from "vuex";
import {computed, ComputedRef, WritableComputedRef} from "vue";
import { Store } from "vuex";
import { computed, ComputedRef, WritableComputedRef } from "vue";
import { AppState } from "../../store/appState/state";
import { ModelGetter } from "../../store/model/getters";
import userMessages from "../../userMessages";
import { anyTrue } from "../../utils";
import {sensitivityUpdateRequiredExplanation, verifyValidPlotSettingsTime} from "../sensitivity/support";
import { sensitivityUpdateRequiredExplanation, verifyValidPlotSettingsTime } from "../sensitivity/support";
import { Dict } from "../../types/utilTypes";
import {BaseSensitivityMutation} from "../../store/sensitivity/mutations";
import {BaseSensitivityAction} from "../../store/sensitivity/actions";
import { BaseSensitivityMutation } from "../../store/sensitivity/mutations";
import { BaseSensitivityAction } from "../../store/sensitivity/actions";

export interface BaseSensitivityMixin {
sensitivityPrerequisitesReady: ComputedRef<boolean>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{ multiSensitivityRunStatusMsg }}
</div>
<error-info :error="error"></error-info>
<sensitivity-summary-download :multi-sensitivity="true" :download-type="'Multi-sensitivity Summary'"></sensitivity-summary-download>
<sensitivity-summary-download :multi-sensitivity="true" :download-type="'Multi-sensitivity Summary'">
</sensitivity-summary-download>
</div>
</template>
<script lang="ts">
Expand All @@ -21,12 +22,12 @@ import { useStore } from "vuex";
import ActionRequiredMessage from "@/app/components/ActionRequiredMessage.vue";
import ErrorInfo from "@/app/components/ErrorInfo.vue";
import { update } from "plotly.js-basic-dist-min";
import SensitivitySummaryDownload from "@/app/components/sensitivity/SensitivitySummaryDownload.vue";
import baseSensitivity from "../mixins/baseSensitivity";
import { MultiSensitivityAction } from "../../store/multiSensitivity/actions";
import LoadingButton from "../LoadingButton.vue";
import userMessages from "../../userMessages";
import { BaseSensitivityGetter } from "../../store/sensitivity/getters";
import SensitivitySummaryDownload from "@/app/components/sensitivity/SensitivitySummaryDownload.vue";
export default defineComponent({
name: "MultiSensitivityTab",
Expand Down
11 changes: 4 additions & 7 deletions app/static/src/app/components/sensitivity/SensitivityTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
<span class="ms-2">{{ sensitivityProgressMsg }}</span>
</div>
<error-info :error="error"></error-info>
<sensitivity-summary-download :multi-sensitivity="false" :download-type="'Sensitivity Summary'"></sensitivity-summary-download>
<sensitivity-summary-download :multi-sensitivity="false" :download-type="'Sensitivity Summary'">
</sensitivity-summary-download>
</div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import { computed, defineComponent } from "vue";
import { useStore } from "vuex";
import VueFeather from "vue-feather";
import DownloadOutput from "@/app/components/DownloadOutput.vue";
import SensitivitySummaryDownload from "@/app/components/sensitivity/SensitivitySummaryDownload.vue";
import SensitivityTracesPlot from "./SensitivityTracesPlot.vue";
import ActionRequiredMessage from "../ActionRequiredMessage.vue";
import { BaseSensitivityGetter } from "../../store/sensitivity/getters";
Expand All @@ -35,13 +35,10 @@ import LoadingSpinner from "../LoadingSpinner.vue";
import LoadingButton from "../LoadingButton.vue";
import { SensitivityMutation } from "../../store/sensitivity/mutations";
import baseSensitivity from "../mixins/baseSensitivity";
import SensitivitySummaryDownload from "@/app/components/sensitivity/SensitivitySummaryDownload.vue";
export default defineComponent({
name: "SensitivityTab",
components: {
DownloadOutput,
VueFeather,
ErrorInfo,
LoadingSpinner,
SensitivitySummaryPlot,
Expand Down
4 changes: 2 additions & 2 deletions app/static/src/app/excel/wodinSensitivitySummaryDownload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as XLSX from "xlsx";
import { WodinExcelDownload } from "./wodinExcelDownload";
import { SensitivityPlotExtreme, SensitivityPlotExtremePrefix} from "../store/sensitivity/state";
import { SensitivityPlotExtreme, SensitivityPlotExtremePrefix } from "../store/sensitivity/state";
import { OdinUserType, OdinUserTypeSeriesSet } from "../types/responseTypes";
import {OdinSensitivityResult} from "../types/wrapperTypes";
import { OdinSensitivityResult } from "../types/wrapperTypes";

interface ExtremeSummarySheetSettings {
name: string,
Expand Down
2 changes: 0 additions & 2 deletions app/static/src/app/store/sensitivity/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ export const runSensitivity = (
}
};



export const baseSensitivityActions: ActionTree<BaseSensitivityState, AppState> = {
[BaseSensitivityAction.ComputeNext](context, batch: Batch) {
const {
Expand Down
27 changes: 19 additions & 8 deletions app/static/tests/unit/components/mixins/baseSensitivity.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Vuex from "vuex";
import { nextTick } from "vue";
import { ModelState } from "../../../../src/app/store/model/state";
import baseSensitivity, {BaseSensitivityMixin} from "../../../../src/app/components/mixins/baseSensitivity";
import baseSensitivity, { BaseSensitivityMixin } from "../../../../src/app/components/mixins/baseSensitivity";
import { BaseSensitivityState } from "../../../../src/app/store/sensitivity/state";
import { noSensitivityUpdateRequired } from "../../../../src/app/store/sensitivity/sensitivity";
import { AppState } from "../../../../src/app/store/appState/state";
import {BaseSensitivityMutation} from "../../../../src/app/store/sensitivity/mutations";
import {nextTick} from "vue";
import {BaseSensitivityAction} from "../../../../src/app/store/sensitivity/actions";
import { BaseSensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import { BaseSensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import mock = jest.mock;

describe("baseSensitivity mixin", () => {
Expand Down Expand Up @@ -34,9 +34,16 @@ describe("baseSensitivity mixin", () => {
hasRunner: () => hasRunner
}
},
run: {
namespace: true,
state: {
endTime: 100
}
},
multiSensitivity: {
namespaced: true,
state: {
downloading: false,
sensitivityUpdateRequired: noSensitivityUpdateRequired(),
result: {
batch: {
Expand All @@ -50,13 +57,17 @@ describe("baseSensitivity mixin", () => {
mockMultiSensSetUserSummaryDownloadFileName
},
actions: {
[BaseSensitivityAction.DownloadSummary]: mockSensDownloadSummary
[BaseSensitivityAction.DownloadSummary]: mockMultiSensDownloadSummary
}
},
sensitivity: {
namespaced: true,
state: {
downloading: false,
sensitivityUpdateRequired: noSensitivityUpdateRequired(),
plotSettings: {
time: 50
},
result: {
batch: {
solutions: [{}]
Expand All @@ -80,7 +91,6 @@ describe("baseSensitivity mixin", () => {
jest.clearAllMocks();
});


it("sensitivityPrerequisitesReady returns true when all prerequisites have been met", () => {
const store = getStore();
const sut = baseSensitivity(store, false);
Expand Down Expand Up @@ -148,15 +158,16 @@ describe("baseSensitivity mixin", () => {
"Status is out of date: model code has been recompiled. Run Multi-sensitivity to update.");
});

const testForSensAndMultiSens = (state: Partial<BaseSensitivityState>, test: (mixin: BaseSensitivityMixin) => void) => {
const testForSensAndMultiSens = (state: Partial<BaseSensitivityState>,
test: (mixin: BaseSensitivityMixin) => void) => {
let store = getStore(true, {}, state, {});
test(baseSensitivity(store, false));
store = getStore(true, {}, {}, state);
test(baseSensitivity(store, true));
};

it("returns downloading", () => {
testForSensAndMultiSens({downloading: true}, (mixin) => {
testForSensAndMultiSens({ downloading: true }, (mixin) => {
expect(mixin.downloading.value).toBe(true);
});
testForSensAndMultiSens({}, (mixin) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import MultiSensitivityTab from "../../../../src/app/components/multiSensitivity/MultiSensitivityTab.vue";
import {AppState, AppType} from "../../../../src/app/store/appState/state";
import { AppState, AppType } from "../../../../src/app/store/appState/state";
import LoadingButton from "../../../../src/app/components/LoadingButton.vue";
import { ModelState } from "../../../../src/app/store/model/state";
import { MultiSensitivityAction } from "../../../../src/app/store/multiSensitivity/actions";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import DownloadOutput from "../../../../src/app/components/DownloadOutput.vue";
import {AppState, AppType} from "../../../../src/app/store/appState/state";
import {BaseSensitivityState, SensitivityPlotType, SensitivityState} from "../../../../src/app/store/sensitivity/state";
import Vuex from "vuex";
import {shallowMount, VueWrapper} from "@vue/test-utils";
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 {
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 { 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 {nextTick} from "vue";
import {ModelGetter} from "../../../../src/app/store/model/getters";
import { ModelGetter } from "../../../../src/app/store/model/getters";

describe("SensitivitySummaryDownload", () => {
const mockSetUserSummaryDownloadFileName = jest.fn();
const mockDownloadSummary = jest.fn();
const mockSetPlotTime = jest.fn();

const getWrapper = (multiSens = false, state: Partial<BaseSensitivityState> = {}) => {

const plotSettings = {
plotType: SensitivityPlotType.TraceOverTime,
time: null
Expand Down Expand Up @@ -90,15 +93,17 @@ describe("SensitivitySummaryDownload", () => {
});
};

const testForSensAndMultiSens = (test: (wrapper: VueWrapper<any>, multiSens: boolean) => void, state: Partial<SensitivityState> = {}) => {
const testForSensAndMultiSens = (test: (wrapper: VueWrapper<any>, multiSens: boolean) => void,
state: Partial<SensitivityState> = {}) => {
let wrapper = getWrapper(false, state);
test(wrapper, false);
jest.clearAllMocks();
wrapper = getWrapper(true, state);
test(wrapper, true);
};

const asyncTestForSensAndMultiSens = async (test: (wrapper: VueWrapper<any>, multiSens: boolean) => Promise<void>, state: Partial<SensitivityState> = {}) => {
const asyncTestForSensAndMultiSens = async (test: (wrapper: VueWrapper<any>, multiSens: boolean) => Promise<void>,
state: Partial<SensitivityState> = {}) => {
let wrapper = getWrapper(false, state);
await test(wrapper, false);
jest.clearAllMocks();
Expand Down Expand Up @@ -158,7 +163,7 @@ describe("SensitivitySummaryDownload", () => {
});

it("renders DownloadOutput as expected", () => {
const state = {userSummaryDownloadFileName: "test.xlsx"};
const state = { userSummaryDownloadFileName: "test.xlsx" };
testForSensAndMultiSens((wrapper) => {
const downloadOutput = wrapper.findComponent(DownloadOutput);
expect(downloadOutput.props().open).toBe(false);
Expand Down Expand Up @@ -186,7 +191,7 @@ describe("SensitivitySummaryDownload", () => {
it("opens dialog on click download button", async () => {
const wrapper = getWrapper();
const button = wrapper.find("button#download-summary-btn");
expect((button.element as HTMLButtonElement).disabled).toBe(false)
expect((button.element as HTMLButtonElement).disabled).toBe(false);
await button.trigger("click");
expect(wrapper.findComponent(DownloadOutput).props().open).toBe(true);
});
Expand All @@ -203,7 +208,7 @@ describe("SensitivitySummaryDownload", () => {
it("verifies end time and dispatches action on download output emit", () => {
testForSensAndMultiSens((wrapper) => {
const downloadOutput = wrapper.findComponent(DownloadOutput);
downloadOutput.vm.$emit("download", {fileName: "test.xlsx"});
downloadOutput.vm.$emit("download", { fileName: "test.xlsx" });
// should have updated plot settings time to run end time
expect(mockSetPlotTime).toHaveBeenCalledTimes(1);
expect(mockSetPlotTime.mock.calls[0][1]).toBe(100);
Expand All @@ -221,4 +226,4 @@ describe("SensitivitySummaryDownload", () => {
expect(downloadOutput.props().open).toBe(false);
});
});
});
});
43 changes: 21 additions & 22 deletions app/static/tests/unit/components/sensitivity/sensitivityTab.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {shallowMount} from "@vue/test-utils";
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import {ModelState} from "../../../../src/app/store/model/state";
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 { 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 { 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 { 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 { SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import SensitivitySummaryDownload from "../../../../src/app/components/sensitivity/SensitivitySummaryDownload.vue";
import LoadingButton from "../../../../src/app/components/LoadingButton.vue";

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

Expand Down Expand Up @@ -106,8 +107,7 @@ describe("SensitivityTab", () => {

it("renders as expected when Trace over Time", () => {
const wrapper = getWrapper();
expect(wrapper.find("button").text()).toBe("Run sensitivity");
expect(wrapper.find("button").element.disabled).toBe(false);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(false);
expect(wrapper.findComponent(ActionRequiredMessage).props("message")).toBe("");
expect(wrapper.findComponent(SensitivityTracesPlot).props("fadePlot")).toBe(false);
expect(wrapper.findComponent(ErrorInfo).props("error")).toBe(null);
Expand All @@ -117,14 +117,13 @@ describe("SensitivityTab", () => {

it("enables sensitivity when app is stochastic and runner is available", () => {
const wrapper = getWrapper(AppType.Stochastic);
expect(wrapper.find("button").element.disabled).toBe(false);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(false);
});

it("renders as expected when Value at Time", () => {
const sensitivityState = { plotSettings: { plotType: SensitivityPlotType.ValueAtTime } as any };
const wrapper = getWrapper(AppType.Fit, {}, sensitivityState);
expect(wrapper.find("button").text()).toBe("Run sensitivity");
expect(wrapper.find("button").element.disabled).toBe(false);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(false);
expect(wrapper.findComponent(ActionRequiredMessage).props("message")).toBe("");
expect(wrapper.findComponent(SensitivitySummaryPlot).props("fadePlot")).toBe(false);

Expand Down Expand Up @@ -167,34 +166,34 @@ describe("SensitivityTab", () => {

it("disables run button when hasRunner is false", () => {
const wrapper = getWrapper(AppType.Basic, { odinRunnerOde: null }, {}, {}, false);
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(true);
});

it("disables run button when no odin model", () => {
const wrapper = getWrapper(AppType.Fit, { odin: null });
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(true);
});

it("disables run button when required action is Compile", () => {
const wrapper = getWrapper(AppType.Basic, {
compileRequired: true
});
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(true);
});

it("disables run button when no batchPars", () => {
const wrapper = getWrapper(AppType.Basic, {}, {}, null);
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("isDisabled")).toBe(true);
});

it("disables run button when loading is true", () => {
it("sets loading prop on LoadingBUtton when loading is true", () => {
const wrapper = getWrapper(AppType.Fit, {}, { loading: true });
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("loading")).toBe(true);
});

it("disables run button when running is true", () => {
it("sets loading prop on LoadingButton when running is true", () => {
const wrapper = getWrapper(AppType.Fit, {}, { running: true });
expect(wrapper.find("button").element.disabled).toBe(true);
expect(wrapper.findComponent(LoadingButton).props("loading")).toBe(true);
});

it("renders expected update message when required action is Compile", () => {
Expand Down Expand Up @@ -281,7 +280,7 @@ describe("SensitivityTab", () => {
const wrapper = getWrapper();
expect(mockRunSensitivity).not.toHaveBeenCalled();
expect(mockSetLoading).not.toHaveBeenCalled();
wrapper.find("button").trigger("click");
wrapper.findComponent(LoadingButton).vm.$emit("click");
await new Promise((r) => setTimeout(r, 101));
expect(mockRunSensitivity).toHaveBeenCalledTimes(1);
expect(mockSetLoading).toHaveBeenCalledTimes(1);
Expand Down
Loading

0 comments on commit 9382fa1

Please sign in to comment.