From f45aad92f5b72242e4021866c757e1cbda4cc976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 5 Apr 2023 14:30:22 +0200 Subject: [PATCH 1/5] feat(e2e): add reliable input clearing function refs #616 --- e2e/calculator.po.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index e73d117a9..f5dcd07e9 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -1,4 +1,4 @@ -import { by, element, ElementFinder, browser, protractor, ElementArrayFinder } from "protractor"; +import { by, element, ElementFinder, browser, protractor, ElementArrayFinder, Key } from "protractor"; import { scrollPageToTop, scrollToElement } from "./util.po"; export class CalculatorPage { @@ -458,4 +458,15 @@ export class CalculatorPage { getCalculatorHelpButton() { return element(by.css("#help-calc")); } + + /** + * reliable input clearing + */ + async clearInput(inp: ElementFinder) { + const txt = await inp.getAttribute('value'); + const len = txt.length; + for (let n = 0; n < len; n++) { + await inp.sendKeys(Key.BACK_SPACE); + } + } } -- GitLab From f7f20968cf0cb6ca13068ce8381b39cdfed2061a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 5 Apr 2023 14:30:58 +0200 Subject: [PATCH 2/5] test(e2e): check calculate button is disabled when a parallel structures input is empty refs #616 --- e2e/calculate-button-validation.e2e-spec.ts | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/e2e/calculate-button-validation.e2e-spec.ts b/e2e/calculate-button-validation.e2e-spec.ts index 512616101..f98e92093 100644 --- a/e2e/calculate-button-validation.e2e-spec.ts +++ b/e2e/calculate-button-validation.e2e-spec.ts @@ -138,4 +138,42 @@ describe("Calculate button - ", () => { expect(await upstream.getAttribute('class')).not.toContain("node-error"); }); }); + + async function checkCalculateButtonValidity(calcType: number) { + // open calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(calcType); + await browser.sleep(200); + + // for each input, set empty and check calculate button is not active + + const inputs = calcPage.getParamInputs(); + const ninp = await inputs.count(); + for (let i = 0; i < ninp; i++) { + const inp = inputs.get(i); + // set input to fixed mode + await calcPage.setParamMode(inp, "fix"); + await browser.sleep(100); + + // clear input + await calcPage.clearInput(inp); + await browser.sleep(10); + + // check calculate button is disabled + await calcPage.checkCalcButtonEnabled(false); + await browser.sleep(100); + + // refill input + await inp.sendKeys("1"); + await browser.sleep(100); + } + } + + it("check status for various calculators", async () => { + // "parallel structures" calculator + await checkCalculateButtonValidity(8); + + // "fish ladder : cross walls" calculator + await checkCalculateButtonValidity(10); + }); }); -- GitLab From 3d5109a2f166e8ba312a09295d8b419a2c76cbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 5 Apr 2023 10:53:41 +0200 Subject: [PATCH 3/5] refactor: remove useless StructureFieldsetContainerComponent refs #616 --- src/app/app.module.ts | 2 -- .../calculator.component.html | 8 ++++---- .../structure-fieldset-container.component.ts | 20 ------------------- 3 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 src/app/components/structure-fieldset-container/structure-fieldset-container.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5c912764c..add5d9f10 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -121,7 +121,6 @@ import { ImmediateErrorStateMatcher } from "./formulaire/immediate-error-state-m import { LoadSessionURLComponent } from "./components/load-session-url/load-session-url.component"; import { DialogShowMessageComponent } from "./components/dialog-show-message/dialog-show-message.component"; import { DialogConfirmLoadSessionURLComponent } from "./components/dialog-confirm-load-session-url/dialog-confirm-load-session-url.component"; -import { StructureFieldsetContainerComponent } from "./components/structure-fieldset-container/structure-fieldset-container.component"; import { BasinFieldsetContainerComponent } from "./components/basin-fieldset-container/basin-fieldset-container.component"; import { PrebarrageService } from "./services/prebarrage.service"; import { SelectSectionDetailsComponent } from "./components/select-section-details/select-section-details.component"; @@ -225,7 +224,6 @@ const appRoutes: Routes = [ DialogConfirmLoadSessionURLComponent, FieldSetComponent, FieldsetContainerComponent, - StructureFieldsetContainerComponent, BasinFieldsetContainerComponent, FixedResultsComponent, FixedVarResultsComponent, diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index 40cac6c06..a332794d6 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -105,11 +105,11 @@ (tabPressed)="onTabPressed($event)"> </field-set> - <structure-fieldset-container *ngIf="isStructureFieldsetContainer(fe)" + <fieldset-container *ngIf="isStructureFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)"> - </structure-fieldset-container> + </fieldset-container> <basin-fieldset-container *ngIf="isBasinFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe @@ -138,12 +138,12 @@ fxFlex="1 0 auto"> </fieldset-container> - <structure-fieldset-container *ngIf="isStructureFieldsetContainer(fe)" + <fieldset-container *ngIf="isStructureFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)" fxFlex="1 0 auto"> - </structure-fieldset-container> + </fieldset-container> <pab-table *ngIf="isPabTable(fe)" [pabTable]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) diff --git a/src/app/components/structure-fieldset-container/structure-fieldset-container.component.ts b/src/app/components/structure-fieldset-container/structure-fieldset-container.component.ts deleted file mode 100644 index 34b9a3bba..000000000 --- a/src/app/components/structure-fieldset-container/structure-fieldset-container.component.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Component } from "@angular/core"; - -import { FieldSet } from "../../formulaire/elements/fieldset"; -import { I18nService } from "../../services/internationalisation.service"; -import { ApplicationSetupService } from "../../services/app-setup.service"; -import { FieldsetContainerComponent } from "../fieldset-container/fieldset-container.component"; - -@Component({ - selector: "structure-fieldset-container", - templateUrl: "../fieldset-container/fieldset-container.component.html", - styleUrls: [ - "../fieldset-container/fieldset-container.component.scss" - ] -}) -export class StructureFieldsetContainerComponent extends FieldsetContainerComponent { - - constructor(i18nService: I18nService, appSetupService: ApplicationSetupService) { - super(i18nService, appSetupService); - } -} -- GitLab From f96fb769e9c8953053f7c2571ecce74d99940b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 5 Apr 2023 11:19:12 +0200 Subject: [PATCH 4/5] fix(e2e): tests on parallel structures (element finder on structure fieldset container) refs #616 --- e2e/calculator.po.ts | 4 ++-- .../generic-calculator/calculator.component.html | 8 ++++---- .../generic-calculator/calculator.component.ts | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index f5dcd07e9..fa9dc5802 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -130,11 +130,11 @@ export class CalculatorPage { } getAddStructureButton() { - return element(by.css("structure-fieldset-container .hyd-window-btns button.add-structure")); + return element(by.css("fieldset-container.structure-fieldsetcontainer .hyd-window-btns button.add-structure")); } getCopyStructureButton() { - return element(by.css("structure-fieldset-container .hyd-window-btns button.copy-structure")); + return element(by.css("fieldset-container.structure-fieldsetcontainer .hyd-window-btns button.copy-structure")); } getAllLinkButtons() { diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index a332794d6..1a816d5c8 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -108,14 +108,14 @@ <fieldset-container *ngIf="isStructureFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) - (tabPressed)="onTabPressed($event)"> + (tabPressed)="onTabPressed($event)" [class]="getFieldsetContainerClass(fe)"> </fieldset-container> <basin-fieldset-container *ngIf="isBasinFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)" - fxFlex="1 0 auto"> + fxFlex="1 0 auto" [class]="getFieldsetContainerClass(fe)"> </basin-fieldset-container> </ng-template> </div> @@ -135,14 +135,14 @@ [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)" - fxFlex="1 0 auto"> + fxFlex="1 0 auto" [class]="getFieldsetContainerClass(fe)"> </fieldset-container> <fieldset-container *ngIf="isStructureFieldsetContainer(fe)" [style.display]="getElementStyleDisplay(fe.id)" [_container]=fe (radio)=onRadioClick($event) (validChange)=onElementValid() (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)" - fxFlex="1 0 auto"> + fxFlex="1 0 auto" [class]="getFieldsetContainerClass(fe)"> </fieldset-container> <pab-table *ngIf="isPabTable(fe)" [pabTable]=fe (radio)=onRadioClick($event) diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 1ef35884a..9d5a06dff 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -232,6 +232,16 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe return false; } + public getFieldsetContainerClass(fe: any): string { + if (this.isStructureFieldsetContainer(fe)) { + return "structure-fieldsetcontainer"; + } + if (this.isBasinFieldsetContainer(fe)) { + return "basin-fieldsetcontainer"; + } + return "fieldsetcontainer"; + } + /** détermine si un FormulaireElement est du type PabTable */ public isPabTable(fe: any): boolean { return fe instanceof PabTable; -- GitLab From 7e7b9eb66342309c4daa58007e7578d914ed7909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 5 Apr 2023 13:42:33 +0200 Subject: [PATCH 5/5] fix(e2e): missing await in CalculatorPage.checkCalcButtonEnabled() refs #616 --- e2e/calculate-all-params.e2e-spec.ts | 4 ++-- e2e/calculate-button-validation.e2e-spec.ts | 12 ++++++------ e2e/calculate-linked-params.e2e-spec.ts | 2 +- e2e/calculator.po.ts | 4 ++-- e2e/solveur.e2e-spec.ts | 6 +++--- e2e/valeurs-erronees.e2e-spec.ts | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/e2e/calculate-all-params.e2e-spec.ts b/e2e/calculate-all-params.e2e-spec.ts index 5d0b9280a..f19c2f7d0 100644 --- a/e2e/calculate-all-params.e2e-spec.ts +++ b/e2e/calculate-all-params.e2e-spec.ts @@ -74,7 +74,7 @@ describe("ngHyd − calculate all parameters of all calculators", () => { const nbParamsCalc = await calcPage.getCheckedCalcModeButtons().count(); expect(nbParamsCalc).toBe(1); // check that "compute" button is active - const calcButton = calcPage.checkCalcButtonEnabled(true); + const calcButton = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButton.click(); // check that result is not empty @@ -84,7 +84,7 @@ describe("ngHyd − calculate all parameters of all calculators", () => { } else { // module has no calculable params, just click the "compute" button // check that "compute" button is active - const calcButton = calcPage.checkCalcButtonEnabled(true); + const calcButton = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButton.click(); // check that result is not empty diff --git a/e2e/calculate-button-validation.e2e-spec.ts b/e2e/calculate-button-validation.e2e-spec.ts index f98e92093..0f472f43e 100644 --- a/e2e/calculate-button-validation.e2e-spec.ts +++ b/e2e/calculate-button-validation.e2e-spec.ts @@ -49,21 +49,21 @@ describe("Calculate button - ", () => { await browser.sleep(200); // check that "compute" button is inactive - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); // back to PAB: chute await navBar.clickCalculatorTab(0); await browser.sleep(200); // check that "compute" button is active - calcPage.checkCalcButtonEnabled(true); + await calcPage.checkCalcButtonEnabled(true); // back to PAB: dimensions await navBar.clickCalculatorTab(1); await browser.sleep(200); // check that "compute" button is inactive - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); }); describe("check button status in prébarrages - ", () => { @@ -83,7 +83,7 @@ describe("Calculate button - ", () => { await inputQ.sendKeys("-1"); await browser.sleep(200); - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); // upstream item // look for g element with id starting by "flowchart-amont-" @@ -120,7 +120,7 @@ describe("Calculate button - ", () => { await browser.sleep(200); // calculate button disabled ? - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); // upstream item displayed in error ? expect(await upstream.getAttribute('class')).toContain("node-highlighted-error"); // upstream item is now selected by default (was 'node-error') @@ -132,7 +132,7 @@ describe("Calculate button - ", () => { await browser.sleep(200); // calculate button still disabled ? (the basin is not connected to anything) - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); // upstream item displayed not in error ? expect(await upstream.getAttribute('class')).not.toContain("node-error"); diff --git a/e2e/calculate-linked-params.e2e-spec.ts b/e2e/calculate-linked-params.e2e-spec.ts index e7192eca9..f87d9b168 100644 --- a/e2e/calculate-linked-params.e2e-spec.ts +++ b/e2e/calculate-linked-params.e2e-spec.ts @@ -45,7 +45,7 @@ describe("ngHyd − calculate with linked parameters", () => { async function computeAndCheckPresenceOfResults() { // check that "compute" button is active - const calcButton = calcPage.checkCalcButtonEnabled(true); + const calcButton = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButton.click(); // check that result is not empty diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index fa9dc5802..d7552190a 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -335,9 +335,9 @@ export class CalculatorPage { } // check that "compute" button is in given enabled/disabled state - checkCalcButtonEnabled(enabled: boolean) { + async checkCalcButtonEnabled(enabled: boolean) { const calcButton = this.getCalculateButton(); - expect(calcButton.isEnabled()).toBe(enabled); + expect(await calcButton.isEnabled()).toBe(enabled); return calcButton; } diff --git a/e2e/solveur.e2e-spec.ts b/e2e/solveur.e2e-spec.ts index 6ca71d3c7..1b4740864 100644 --- a/e2e/solveur.e2e-spec.ts +++ b/e2e/solveur.e2e-spec.ts @@ -63,7 +63,7 @@ describe("Solveur - ", () => { expect(spV).toContain("Z2 - Cote aval (PAB : chute)"); // check that "compute" button is active - const calcButton = calcPage.checkCalcButtonEnabled(true); + const calcButton = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButton.click(); // check that result is not empty @@ -113,7 +113,7 @@ describe("Solveur - ", () => { await calcPage.getInputById("Ytarget").sendKeys("318"); // check that "compute" button is active - const calcButton = calcPage.checkCalcButtonEnabled(true); + const calcButton = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButton.click(); // check that result is not empty @@ -134,7 +134,7 @@ describe("Solveur - ", () => { expect(hasResultsClone1).toBe(false); // check that "compute" button is active - const calcButtonClone = calcPage.checkCalcButtonEnabled(true); + const calcButtonClone = await calcPage.checkCalcButtonEnabled(true); // click "compute" button await calcButtonClone.click(); // check that result is not empty diff --git a/e2e/valeurs-erronees.e2e-spec.ts b/e2e/valeurs-erronees.e2e-spec.ts index 8580ae57e..73f815a39 100644 --- a/e2e/valeurs-erronees.e2e-spec.ts +++ b/e2e/valeurs-erronees.e2e-spec.ts @@ -54,6 +54,6 @@ describe("ngHyd - check invalid values are removed - ", () => { expect(w).toEqual(""); // check that "compute" button is disabled - calcPage.checkCalcButtonEnabled(false); + await calcPage.checkCalcButtonEnabled(false); }); }); -- GitLab