Skip to content

Commit

Permalink
tests: unit test + e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
absternator committed Nov 10, 2023
1 parent cd6afb3 commit 2d2c17e
Show file tree
Hide file tree
Showing 10 changed files with 881 additions and 480 deletions.
1 change: 1 addition & 0 deletions app/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"copy-all": "concurrently \"npm run copy-js\" \"npm run copy-bootstrap\" && concurrently \"npm run copy-css \" \"npm run copy-js-map\" \"npm run copy-fonts\"",
"build": "npm run build-wodin && npm run copy-all",
"test:unit": "vue-cli-service test:unit",
"test:dev": "vue-cli-service test:unit --watch",
"lint": "vue-cli-service lint --no-fix",
"lint:fix": "vue-cli-service lint",
"e2e-test": "npx playwright test",
Expand Down
6 changes: 1 addition & 5 deletions app/static/src/app/components/options/ParameterSetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ export default defineComponent({
type: Object as PropType<ParameterSet>,
required: true,
},
showUnchangedParameters: {
type: Boolean,
required: true,
},
},
components: {
VueFeather,
Expand All @@ -141,7 +137,7 @@ export default defineComponent({
grey: "#bbb",
};
var parametersToShow = computed(() =>
props.showUnchangedParameters
store.state.run.showUnchangedParameters
? props.parameterSet.parameterValues
: Object.fromEntries(
Object.entries(props.parameterSet.parameterValues).filter(
Expand Down
1 change: 0 additions & 1 deletion app/static/src/app/components/options/ParameterSets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
:index="index"
class="mt-2"
:key="`saved-parameterSet-${paramSet.name}`"
:showUnchangedParameters="showUnchangedParameters"
>
</parameter-set-view>
</template>
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/e2e/code.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ test.describe("Code Tab tests", () => {
await page.click("#reset-btn");
await page.waitForResponse((response) => response.url().includes("/odin"));
expect(await page.innerText(".wodin-left .wodin-content .editor-container")).toBe(defaultCode);
await expect(await page.innerText(".wodin-left .wodin-content #code-status")).toContain("Code is valid");
await expect(page.getByText("Code is valid")).toBeVisible();
});

test("can display error message on code tab", async ({ page }) => {
Expand Down
1,307 changes: 837 additions & 470 deletions app/static/tests/e2e/options.etest.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/static/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const mockRunState = (state: Partial<RunState> = {}): RunState => {
parameterSetsCreated: 0,
parameterSets: [],
parameterSetResults: {},
showUnchangedParameters: false,
advancedSettings: {
[AdvancedOptions.tol]: { val: [null, null], default: [1, -6], type: AdvancedComponentType.stdf },
[AdvancedOptions.maxSteps]: { val: null, default: 10000, type: AdvancedComponentType.num },
Expand Down
14 changes: 12 additions & 2 deletions app/static/tests/unit/components/options/parameterSetView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe("ParameterSetView", () => {
index = 0,
modelChanged = false,
compileRequired = false,
dispNameErrorMsg = ""
dispNameErrorMsg = "",
showUnchangedParameters = true
) => {
const store = new Vuex.Store<BasicState>({
state: mockBasicState({
Expand All @@ -37,12 +38,13 @@ describe("ParameterSetView", () => {
namespaced: true,
state: mockRunState({
parameterValues: { alpha: 1, beta: 2, gamma: 3 },
showUnchangedParameters,
runRequired: {
modelChanged,
parameterValueChanged: false,
endTimeChanged: false,
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
advancedSettingsChanged: false,
}
}),
actions: {
Expand Down Expand Up @@ -386,4 +388,12 @@ describe("ParameterSetView", () => {
expect(mockToggleParameterSetHidden).toHaveBeenCalledTimes(1);
expect(mockToggleParameterSetHidden.mock.calls[0][1]).toBe("Set 1");
});

it('should not show same parameters when showUnchangedParameters is false', () => {
const wrapper = getWrapper(false, 0, false, false, "", false);
const paramSpans = wrapper.findAll(".card-body span.badge");
expect(paramSpans.length).toBe(2);
expect(paramSpans[0].text()).toBe("alpha: 0");
expect(paramSpans[1].text()).toBe("gamma: 4");
})
});
15 changes: 15 additions & 0 deletions app/static/tests/unit/components/options/parameterSets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import ParameterSetView from "../../../../src/app/components/options/ParameterSe
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";

describe("ParameterSets", () => {
const mockNewParameterSet = jest.fn();
const mockToggleShowUnchangedParameters = jest.fn();
const getWrapper = (runState: Partial<RunState>, modelState: Partial<ModelState> = {}) => {
const store = new Vuex.Store<BasicState>({
state: mockBasicState({
Expand All @@ -23,6 +25,9 @@ describe("ParameterSets", () => {
getters,
actions: {
[RunAction.NewParameterSet]: mockNewParameterSet
},
mutations: {
[RunMutation.ToggleShowUnchangedParameters]: mockToggleShowUnchangedParameters
}
}
}
Expand Down Expand Up @@ -122,4 +127,14 @@ describe("ParameterSets", () => {
await wrapper.find("button#create-param-set").trigger("click");
expect(mockNewParameterSet).toHaveBeenCalledTimes(1);
});

it('should show text when no parameter sets saved', () => {
const wrapper = getWrapper({});
expect(wrapper.find('p.small').text()).toBe('Saved parameter sets will show here');
})
it('should call RunMutation.ToggleShowUnchangedParameters when unchanged parameters checkbox is clicked', async() => {
const wrapper = getWrapper({});
await wrapper.find('input.form-check-input').trigger('click');
expect(mockToggleShowUnchangedParameters).toHaveBeenCalledTimes(1);
})
});
2 changes: 2 additions & 0 deletions app/static/tests/unit/serialiser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("serialise", () => {
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
},
showUnchangedParameters: false,
parameterValues: { alpha: 1, beta: 1.1 },
endTime: 20,
resultOde: {
Expand Down Expand Up @@ -408,6 +409,7 @@ describe("serialise", () => {
numberOfReplicatesChanged: false,
advancedSettingsChanged: false
},
showUnchangedParameters: false,
parameterValues: runState.parameterValues,
parameterSetsCreated: runState.parameterSetsCreated,
parameterSets: runState.parameterSets,
Expand Down
12 changes: 11 additions & 1 deletion app/static/tests/unit/store/run/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mutations } from "../../../../src/app/store/run/mutations";
import { RunMutation, mutations } from "../../../../src/app/store/run/mutations";
import { AdvancedComponentType } from "../../../../src/app/store/run/state";
import { AdvancedOptions } from "../../../../src/app/types/responseTypes";
import { mockRunState } from "../../../mocks";
Expand Down Expand Up @@ -617,4 +617,14 @@ describe("Run mutations", () => {
hidden: false
}]);
});

it('toggles showUnchangedParameters when ToggleShowUnchangedParameters is called', () => {
const state = mockRunState({
showUnchangedParameters: false
});
mutations[RunMutation.ToggleShowUnchangedParameters](state);
expect(state.showUnchangedParameters).toBe(true);
mutations[RunMutation.ToggleShowUnchangedParameters](state);
expect(state.showUnchangedParameters).toBe(false);
})
});

0 comments on commit 2d2c17e

Please sign in to comment.