From d65fcb628485158caf078317eac96f61a7b14c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Mon, 11 Apr 2022 10:49:58 +0200 Subject: [PATCH 1/2] test: add check on empty fields when creating a predams calculator refs #503 --- e2e/predam-empty-fields.e2e-spec.ts | 75 +++++++++++++++++++ .../dialog-new-pb-cloison.component.html | 3 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 e2e/predam-empty-fields.e2e-spec.ts diff --git a/e2e/predam-empty-fields.e2e-spec.ts b/e2e/predam-empty-fields.e2e-spec.ts new file mode 100644 index 000000000..b434bd81d --- /dev/null +++ b/e2e/predam-empty-fields.e2e-spec.ts @@ -0,0 +1,75 @@ +import { browser, by, element } from "protractor"; +import { CalculatorPage } from "./calculator.po"; +import { ListPage } from "./list.po"; +import { Navbar } from "./navbar.po"; +import { PreferencesPage } from "./preferences.po" + +/** + * check that fields are empty on creation + */ +describe("ngHyd − check that predam fields are empty on creation", () => { + let listPage: ListPage; + let prefPage: PreferencesPage; + let navBar: Navbar; + let calcPage: CalculatorPage; + + beforeEach(async () => { + prefPage = new PreferencesPage(); + listPage = new ListPage(); + navBar = new Navbar(); + calcPage = new CalculatorPage(); + + // enable evil option "empty fields on module creation" + await prefPage.navigateTo(); + await browser.sleep(200); + await prefPage.enableEvilEmptyFields(); + await browser.sleep(200); + }); + + it("when a basin is added", async () => { + // open predam calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(30); + await browser.sleep(200); + + // add basin + const addBasinBtn = element(by.id("add-basin")); + await addBasinBtn.click(); + await browser.sleep(200); + + // check "surface" input is empty + let inp = calcPage.getInputById("3_S"); + let txt = await inp.getAttribute("value"); + expect(txt).toEqual(""); + + // check "cote de fond" input is empty + inp = calcPage.getInputById("3_ZF"); + txt = await inp.getAttribute("value"); + expect(txt).toEqual(""); + }); + + it("when a wall is added", async () => { + // open predam calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(30); + await browser.sleep(200); + + // add wall + const addWallBtn = element(by.id("add-wall")); + await addWallBtn.click(); + + // connect basins + const connectBasinsBtn = element(by.id("validate-connect-basins")); + await connectBasinsBtn.click(); + + // check ZDV input is empty + let inp = calcPage.getInputById("0_ZDV"); + let txt = await inp.getAttribute("value"); + expect(txt).toEqual(""); + + // check CdWSL input is NOT empty + inp = calcPage.getInputById("0_CdWSL"); + txt = await inp.getAttribute("value"); + expect(txt === "").toBe(false); + }); +}); diff --git a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html index a6587c773..fdded3ee4 100644 --- a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html +++ b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html @@ -21,7 +21,8 @@ <button mat-raised-button color="primary" [mat-dialog-close]="true" cdkFocusInitial> {{ uitextCancel }} </button> - <button mat-raised-button color="warn" (click)="onValidate()" [disabled]="! enableValidate"> + <button mat-raised-button id="validate-connect-basins" color="warn" (click)="onValidate()" + [disabled]="! enableValidate"> {{ uitextValidate }} </button> </div> -- GitLab From b424c10bc444f879743dbf21c9072e10a5959ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Mon, 11 Apr 2022 13:09:07 +0200 Subject: [PATCH 2/2] fix: predams: fields not empty on basin creation refs #503 --- .../pb-schema/pb-schema.component.ts | 28 ++++++++++++++++++- .../formulaire/elements/formulaire-node.ts | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 40217b619..e1e74c9e6 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -5,7 +5,7 @@ import * as screenfull from "screenfull"; import { Screenfull } from "screenfull"; // @see https://github.com/sindresorhus/screenfull.js/issues/126#issuecomment-488796645 import { - PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable + PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable, ParamDefinition, ParamValueMode } from "jalhyd"; import * as mermaid from "mermaid"; @@ -20,6 +20,7 @@ import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrag import { AppComponent } from "../../app.component"; import { fv } from "app/util"; +import { FormulaireNode } from "app/formulaire/elements/formulaire-node"; /** * The interactive schema for calculator type "PreBarrage" (component) @@ -491,10 +492,35 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni return this.i18nService.localizeText("INFO_FIELDSET_COPY"); } + /** + * Set value of all single parameters to undefined, except for the given parameter ids + */ + private emptyFields(basin: PbBassin, except: string[] = FormulaireNode.NeverEmptyFields) { + // save current calculated param, as setting value on a CALC param will + // change its mode and choose another calculated param by default + let calcP: ParamDefinition; + for (const p of basin.parameterIterator) { + if ( + [ParamValueMode.SINGLE, ParamValueMode.CALCUL].includes(p.valueMode) + && !except.includes(p.symbol) + ) { + if (p.valueMode === ParamValueMode.CALCUL) { + calcP = p; + } + p.setValue(undefined); + } + } + // restore original calculated param + if (calcP !== undefined) { + calcP.setCalculated(); + } + } + /** Adds a new lone basin */ public onAddBasinClick() { const newBasin = new PbBassin(new PbBassinParams(20, 99)); this.model.addChild(newBasin); + this.emptyFields(newBasin); this.clearResults(); this.refreshWithSelection(newBasin.uid); this.calculatorComponent.showPBInputData = true; diff --git a/src/app/formulaire/elements/formulaire-node.ts b/src/app/formulaire/elements/formulaire-node.ts index b0e214f5e..4d48607af 100644 --- a/src/app/formulaire/elements/formulaire-node.ts +++ b/src/app/formulaire/elements/formulaire-node.ts @@ -12,7 +12,7 @@ export abstract class FormulaireNode implements IObservable { /** * fields in fieldset that must not be empty due to enableEmptyFieldsOnFormInit option */ - protected static NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"]; + public static readonly NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"]; /** aide en ligne */ protected _helpLink: string; -- GitLab