From c971815319875f4c2ed07c336290daff0ab59809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 4 Nov 2022 15:22:50 +0100 Subject: [PATCH 1/3] update jalhyd_branch to 331-les-resultats-ne-sont-pas-reinitialises-quand-on-modifie-des-parametres-globaux refs #574 --- jalhyd_branch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jalhyd_branch b/jalhyd_branch index a210a99ef..53f3046a7 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -329-un-parametre-lie-ne-change-pas-d-etat-apres-la-suppression-du-module-cible +331-les-resultats-ne-sont-pas-reinitialises-quand-on-modifie-des-parametres-globaux -- GitLab From 3ed748720a4fcef2c3c79375c22b0b375aa5ea53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 4 Nov 2022 16:01:28 +0100 Subject: [PATCH 2/3] test(e2e): check calculator results are reset after application setup modification refs #574 --- e2e/preferences.po.ts | 8 ++++ e2e/reset-results.e2e-spec.ts | 84 +++++++++++++++++++++++++++++++++++ e2e/sidenav.po.ts | 4 ++ 3 files changed, 96 insertions(+) create mode 100644 e2e/reset-results.e2e-spec.ts diff --git a/e2e/preferences.po.ts b/e2e/preferences.po.ts index ff9ff36ae..2360ff351 100644 --- a/e2e/preferences.po.ts +++ b/e2e/preferences.po.ts @@ -29,6 +29,14 @@ export class PreferencesPage { return ff.element(by.css("input")); } + /** + * find input with given "name" attribute + */ + getInputFromName(name: string) { + const cssSelector: string = `input[name="${name}"]`; + return element(by.css(cssSelector)); + } + getErrorsForField(ff: ElementFinder) { return ff.element(by.css("mat-error")); } diff --git a/e2e/reset-results.e2e-spec.ts b/e2e/reset-results.e2e-spec.ts new file mode 100644 index 000000000..7b98cde01 --- /dev/null +++ b/e2e/reset-results.e2e-spec.ts @@ -0,0 +1,84 @@ +import { ListPage } from "./list.po"; +import { Navbar } from "./navbar.po"; +import { browser } from "protractor"; +import { CalculatorPage } from "./calculator.po"; +import { PreferencesPage } from "./preferences.po"; +import { cp } from "fs"; +import { SideNav } from "./sidenav.po"; + +describe("Check results are reset after application settings modification - ", () => { + let listPage: ListPage; + let navBar: Navbar; + let calcPage: CalculatorPage; + let prefPage: PreferencesPage; + let sideNav: SideNav; + + beforeAll(async () => { + listPage = new ListPage(); + navBar = new Navbar(); + calcPage = new CalculatorPage(); + prefPage = new PreferencesPage(); + sideNav = new SideNav(); + }); + + beforeEach(async () => { + // browser.manage().window().setPosition(2000, 30); + + // disable evil option "empty fields on module creation" + await prefPage.navigateTo(); + await prefPage.disableEvilEmptyFields(); + await browser.sleep(200); + }); + + async function runTestWithParamater(param: string, val1: number, val2: number) { + // set starting compute precision + const input = prefPage.getInputFromName(param); + await input.clear(); + await browser.sleep(20); + await input.sendKeys(val1.toString()); + await browser.sleep(200); + + // open "fish ladder: fall" calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // click "compute" button + const calcButton = calcPage.getCalculateButton(); + await calcButton.click(); + await browser.sleep(200); + + // results should be here + let hasResults = await calcPage.hasResults(); + expect(hasResults).toBe(true); + + // reopen settings + await navBar.clickMenuButton(); + await browser.sleep(200); + const setupBtn = await sideNav.getSetupButton(); + await setupBtn.click(); + await browser.sleep(200); + + // modify compute precision + await input.clear(); + await browser.sleep(20); + await input.sendKeys(val2.toString()); + await browser.sleep(200); + + // back to calculator + await navBar.openNthCalculator(0); + + // results should not be here + hasResults = await calcPage.hasResults(); + expect(hasResults).toBe(false); + + } + + it("compute precision", async () => { + await runTestWithParamater("cp", 0.001, 0.0001); + }); + + it("max iterations", async () => { + await runTestWithParamater("nmi", 10, 100); + }); +}); diff --git a/e2e/sidenav.po.ts b/e2e/sidenav.po.ts index 437aef644..5b4060f52 100644 --- a/e2e/sidenav.po.ts +++ b/e2e/sidenav.po.ts @@ -15,6 +15,10 @@ export class SideNav { return element(by.css("#side-nav-diagram")); } + getSetupButton() { + return element(by.css("#side-nav-setup")); + } + getFileInput() { return element(by.css(`dialog-load-session input[type="file"]`)); } -- GitLab From 46838ca0df7e7be5a0c5d73e4326de058c2a1efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 4 Nov 2022 15:23:48 +0100 Subject: [PATCH 3/3] fix: reset results when application settings are modified (max iterations, compute precision) refs #574 --- src/app/formulaire/definition/form-definition.ts | 8 +++++++- src/app/services/app-setup.service.ts | 12 ++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 814db2e70..5a6504ec0 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -10,7 +10,8 @@ import { ParamDefinition, Result, VariatedDetails, - Prop_NullParameters + Prop_NullParameters, + SessionSettings } from "jalhyd"; import { FormulaireElement } from "../elements/formulaire-element"; @@ -67,6 +68,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs constructor(parent?: FormulaireNode) { super(parent); + SessionSettings.instance.addObserver(this); } // surcharge de FormulaireNode::get:uid() @@ -421,6 +423,10 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs break; } } + else if (sender instanceof SessionSettings) { + // reset results if a session setting (max iterations, compute precision) has been modified + this.reset(); + } } /** diff --git a/src/app/services/app-setup.service.ts b/src/app/services/app-setup.service.ts index 16e3cf00e..1bc771227 100644 --- a/src/app/services/app-setup.service.ts +++ b/src/app/services/app-setup.service.ts @@ -20,31 +20,27 @@ export class ApplicationSetupService extends Observable { // default builtin values public displayPrecision = 3; - private _computePrecision = 1e-7; // tied to model - private _maxIterations = 100; // tied to model + private static readonly _defaultComputePrecision = 1e-7; // tied to model + private static readonly _defaultMaxIterations = 100; // tied to model public enableNotifications = true; public enableHotkeys = false; private _enableEmptyFieldsOnFormInit = true; private _foldedMessageLog = false; public set computePrecision(p: number) { - this._computePrecision = p; - // forward to model SessionSettings.precision = p; } public get computePrecision(): number { - return this._computePrecision; + return SessionSettings.precision; } public set maxIterations(m: number) { - this._maxIterations = m; - // forward to model SessionSettings.maxIterations = m; } public get maxIterations(): number { - return this._maxIterations; + return SessionSettings.maxIterations; } public get enableEmptyFieldsOnFormInit() { -- GitLab