Skip to content

Commit

Permalink
fix merge conflicts and update e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Sep 15, 2023
2 parents d4bbeb6 + 2c9135a commit 45eedb7
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 104 deletions.
39 changes: 29 additions & 10 deletions app/static/src/app/serialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ 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 { 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";
import {
SerialisedAppState, SerialisedModelState,
SerialisedAppState,
SerialisedModelState,
SerialisedRunState,
SerialisedSensitivityState,
SerialisedRunResult, SerialisedSensitivityResult, SerialisedModelFitState
SerialisedRunResult,
SerialisedSensitivityResult,
SerialisedModelFitState,
SerialisedMultiSensitivityState
} from "./types/serialisationTypes";
import { GraphSettingsState } from "./store/graphSettings/state";
import { Dict } from "./types/utilTypes";
import { MultiSensitivityState } from "./store/multiSensitivity/state";

function serialiseCode(code: CodeState) : CodeState {
return {
Expand Down Expand Up @@ -70,6 +75,18 @@ function serialiseRun(run: RunState): SerialisedRunState {
};
}

function serialiseBaseSensitivity(sensitivity: BaseSensitivityState) {
return {
running: false,
sensitivityUpdateRequired: sensitivity.sensitivityUpdateRequired,
result: sensitivity.result ? {
inputs: sensitivity.result.inputs,
hasResult: !!sensitivity.result.batch,
error: sensitivity.result.error
} : null
};
}

function serialiseSensitivity(sensitivity: SensitivityState): SerialisedSensitivityState {
const serialisedParameterSetResults = {} as Dict<SerialisedSensitivityResult>;
Object.keys(sensitivity.parameterSetResults).forEach((name) => {
Expand All @@ -82,19 +99,20 @@ function serialiseSensitivity(sensitivity: SensitivityState): SerialisedSensitiv
});

return {
running: false,
...serialiseBaseSensitivity(sensitivity),
paramSettings: sensitivity.paramSettings,
sensitivityUpdateRequired: sensitivity.sensitivityUpdateRequired,
plotSettings: sensitivity.plotSettings,
result: sensitivity.result ? {
inputs: sensitivity.result.inputs,
hasResult: !!sensitivity.result.batch,
error: sensitivity.result.error
} : null,
parameterSetResults: serialisedParameterSetResults
};
}

function serialiseMultiSensitivity(multiSensitivity: MultiSensitivityState): SerialisedMultiSensitivityState {
return {
...serialiseBaseSensitivity(multiSensitivity),
paramSettings: multiSensitivity.paramSettings
};
}

function serialiseFitData(fitData: FitDataState) : FitDataState {
return {
data: fitData.data,
Expand Down Expand Up @@ -129,6 +147,7 @@ export const serialiseState = (state: AppState): string => {
model: serialiseModel(state.model),
run: serialiseRun(state.run),
sensitivity: serialiseSensitivity(state.sensitivity),
multiSensitivity: serialiseMultiSensitivity(state.multiSensitivity),
graphSettings: serialiseGraphSettings(state.graphSettings)
};

Expand Down
11 changes: 10 additions & 1 deletion app/static/src/app/store/multiSensitivity/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ActionTree } from "vuex";
import { AppState } from "../appState/state";
import { baseSensitivityActions, runSensitivity } from "../sensitivity/actions";
import {
baseSensitivityActions,
runSensitivity,
runSensitivityOnRehydrate
} from "../sensitivity/actions";
import { MultiSensitivityState } from "./state";
import { BaseSensitivityGetter } from "../sensitivity/getters";

export enum MultiSensitivityAction {
RunMultiSensitivity = "RunMultiSensitivity",
RunMultiSensitivityOnRehydrate = "RunMultiSensitivityOnRehydrate"
}

export const actions: ActionTree<MultiSensitivityState, AppState> = {
Expand All @@ -16,5 +21,9 @@ export const actions: ActionTree<MultiSensitivityState, AppState> = {
const batchPars = getters[BaseSensitivityGetter.batchPars];

runSensitivity(batchPars, endTime, context, true);
},

[MultiSensitivityAction.RunMultiSensitivityOnRehydrate](context) {
runSensitivityOnRehydrate(context);
}
};
14 changes: 9 additions & 5 deletions app/static/src/app/store/sensitivity/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export const runSensitivity = (
}
};

export const runSensitivityOnRehydrate = (context: ActionContext<BaseSensitivityState, AppState>) => {
const { state, rootState } = context;
const { endTime } = rootState.run;
const { pars } = state.result!.inputs;

runSensitivity(pars, endTime, context);
};

export const baseSensitivityActions: ActionTree<BaseSensitivityState, AppState> = {
[BaseSensitivityAction.ComputeNext](context, batch: Batch) {
const {
Expand Down Expand Up @@ -181,10 +189,6 @@ export const actions: ActionTree<SensitivityState, AppState> = {
},

[SensitivityAction.RunSensitivityOnRehydrate](context) {
const { state, rootState } = context;
const { endTime } = rootState.run;
const { pars } = state.result!.inputs;

runSensitivity(pars, endTime, context);
runSensitivityOnRehydrate(context);
}
};
5 changes: 5 additions & 0 deletions app/static/src/app/store/sessions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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";

export enum SessionsAction {
GetSessions = "GetSessions",
Expand Down Expand Up @@ -67,6 +68,10 @@ export const actions: ActionTree<SessionsState, AppState> = {
if (sessionData.sensitivity.result?.hasResult) {
dispatch(`sensitivity/${SensitivityAction.RunSensitivityOnRehydrate}`, null, rootOption);
}
if (sessionData.multiSensitivity.result?.hasResult) {
dispatch(`multiSensitivity/${MultiSensitivityAction.RunMultiSensitivityOnRehydrate}`, null,
rootOption);
}
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions app/static/src/app/types/serialisationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export interface SerialisedSensitivityState {
parameterSetResults: Dict<SerialisedSensitivityResult>
}

export interface SerialisedMultiSensitivityState {
running: boolean,
paramSettings: SensitivityParameterSettings[]
sensitivityUpdateRequired: SensitivityUpdateRequiredReasons,
result: null | SerialisedSensitivityResult
}

export interface SerialisedModelFitState {
fitUpdateRequired: FitUpdateRequiredReasons,
iterations: number | null,
Expand All @@ -80,6 +87,7 @@ export interface SerialisedAppState {
model: SerialisedModelState,
run: SerialisedRunState,
sensitivity: SerialisedSensitivityState,
multiSensitivity: SerialisedMultiSensitivityState,
graphSettings: GraphSettingsState,
fitData?: FitDataState,
modelFit?: SerialisedModelFitState,
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(await page.locator(".wodin-left .wodin-content #code-status")).toHaveText("Code is valid");
});

test("can display error message on code tab", async ({ 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();
};
Loading

0 comments on commit 45eedb7

Please sign in to comment.