From b98ed2dab6aa1a2c0c305ca9068dafdec7a570d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Sat, 28 May 2022 19:30:06 +0200 Subject: [PATCH 1/2] text(e2e): check all fields are empty on pre-dams calculator creation with "empty fields" option refs #546 --- e2e/predam-empty-fields.e2e-spec.ts | 46 ++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/e2e/predam-empty-fields.e2e-spec.ts b/e2e/predam-empty-fields.e2e-spec.ts index 68db87689..8c3c9789f 100644 --- a/e2e/predam-empty-fields.e2e-spec.ts +++ b/e2e/predam-empty-fields.e2e-spec.ts @@ -7,7 +7,7 @@ import { PreferencesPage } from "./preferences.po" /** * check that fields are empty on creation */ -describe("ngHyd − check that predam fields are empty on creation", () => { +describe("ngHyd − check that predam fields are empty", () => { let listPage: ListPage; let prefPage: PreferencesPage; let navBar: Navbar; @@ -26,6 +26,50 @@ describe("ngHyd − check that predam fields are empty on creation", () => { await browser.sleep(200); }); + async function checkEmptyInput(id: string) { + const inp = calcPage.getInputById(id); + const val = await inp.getAttribute("value"); + expect(val).toEqual(""); + } + + it("on creation", async () => { + //browser.manage().window().setPosition(2000, 30); + // open predam calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(30); + await browser.sleep(200); + + // check upstream inputs + await checkEmptyInput("Q"); + // Z1 is calculated + await checkEmptyInput("Z2"); + + // check basin 1 inputs + let node = element(by.css("g.node.basin")); + await node.click(); + await browser.sleep(200); + await checkEmptyInput("0_S"); + await checkEmptyInput("0_ZF"); + + // check walls inputs + const walls = element.all(by.css("g.node.wall")); + expect(walls.count()).toEqual(2); + await walls.each(async (w) => { + await w.click(); + await browser.sleep(200); + await checkEmptyInput("0_ZDV"); + await checkEmptyInput("0_L"); + }); + + // check downstream basin inputs + node = element(by.id("aval")); + await node.click(); + await browser.sleep(200); + checkEmptyInput("Q"); + // Z1 is calculated + checkEmptyInput("Z2"); + }); + it("when a basin is added", async () => { // open predam calculator await navBar.clickNewCalculatorButton(); -- GitLab From c36d652fa0ed635d116396be7fac9e7025bfe5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Sat, 28 May 2022 19:31:14 +0200 Subject: [PATCH 2/2] fix: fields not empty on pre-dams calculator creation with "empty fields" option refs #546 --- .../pb-schema/pb-schema.component.ts | 11 +++++---- .../formulaire/definition/form-pb-cloison.ts | 6 +++-- src/app/services/formulaire.service.ts | 23 ++++++++++--------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index b2f00304c..c37219926 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -453,13 +453,14 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni // never let an unconnected basin ! (not done in model to prevent unwanted // automatic child addition when clearing children) if (this._selectedItem instanceof PbCloison) { + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // if no downstream connections remain, connect to river downstream if (this._selectedItem.bassinAmont?.cloisonsAval.length === 0) { - this.model.addChild(new PbCloison(this._selectedItem.bassinAmont, undefined)); + this.model.addChild(new PbCloison(this._selectedItem.bassinAmont, undefined, undefined, emptyFields)); } // if no upstream connections remain, connect to river upstream if (this._selectedItem.bassinAval?.cloisonsAmont.length === 0) { - this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval)); + this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval, undefined, emptyFields)); } } this.clearResults(); @@ -486,7 +487,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** Copies a wall */ public onCopyClick() { const wall = this._selectedItem as PbCloison; - const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); + const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval, undefined, ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit); wallCopy.loadObjectRepresentation(wall.objectRepresentation()); this.model.addChild(wallCopy); this.clearResults(); @@ -532,7 +533,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni if (result.up !== undefined && result.down !== undefined) { const wall = new PbCloison( result.up === 0 ? undefined : this.model.bassins[result.up - 1], - result.down === 0 ? undefined : this.model.bassins[result.down - 1] + result.down === 0 ? undefined : this.model.bassins[result.down - 1], + undefined, + ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit ); this.model.addChild(wall); this.clearResults(); diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index f7680be3a..02934c401 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -6,6 +6,7 @@ import { FormulaireNode } from "../elements/formulaire-node"; import { FieldsetContainer } from "../elements/fieldset-container"; import { FormulairePrebarrage } from "./form-prebarrage"; import { SelectFieldCustom } from "../elements/select-field-custom"; +import { ServiceFactory } from "app/services/service-factory"; export class FormulairePbCloison extends FormulaireParallelStructure { @@ -43,6 +44,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { if (sender instanceof SelectFieldCustom) { const nub = this._currentNub as PbCloison; const pb = nub.parent; + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // empty "" data.value.value should return undefined, which is good for amont/aval const newBasin = pb.findChild(data.value?.value) as PbBassin; if (sender.id === "select_upstream_basin") { @@ -52,7 +54,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { const uid = nub.uid; const oldDownstreamBasin = nub.bassinAval; pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(newBasin, oldDownstreamBasin); + const newWall = new PbCloison(newBasin, oldDownstreamBasin, undefined, emptyFields); newWall.setUid(uid); // copy structures for (const s of nub.structures) { @@ -69,7 +71,7 @@ export class FormulairePbCloison extends FormulaireParallelStructure { const uid = nub.uid; const oldUpstreamBasin = nub.bassinAmont; pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(oldUpstreamBasin, newBasin); + const newWall = new PbCloison(oldUpstreamBasin, newBasin, undefined, emptyFields); newWall.setUid(uid); // copy structures for (const s of nub.structures) { diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 1bfdbe14f..bf650c62b 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -453,21 +453,22 @@ export class FormulaireService extends Observable { && f.currentNub instanceof PreBarrage && f.currentNub.children.length === 0 ) { + const emptyFields: boolean = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // 1 basin - f.currentNub.addChild(new PbBassin(new PbBassinParams(13.80, 95))); + f.currentNub.addChild(new PbBassin(new PbBassinParams(13.80, 95, emptyFields))); // 1st wall - f.currentNub.addChild(new PbCloison(undefined, f.currentNub.children[0] as PbBassin)); - const s1: Structure = CreateStructure(LoiDebit.WeirCunge80); - s1.prms.ZDV.singleValue = 95.30; - s1.getParameter("L").singleValue = 0.4; - s1.getParameter("CdGR").singleValue = 1.04; + f.currentNub.addChild(new PbCloison(undefined, f.currentNub.children[0] as PbBassin, undefined, emptyFields)); + const s1: Structure = CreateStructure(LoiDebit.WeirCunge80, undefined, undefined, emptyFields); + // s1.prms.ZDV.singleValue = 95.30; + // s1.getParameter("L").singleValue = 0.4; + // s1.getParameter("CdGR").singleValue = 1.04; f.currentNub.children[1].addChild(s1); // 2nd wall - f.currentNub.addChild(new PbCloison(f.currentNub.children[0] as PbBassin, undefined)); - const s2: Structure = CreateStructure(LoiDebit.WeirCunge80); - s2.prms.ZDV.singleValue = 95.30; - s2.getParameter("L").singleValue = 0.4; - s2.getParameter("CdGR").singleValue = 1.04; + f.currentNub.addChild(new PbCloison(f.currentNub.children[0] as PbBassin, undefined, undefined, emptyFields)); + const s2: Structure = CreateStructure(LoiDebit.WeirCunge80, undefined, undefined, emptyFields); + // s2.prms.ZDV.singleValue = 95.30; + // s2.getParameter("L").singleValue = 0.4; + // s2.getParameter("CdGR").singleValue = 1.04; f.currentNub.children[2].addChild(s2); } -- GitLab