diff --git a/e2e/predam-empty-fields.e2e-spec.ts b/e2e/predam-empty-fields.e2e-spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..b434bd81d45e9d05c7952027f7c5303074eb6bf9 --- /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 a6587c7730d3cf912b851df5f0e55f237fd3bb87..fdded3ee4de8ef7ee55fb9a656e02cbf9bd3246c 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> diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 40217b619a7b18f79624bd14496f2433fe7ca2a1..e1e74c9e6fcf715c1a11c1da7dbf121960ea5801 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 b0e214f5ebd3f41a30c9918b2aea7ae5b4b3056c..4d48607af879a7bbfe7aadd459e61737db0787b6 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;