Skip to content

Commit

Permalink
more tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Sep 13, 2023
1 parent 79d9fe0 commit a56c1d5
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 39 deletions.
6 changes: 3 additions & 3 deletions app/static/src/app/serialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FitState } from "./store/fit/state";
import { CodeState } from "./store/code/state";
import { ModelState } from "./store/model/state";
import { RunState } from "./store/run/state";
import {BaseSensitivityState, SensitivityState} from "./store/sensitivity/state";
import { BaseSensitivityState, SensitivityState } from "./store/sensitivity/state";
import { FitDataState } from "./store/fitData/state";
import { ModelFitState } from "./store/modelFit/state";
import { OdinFitResult, OdinRunResultDiscrete, OdinRunResultOde } from "./types/wrapperTypes";
Expand All @@ -15,7 +15,7 @@ import {
} from "./types/serialisationTypes";
import { GraphSettingsState } from "./store/graphSettings/state";
import { Dict } from "./types/utilTypes";
import {MultiSensitivityState} from "./store/multiSensitivity/state";
import { MultiSensitivityState } from "./store/multiSensitivity/state";

function serialiseCode(code: CodeState) : CodeState {
return {
Expand Down Expand Up @@ -80,7 +80,7 @@ function serialiseBaseSensitivity(sensitivity: BaseSensitivityState) {
hasResult: !!sensitivity.result.batch,
error: sensitivity.result.error
} : null
}
};
}

function serialiseSensitivity(sensitivity: SensitivityState): SerialisedSensitivityState {
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/sensitivity/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const runSensitivityOnRehydrate = (context: ActionContext<BaseSensitivity
const { pars } = state.result!.inputs;

runSensitivity(pars, endTime, context);
}
};

export const baseSensitivityActions: ActionTree<BaseSensitivityState, AppState> = {
[BaseSensitivityAction.ComputeNext](context, batch: Batch) {
Expand Down
5 changes: 3 additions & 2 deletions app/static/src/app/store/sessions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SerialisedAppState } from "../../types/serialisationTypes";
import { deserialiseState } from "../../serialise";
import { SensitivityAction } from "../sensitivity/actions";
import { AppStateGetter } from "../appState/getters";
import {MultiSensitivityAction} from "../multiSensitivity/actions";
import { MultiSensitivityAction } from "../multiSensitivity/actions";

export enum SessionsAction {
GetSessions = "GetSessions",
Expand Down Expand Up @@ -69,7 +69,8 @@ export const actions: ActionTree<SessionsState, AppState> = {
dispatch(`sensitivity/${SensitivityAction.RunSensitivityOnRehydrate}`, null, rootOption);
}
if (sessionData.multiSensitivity.result?.hasResult) {
dispatch(`multiSensitivity/${MultiSensitivityAction.RunMultiSensitivityOnRehydrate}`, null, rootOption);
dispatch(`multiSensitivity/${MultiSensitivityAction.RunMultiSensitivityOnRehydrate}`, null,
rootOption);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/static/tests/e2e/download.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test.describe("Download tests", () => {
};

test("can download from Run tab", async ({ page }) => {
console.log("start download");
await page.click("#download-btn");
await expect(await page.inputValue("#download-file-name input")).toContain("day2-run");
await testCanInputFileNameAndDownload(page);
Expand Down
24 changes: 5 additions & 19 deletions app/static/tests/e2e/multiSensitivity.etest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, Page, test } from "@playwright/test";
import { SensitivityScaleType, SensitivityVariationType } from "../../src/app/store/sensitivity/state";
import PlaywrightConfig from "../../playwright.config";
import { writeCode } from "./utils";
import { expectCanRunMultiSensitivity, writeCode } from "./utils";

test.describe("Multi-sensitivity tests", () => {
const { timeout } = PlaywrightConfig;
const { timeout } = PlaywrightConfig;

test.describe("Multi-sensitivity tests", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/apps/day1");
// Open Options tab
Expand Down Expand Up @@ -122,22 +122,8 @@ test.describe("Multi-sensitivity tests", () => {
SensitivityVariationType.Percentage, 5, null, null, 10, "1.900, 1.922, 1.944, ..., 2.100");
});

const expectCanRunMultiSensitivity = async (page: Page) => {
// add a second varying parameter with default 10 values - should get 100 solutions from the 2 varying
await page.click("#add-param-settings");
await expect(await page.locator("#edit-param-to-vary select")).toBeVisible();
await page.click("#ok-settings");
await expect(await page.locator(".sensitivity-options-settings").count()).toBe(2);

await expect(await page.innerText(".multi-sensitivity-status")).toBe("Multi-sensitivity has not been run.");
await page.click("#run-multi-sens-btn");
await expect(await page.locator("#run-multi-sens-btn")).toBeEnabled();
await expect(await page.locator(".multi-sensitivity-status"))
.toHaveText("Multi-sensitivity run produced 100 solutions.", { timeout });
};

test("can run multi-sensitivity", async ({ page }) => {
await expectCanRunMultiSensitivity(page);
await expectCanRunMultiSensitivity(page, timeout);

// shows update required message when update code
await page.click(":nth-match(.wodin-left .nav-tabs a, 1)");
Expand All @@ -152,7 +138,7 @@ test.describe("Multi-sensitivity tests", () => {
await page.click(":nth-match(.wodin-left .nav-tabs a, 2)");
await page.click(":nth-match(.wodin-right .nav-tabs a, 4)");

await expectCanRunMultiSensitivity(page);
await expectCanRunMultiSensitivity(page, timeout);
});

test("can show error in multi-sensitivity run", async ({ page }) => {
Expand Down
18 changes: 16 additions & 2 deletions app/static/tests/e2e/sessions.etest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {
expect, test, chromium, Page
expect, test,
chromium,
Page
} from "@playwright/test";
import * as os from "os";
import {
writeCode,
newFitCode,
realisticFitData,
startModelFit,
waitForModelFitCompletion, expectWodinPlotDataSummary
waitForModelFitCompletion, expectWodinPlotDataSummary,
expectCanRunMultiSensitivity
} from "./utils";
import PlaywrightConfig from "../../playwright.config";

Expand Down Expand Up @@ -64,6 +67,10 @@ test.describe("Sessions tests", () => {
// 5 * 10 sensitivity traces, 5 central traces, 1 data plot
expect(await page.locator(".wodin-plot-data-summary-series").count()).toBe(56);

// Run multi-sensitivity
await page.click(":nth-match(.wodin-right .nav-tabs a, 4)");
expectCanRunMultiSensitivity(page, timeout);

// give the page a chance to save the session to back end
await page.waitForTimeout(saveSessionTimeout);

Expand Down Expand Up @@ -182,6 +189,13 @@ test.describe("Sessions tests", () => {
const sensitivityDataSummary = await page.locator(":nth-match(.wodin-plot-data-summary-series, 56)");
await expectWodinPlotDataSummary(sensitivityDataSummary, "Cases", 32, 0, 31, 0, 13, "markers", null, "#cccc00");

// Check multi-sensitivity result
await page.click(":nth-match(.wodin-right .nav-tabs a, 4)"); // Multi-sensitivity tab
await expect(await page.locator(".multi-sensitivity-status"))
.toHaveText("Multi-sensitivity run produced 100 solutions.", { timeout });
await expect(await page.locator("#download-summary-btn")).toBeEnabled();
await expect(await page.locator("#run-multi-sens-btn")).toBeEnabled();

// Expect to be able to navigate to the share link we copied earlier - check it has some rehydrated data
await page.goto(copiedLinkText);
await expect(await page.innerText("#data-upload-success")).toBe(" Uploaded 32 rows and 2 columns");
Expand Down
15 changes: 15 additions & 0 deletions app/static/tests/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ export const expectSummaryValues = async (page: Page, idx: number, name: string,
expect(await page.getAttribute(locator, "y-max")).toBe(yMax);
}
};

export const expectCanRunMultiSensitivity = async (page: Page, timeout = 10000) => {
// add a second varying parameter with default 10 values - should get 100 solutions from the 2 varying
await page.click("#add-param-settings");
await expect(await page.locator("#edit-param-to-vary select")).toBeVisible();
await page.click("#ok-settings");
await expect(await page.locator(".sensitivity-options-settings").count()).toBe(2);

await expect(await page.innerText(".multi-sensitivity-status")).toBe("Multi-sensitivity has not been run.");
await page.click("#run-multi-sens-btn");
await expect(await page.locator("#run-multi-sens-btn")).toBeEnabled();
await expect(await page.locator(".multi-sensitivity-status"))
.toHaveText("Multi-sensitivity run produced 100 solutions.", { timeout });
await expect(await page.locator("#download-summary-btn")).toBeEnabled();
};
5 changes: 3 additions & 2 deletions app/static/tests/unit/store/multiSensitivity/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "../sensitivity/actions.test";
import { AppType } from "../../../../src/app/store/appState/state";
import { BaseSensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import {SensitivityAction} from "../../../../src/app/store/sensitivity/actions";
import { SensitivityAction } from "../../../../src/app/store/sensitivity/actions";

jest.mock("../../../../src/app/excel/wodinSensitivitySummaryDownload");

Expand Down Expand Up @@ -70,6 +70,7 @@ describe("multiSensitivity actions", () => {

it("run multiSensitivity on rehydrate uses parameters from result", () => {
expectRunOnRehydrateToUseParametersFromResult(
actions[MultiSensitivityAction.RunMultiSensitivityOnRehydrate] as any);
actions[MultiSensitivityAction.RunMultiSensitivityOnRehydrate] as any
);
});
});
4 changes: 2 additions & 2 deletions app/static/tests/unit/store/sensitivity/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Action, ActionTree} from "vuex";
import { Action, ActionTree } from "vuex";
import { actions, BaseSensitivityAction, SensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import { BaseSensitivityMutation, SensitivityMutation } from "../../../../src/app/store/sensitivity/mutations";
import { ModelGetter } from "../../../../src/app/store/model/getters";
Expand All @@ -8,7 +8,7 @@ import { AdvancedOptions } from "../../../../src/app/types/responseTypes";
import { AdvancedComponentType } from "../../../../src/app/store/run/state";
import { WodinSensitivitySummaryDownload } from "../../../../src/app/excel/wodinSensitivitySummaryDownload";
import Mock = jest.Mock;
import {BaseSensitivityState} from "../../../../src/app/store/sensitivity/state";
import { BaseSensitivityState } from "../../../../src/app/store/sensitivity/state";

jest.mock("../../../../src/app/excel/wodinSensitivitySummaryDownload");

Expand Down
58 changes: 50 additions & 8 deletions app/static/tests/unit/store/sessions/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ModelAction } from "../../../../src/app/store/model/actions";
import { RunAction } from "../../../../src/app/store/run/actions";
import { SensitivityAction } from "../../../../src/app/store/sensitivity/actions";
import { AppStateGetter } from "../../../../src/app/store/appState/getters";
import { MultiSensitivityAction } from "../../../../src/app/store/multiSensitivity/actions";

describe("SessionsActions", () => {
const getSessionIdsSpy = jest.spyOn(localStorageManager, "getSessionIds")
Expand All @@ -22,7 +23,8 @@ describe("SessionsActions", () => {
});

const getSessionData = (hasOdin: boolean, compileRequired: boolean,
runHasResultOde: boolean, runHasResultDiscrete: boolean, sensitivityHasResult: boolean) => {
runHasResultOde: boolean, runHasResultDiscrete: boolean, sensitivityHasResult: boolean,
multiSensitivityHasResult: boolean) => {
return {
code: {
currentCode: ["some saved code"]
Expand All @@ -44,6 +46,11 @@ describe("SessionsActions", () => {
result: {
hasResult: sensitivityHasResult
}
},
multiSensitivity: {
result: {
hasResult: multiSensitivityHasResult
}
}
};
};
Expand All @@ -53,7 +60,7 @@ describe("SessionsActions", () => {
};

const testRehydrate = async (stochastic: boolean) => {
const mockSessionData = getSessionData(true, false, !stochastic, stochastic, true);
const mockSessionData = getSessionData(true, false, !stochastic, stochastic, true, true);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

Expand All @@ -64,7 +71,7 @@ describe("SessionsActions", () => {
expect(rootState.code.currentCode).toStrictEqual(["some saved code"]);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(AppStateMutation.SetConfigured);
expect(dispatch).toHaveBeenCalledTimes(4);
expect(dispatch).toHaveBeenCalledTimes(5);
expect(dispatch.mock.calls[0][0]).toBe(`model/${ModelAction.FetchOdinRunner}`);
expect(dispatch.mock.calls[0][1]).toBe(null);
expect(dispatch.mock.calls[0][2]).toStrictEqual({ root: true });
Expand All @@ -77,6 +84,10 @@ describe("SessionsActions", () => {
expect(dispatch.mock.calls[3][0]).toBe(`sensitivity/${SensitivityAction.RunSensitivityOnRehydrate}`);
expect(dispatch.mock.calls[3][1]).toBe(null);
expect(dispatch.mock.calls[3][2]).toStrictEqual({ root: true });
expect(dispatch.mock.calls[4][0])
.toBe(`multiSensitivity/${MultiSensitivityAction.RunMultiSensitivityOnRehydrate}`);
expect(dispatch.mock.calls[4][1]).toBe(null);
expect(dispatch.mock.calls[4][2]).toStrictEqual({ root: true });
};

it("Rehydrates as expected for non-stochastic", async () => {
Expand All @@ -88,7 +99,7 @@ describe("SessionsActions", () => {
});

it("Rehydrate does not compile or run if no odin model", async () => {
const mockSessionData = getSessionData(false, false, true, false, true);
const mockSessionData = getSessionData(false, false, true, false, true, false);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

Expand All @@ -106,7 +117,7 @@ describe("SessionsActions", () => {
});

it("Rehydrate does not compile or run if compile required is true", async () => {
const mockSessionData = getSessionData(true, true, true, false, true);
const mockSessionData = getSessionData(true, true, true, false, true, false);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

Expand All @@ -124,7 +135,7 @@ describe("SessionsActions", () => {
});

it("Rehydrate does not run model if run has no result", async () => {
const mockSessionData = getSessionData(true, false, false, false, true);
const mockSessionData = getSessionData(true, false, false, false, true, false);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

Expand All @@ -148,7 +159,7 @@ describe("SessionsActions", () => {
});

it("Rehydrate does not run sensitivity if sensitivity has no result", async () => {
const mockSessionData = getSessionData(true, false, true, false, false);
const mockSessionData = getSessionData(true, false, true, false, false, true);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

Expand All @@ -159,7 +170,7 @@ describe("SessionsActions", () => {
expect(rootState.code.currentCode).toStrictEqual(["some saved code"]);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(AppStateMutation.SetConfigured);
expect(dispatch).toHaveBeenCalledTimes(3);
expect(dispatch).toHaveBeenCalledTimes(4);
expect(dispatch.mock.calls[0][0]).toBe(`model/${ModelAction.FetchOdinRunner}`);
expect(dispatch.mock.calls[0][1]).toBe(null);
expect(dispatch.mock.calls[0][2]).toStrictEqual({ root: true });
Expand All @@ -169,6 +180,37 @@ describe("SessionsActions", () => {
expect(dispatch.mock.calls[2][0]).toBe(`run/${RunAction.RunModelOnRehydrate}`);
expect(dispatch.mock.calls[2][1]).toBe(null);
expect(dispatch.mock.calls[2][2]).toStrictEqual({ root: true });
expect(dispatch.mock.calls[3][0])
.toBe(`multiSensitivity/${MultiSensitivityAction.RunMultiSensitivityOnRehydrate}`);
expect(dispatch.mock.calls[3][1]).toBe(null);
expect(dispatch.mock.calls[3][2]).toStrictEqual({ root: true });
});

it("Rehydrate does not run multiSensitivity if sensitivity has no result", async () => {
const mockSessionData = getSessionData(true, false, true, false, true, false);
mockAxios.onGet("/apps/testApp/sessions/1234")
.reply(200, mockSuccess(mockSessionData));

const commit = jest.fn();
const dispatch = jest.fn();
const rootState = { appName: "testApp", baseUrl: "", appsPath: "apps" } as any;
await (actions[SessionsAction.Rehydrate] as any)({ commit, dispatch, rootState }, "1234");
expect(rootState.code.currentCode).toStrictEqual(["some saved code"]);
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls[0][0]).toBe(AppStateMutation.SetConfigured);
expect(dispatch).toHaveBeenCalledTimes(4);
expect(dispatch.mock.calls[0][0]).toBe(`model/${ModelAction.FetchOdinRunner}`);
expect(dispatch.mock.calls[0][1]).toBe(null);
expect(dispatch.mock.calls[0][2]).toStrictEqual({ root: true });
expect(dispatch.mock.calls[1][0]).toBe(`model/${ModelAction.CompileModelOnRehydrate}`);
expect(dispatch.mock.calls[1][1]).toBe(null);
expect(dispatch.mock.calls[1][2]).toStrictEqual({ root: true });
expect(dispatch.mock.calls[2][0]).toBe(`run/${RunAction.RunModelOnRehydrate}`);
expect(dispatch.mock.calls[2][1]).toBe(null);
expect(dispatch.mock.calls[2][2]).toStrictEqual({ root: true });
expect(dispatch.mock.calls[3][0]).toBe(`sensitivity/${SensitivityAction.RunSensitivityOnRehydrate}`);
expect(dispatch.mock.calls[3][1]).toBe(null);
expect(dispatch.mock.calls[3][2]).toStrictEqual({ root: true });
});

it("GetSessions fetches and commits session metadata", async () => {
Expand Down

0 comments on commit a56c1d5

Please sign in to comment.