Skip to content

Commit

Permalink
third batch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Nov 5, 2024
1 parent 465b0ab commit 88371b8
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 208 deletions.
28 changes: 14 additions & 14 deletions app/static/tests/unit/components/options/advancedSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { VueWrapper, shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import AdvancedSettings from "../../../../src/app/components/options/AdvancedSettings.vue";
import AdvancedSettings from "../../../../src/components/options/AdvancedSettings.vue";
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 { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import { AppType } from "../../../../src/app/store/appState/state";
import { RunMutation } from "../../../../src/store/run/mutations";
import NumericInput from "../../../../src/components/options/NumericInput.vue";
import StandardFormInput from "../../../../src/components/options/StandardFormInput.vue";
import { AdvancedOptions } from "../../../../src/types/responseTypes";
import TagInput from "../../../../src/components/options/TagInput.vue";
import { ModelFitMutation } from "../../../../src/store/modelFit/mutations";
import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/store/sensitivity/mutations";
import { AppType } from "../../../../src/store/appState/state";

describe("Advanced Settings", () => {
const mockUpdateAdvancedSettings = jest.fn();
const mockSetFitUpdateRequired = jest.fn();
const mockSetSensitivityUpdateRequired = jest.fn();
const mockSetMultiSensitivityUpdateRequired = jest.fn();
const mockUpdateAdvancedSettings = vi.fn();
const mockSetFitUpdateRequired = vi.fn();
const mockSetSensitivityUpdateRequired = vi.fn();
const mockSetMultiSensitivityUpdateRequired = vi.fn();

const getWrapper = (isFit = false, multiSensitivity = false) => {
const store = new Vuex.Store({
Expand Down Expand Up @@ -64,7 +64,7 @@ describe("Advanced Settings", () => {
};

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

const expectValueAndPlaceholder = (
Expand Down
26 changes: 13 additions & 13 deletions app/static/tests/unit/components/options/editParamSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import {
SensitivityParameterSettings,
SensitivityScaleType,
SensitivityVariationType
} from "../../../../src/app/store/sensitivity/state";
} from "../../../../src/store/sensitivity/state";
import {
mockBasicState,
mockBatchParsDisplace,
mockBatchParsRange,
mockModelState,
mockRunState
} from "../../../mocks";
import EditParamSettings from "../../../../src/app/components/options/EditParamSettings.vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import NumericInput from "../../../../src/app/components/options/NumericInput.vue";
import SensitivityParamValues from "../../../../src/app/components/options/SensitivityParamValues.vue";
import EditParamSettings from "../../../../src/components/options/EditParamSettings.vue";
import { BasicState } from "../../../../src/store/basic/state";
import NumericInput from "../../../../src/components/options/NumericInput.vue";
import SensitivityParamValues from "../../../../src/components/options/SensitivityParamValues.vue";
import { expectCloseNumericArray } from "../../../testUtils";
import TagInput from "../../../../src/app/components/options/TagInput.vue";
import ErrorInfo from "../../../../src/app/components/ErrorInfo.vue";
import TagInput from "../../../../src/components/options/TagInput.vue";
import ErrorInfo from "../../../../src/components/ErrorInfo.vue";

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

describe("EditParamSettings", () => {
const percentSettings = {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("EditParamSettings", () => {
};

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it("renders as expected when variation type is Percentage", async () => {
Expand Down Expand Up @@ -262,11 +262,11 @@ describe("EditParamSettings", () => {
});

it("renders and updates sensitivity param values", async () => {
const percentSpy = jest.spyOn(mockRunner, "batchParsDisplace");
const rangeSpy = jest.spyOn(mockRunner, "batchParsRange");
const percentSpy = vi.spyOn(mockRunner, "batchParsDisplace");
const rangeSpy = vi.spyOn(mockRunner, "batchParsRange");
const wrapper = await getWrapper(percentSettings);
const sensitivityValues = wrapper.findComponent(SensitivityParamValues);
const { values, name } = sensitivityValues.props("batchPars").varying[0];
const { values, name } = sensitivityValues.props("batchPars")!.varying[0];
expectCloseNumericArray(values, [1.8, 1.9, 2, 2.1, 2.2]);
expect(name).toBe("B");
expect(percentSpy).toHaveBeenCalledTimes(1);
Expand All @@ -279,7 +279,7 @@ describe("EditParamSettings", () => {
await updateSelect(wrapper, "edit-variation-type", SensitivityVariationType.Range);
await wrapper.find("#edit-from").findComponent(NumericInput).vm.$emit("update", 1);
await wrapper.find("#edit-to").findComponent(NumericInput).vm.$emit("update", 3);
const updatedValues = sensitivityValues.props("batchPars").varying[0].values;
const updatedValues = sensitivityValues.props("batchPars")!.varying[0].values;
expectCloseNumericArray(updatedValues, [1, 1.5, 2, 2.5, 3]);
expect(rangeSpy).toHaveBeenCalledTimes(3); // called on each update
expect(rangeSpy.mock.calls[2][0]).toStrictEqual(parameterValues);
Expand Down
18 changes: 9 additions & 9 deletions app/static/tests/unit/components/options/linkData.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { shallowMount, VueWrapper } from "@vue/test-utils";
import Vuex from "vuex";
import LinkData from "../../../../src/app/components/options/LinkData.vue";
import { FitState } from "../../../../src/app/store/fit/state";
import { getters } from "../../../../src/app/store/fitData/getters";
import LinkData from "../../../../src/components/options/LinkData.vue";
import { FitState } from "../../../../src/store/fit/state";
import { getters } from "../../../../src/store/fitData/getters";
import { mockFitDataState, mockFitState, mockGraphsState, mockModelState } from "../../../mocks";
import { FitDataAction } from "../../../../src/app/store/fitData/actions";
import { getters as graphGetters } from "../../../../src/app/store/graphs/getters";
import { defaultGraphSettings } from "../../../../src/app/store/graphs/state";
import { FitDataAction } from "../../../../src/store/fitData/actions";
import { getters as graphGetters } from "../../../../src/store/graphs/getters";
import { defaultGraphSettings } from "../../../../src/store/graphs/state";

describe("LinkData", () => {
const getWrapper = (includeColumns = true, includeValidModel = true, mockUpdateLinkedVariable = jest.fn()) => {
const getWrapper = (includeColumns = true, includeValidModel = true, mockUpdateLinkedVariable = vi.fn()) => {
const store = new Vuex.Store<FitState>({
state: mockFitState(),
modules: {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("LinkData", () => {
});

it("updates linked variable on select variable", async () => {
const mockUpdateLinkedVariable = jest.fn();
const mockUpdateLinkedVariable = vi.fn();
const wrapper = getWrapper(true, true, mockUpdateLinkedVariable);
const admissionsSelect = wrapper.findAll("select").at(1)!;
(admissionsSelect.element as HTMLSelectElement).value = "R";
Expand All @@ -115,7 +115,7 @@ describe("LinkData", () => {
});

it("updates linked variable on select no link", async () => {
const mockUpdateLinkedVariable = jest.fn();
const mockUpdateLinkedVariable = vi.fn();
const wrapper = getWrapper(true, true, mockUpdateLinkedVariable);
const casesSelect = wrapper.findAll("select").at(0)!;
(casesSelect.element as HTMLSelectElement).value = "";
Expand Down
6 changes: 3 additions & 3 deletions app/static/tests/unit/components/options/numericInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { mount, VueWrapper } from "@vue/test-utils";
import { nextTick } from "vue";
import NumericInput from "../../../../src/app/components/options/NumericInput.vue";
import NumericInput from "../../../../src/components/options/NumericInput.vue";

export type BoundTooltip = {
error: { number: number; message?: string };
warning: { number: number; message: string };
};

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

describe("NumericInput", () => {
const getWrapper = (
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("NumericInput", () => {
};

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it("renders as expected", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { mockFitDataState } from "../../../mocks";
import { FitState } from "../../../../src/app/store/fit/state";
import OptimisationOptions from "../../../../src/app/components/options/OptimisationOptions.vue";
import { FitDataAction } from "../../../../src/app/store/fitData/actions";
import { FitState } from "../../../../src/store/fit/state";
import OptimisationOptions from "../../../../src/components/options/OptimisationOptions.vue";
import { FitDataAction } from "../../../../src/store/fitData/actions";

describe("OptimisationOptions", () => {
const getWrapper = (fitDataState = mockFitDataState(), mockUpdateColumnToFit = jest.fn()) => {
const getWrapper = (fitDataState = mockFitDataState(), mockUpdateColumnToFit = vi.fn()) => {
const store = new Vuex.Store<FitState>({
state: {} as any,
modules: {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("OptimisationOptions", () => {
});

it("updates column to fit when select changes", async () => {
const mockUpdateColumnToFit = jest.fn();
const mockUpdateColumnToFit = vi.fn();
const state = mockFitDataState({
columnToFit: "col2",
linkedVariables: {
Expand Down
36 changes: 18 additions & 18 deletions app/static/tests/unit/components/options/optionsTab.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { mount, shallowMount } from "@vue/test-utils";
import Vuex, { Store } from "vuex";
import OptionsTab from "../../../../src/app/components/options/OptionsTab.vue";
import VerticalCollapse from "../../../../src/app/components/VerticalCollapse.vue";
import ParameterValues from "../../../../src/app/components/options/ParameterValues.vue";
import RunOptions from "../../../../src/app/components/options/RunOptions.vue";
import LinkData from "../../../../src/app/components/options/LinkData.vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import { FitState } from "../../../../src/app/store/fit/state";
import { AppType, VisualisationTab } from "../../../../src/app/store/appState/state";
import SensitivityOptions from "../../../../src/app/components/options/SensitivityOptions.vue";
import OptimisationOptions from "../../../../src/app/components/options/OptimisationOptions.vue";
import OptionsTab from "../../../../src/components/options/OptionsTab.vue";
import VerticalCollapse from "../../../../src/components/VerticalCollapse.vue";
import ParameterValues from "../../../../src/components/options/ParameterValues.vue";
import RunOptions from "../../../../src/components/options/RunOptions.vue";
import LinkData from "../../../../src/components/options/LinkData.vue";
import { BasicState } from "../../../../src/store/basic/state";
import { FitState } from "../../../../src/store/fit/state";
import { AppType, VisualisationTab } from "../../../../src/store/appState/state";
import SensitivityOptions from "../../../../src/components/options/SensitivityOptions.vue";
import OptimisationOptions from "../../../../src/components/options/OptimisationOptions.vue";
import { mockModelState, mockRunState } from "../../../mocks";
import { RunMutation } from "../../../../src/app/store/run/mutations";
import GraphSettings from "../../../../src/app/components/GraphSettings.vue";
import ParameterSets from "../../../../src/app/components/options/ParameterSets.vue";
import { getters as runGetters } from "../../../../src/app/store/run/getters";
import AdvancedSettings from "../../../../src/app/components/options/AdvancedSettings.vue";
import GraphConfigsCollapsible from "../../../../src/app/components/graphConfig/GraphConfigsCollapsible.vue";
import { RunMutation } from "../../../../src/store/run/mutations";
import GraphSettings from "../../../../src/components/GraphSettings.vue";
import ParameterSets from "../../../../src/components/options/ParameterSets.vue";
import { getters as runGetters } from "../../../../src/store/run/getters";
import AdvancedSettings from "../../../../src/components/options/AdvancedSettings.vue";
import GraphConfigsCollapsible from "../../../../src/components/graphConfig/GraphConfigsCollapsible.vue";

describe("OptionsTab", () => {
const mockTooltipDirective = jest.fn();
const mockTooltipDirective = vi.fn();

const getWrapper = (store: Store<any>) => {
return mount(OptionsTab, {
Expand Down Expand Up @@ -95,7 +95,7 @@ describe("OptionsTab", () => {
});

it("can reset model parameters", async () => {
const mockUpdateParameterValuesMutation = jest.fn();
const mockUpdateParameterValuesMutation = vi.fn();
const store = new Vuex.Store<BasicState>({
state: {
appType: AppType.Basic,
Expand Down
29 changes: 14 additions & 15 deletions app/static/tests/unit/components/options/parameterSetView.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import Vuex from "vuex";
import { nextTick } from "vue";
import { shallowMount } from "@vue/test-utils";
import { flushPromises, shallowMount } from "@vue/test-utils";
import VueFeather from "vue-feather";
import { BasicState } from "../../../../src/app/store/basic/state";
import { BasicState } from "../../../../src/store/basic/state";
import { mockBasicState, mockRunState, mockModelState } from "../../../mocks";
import ParameterSetView from "../../../../src/app/components/options/ParameterSetView.vue";
import { RunAction } from "../../../../src/app/store/run/actions";
import { RunMutation } from "../../../../src/app/store/run/mutations";
import { getters } from "../../../../src/app/store/run/getters";
import ParameterSetView from "../../../../src/components/options/ParameterSetView.vue";
import { RunAction } from "../../../../src/store/run/actions";
import { RunMutation } from "../../../../src/store/run/mutations";
import { getters } from "../../../../src/store/run/getters";

describe("ParameterSetView", () => {
const mockDeleteParameterSet = jest.fn();
const mockToggleParameterSetHidden = jest.fn();
const mockTooltipDirective = jest.fn();
const mockSwapParameterSet = jest.fn();
const mockSaveParameterDisplayName = jest.fn();
const mockTurnOffDisplayNameError = jest.fn();
const mockDeleteParameterSet = vi.fn();
const mockToggleParameterSetHidden = vi.fn();
const mockTooltipDirective = vi.fn();
const mockSwapParameterSet = vi.fn();
const mockSaveParameterDisplayName = vi.fn();
const mockTurnOffDisplayNameError = vi.fn();

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

const getWrapper = (
Expand Down Expand Up @@ -286,8 +286,7 @@ describe("ParameterSetView", () => {
expect(displayNameInput.element.value).toBe("Set 1");
expect(displayNameText.isVisible()).toBe(false);

// 4 on mount + 1 input on mount + 4 after update
expect(mockTooltipDirective).toHaveBeenCalledTimes(9);
// 4 on mount + 1 input on mount + 2nd one is saveIcon
expect(mockTooltipDirective.mock.calls[6][0]).toBe(saveIcon.element);
expect(mockTooltipDirective.mock.calls[6][1].value).toBe("Save Parameter Set Name");
});
Expand Down
25 changes: 13 additions & 12 deletions app/static/tests/unit/components/options/parameterSets.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { BasicState } from "../../../../src/app/store/basic/state";
import { RunState } from "../../../../src/app/store/run/state";
import { BasicState } from "../../../../src/store/basic/state";
import { RunState } from "../../../../src/store/run/state";
import { mockBasicState, mockModelState, mockRunState } from "../../../mocks";
import ParameterSets from "../../../../src/app/components/options/ParameterSets.vue";
import ParameterSetView from "../../../../src/app/components/options/ParameterSetView.vue";
import { ModelState } from "../../../../src/app/store/model/state";
import { getters } from "../../../../src/app/store/run/getters";
import { RunAction } from "../../../../src/app/store/run/actions";
import { RunMutation } from "../../../../src/app/store/run/mutations";
import ParameterSets from "../../../../src/components/options/ParameterSets.vue";
import ParameterSetView from "../../../../src/components/options/ParameterSetView.vue";
import { ModelState } from "../../../../src/store/model/state";
import { getters } from "../../../../src/store/run/getters";
import { RunAction } from "../../../../src/store/run/actions";
import { RunMutation } from "../../../../src/store/run/mutations";
import { nextTick } from "vue";

describe("ParameterSets", () => {
const mockNewParameterSet = jest.fn();
const mockToggleShowUnchangedParameters = jest.fn();
const mockNewParameterSet = vi.fn();
const mockToggleShowUnchangedParameters = vi.fn();
const getWrapper = (runState: Partial<RunState>, modelState: Partial<ModelState> = {}) => {
const store = new Vuex.Store<BasicState>({
state: mockBasicState({
Expand Down Expand Up @@ -40,7 +41,7 @@ describe("ParameterSets", () => {
};

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it("renders as expected", () => {
Expand Down Expand Up @@ -134,7 +135,7 @@ describe("ParameterSets", () => {
});
it("should call ToggleShowUnchangedParameters when unchanged parameters checkbox is clicked", async () => {
const wrapper = getWrapper({});
await wrapper.find("input.form-check-input").trigger("click");
await wrapper.find("input.form-check-input").trigger("input");
expect(mockToggleShowUnchangedParameters).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 88371b8

Please sign in to comment.