From affc3e2deb4a0217d2fbc138dee353ac1a112ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Thu, 12 May 2022 16:40:20 +0200 Subject: [PATCH 1/4] test(e2e): check that invalid values are preserved refs #501 --- e2e/valeurs-erronees.e2e-spec.ts | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 e2e/valeurs-erronees.e2e-spec.ts diff --git a/e2e/valeurs-erronees.e2e-spec.ts b/e2e/valeurs-erronees.e2e-spec.ts new file mode 100644 index 000000000..de0fca39e --- /dev/null +++ b/e2e/valeurs-erronees.e2e-spec.ts @@ -0,0 +1,60 @@ +import { browser } from "protractor"; +import { CalculatorPage } from "./calculator.po"; +import { ListPage } from "./list.po"; +import { Navbar } from "./navbar.po"; +import { PreferencesPage } from "./preferences.po"; + +describe("ngHyd - check invalid values are preserved - ", () => { + 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(); + + // disable evil option "empty fields on module creation" + await prefPage.navigateTo(); + await browser.sleep(200); + await prefPage.disableEvilEmptyFields(); + await browser.sleep(200); + }); + + it("when switching to another calculator", async () => { + // open PAB dimensions calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(5); + await browser.sleep(200); + + // modify W input with invalid value + const inputW = calcPage.getInputById("W"); + await browser.sleep(200); + await inputW.clear(); + await browser.sleep(200); + await inputW.sendKeys("-1"); + await browser.sleep(200); + + // open another calculator + await navBar.clickNewCalculatorButton(); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // back to first calculator + await navBar.openNthCalculator(0); + await browser.sleep(200); + + // check invalid value is still present + const w = await inputW.getAttribute("value"); + await browser.sleep(200); + expect(w).toEqual("-1"); + + // check that "compute" button is disabled + const calcButton = calcPage.getCalculateButton(); + const disabledState = await calcButton.getAttribute("disabled"); + const disabled = disabledState === null || disabledState === "true"; + expect(disabled).toBe(true); + }); +}); -- GitLab From 5ece88263e496f150959c4c305a40502ec9e2871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 13 May 2022 16:49:50 +0200 Subject: [PATCH 2/4] refactor: remove NgParam.unit member refs #501 --- src/app/formulaire/elements/ngparam.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index 43d7cb298..c4d6c146e 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -32,8 +32,6 @@ export class NgParameter extends InputField implements Observer { /** set to true to disable UI validation on this input */ private _allowEmpty = false; - public unit: string; - public radioConfig: ParamRadioConfig; public disabled: boolean; @@ -207,6 +205,10 @@ export class NgParameter extends InputField implements Observer { return this._paramDef.valueMode; } + public get unit() { + return this._paramDef.unit; + } + /** * Unlinks the parameter and updates its value when value mode changes */ @@ -496,7 +498,7 @@ export class NgParameter extends InputField implements Observer { if (this._paramDef.symbol === rep.prmDef.symbol) { this._paramDef.loadObjectRepresentation(rep.prmDef); this._allowEmpty = rep.allowEmpty; - this.unit = rep.unit; + this._paramDef.setUnit(rep.unit); this.radioConfig = rep.radioConfig; } } @@ -581,7 +583,6 @@ export class NgParameter extends InputField implements Observer { if (json["allowEmpty"] !== undefined && typeof json["allowEmpty"] === "boolean") { this._allowEmpty = json["allowEmpty"]; } - this.unit = this.paramDefinition.unit; this.radioConfig = this.getRadioConfig(); if (json["calculable"] !== undefined && json["calculable"] === false) { this.radioConfig = Math.min(ParamCalculability.FREE, this.getRadioConfig()); -- GitLab From 425ae8fabfdb1bbefc6203f620b6ef1e7b6f82a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 18 May 2022 15:19:15 +0200 Subject: [PATCH 3/4] fix: set invalid parameter single value to undefined refs #501 --- .../components/generic-input/generic-input.component.ts | 3 +++ .../components/ngparam-input/ngparam-input.component.ts | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index 3dc390d50..c30e69123 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -154,11 +154,14 @@ export abstract class GenericInputComponentDirective implements OnChanges { this.emitValidChanged(); } // répercussion des erreurs sur le Form angular, pour faire apparaître/disparaître les mat-error + // setTimeout(() => { // en cas de pb, décommenter le timeout if (b) { this.inputField.control.setErrors(null); } else { this.inputField.control.setErrors({ "incorrect": true }); } + // this.inputField.control.markAsTouched(); + // }, 100); } private validateModel(): boolean { diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts index 2449f691e..781e29b15 100644 --- a/src/app/components/ngparam-input/ngparam-input.component.ts +++ b/src/app/components/ngparam-input/ngparam-input.component.ts @@ -2,7 +2,7 @@ import { Component, ChangeDetectorRef, OnDestroy, Input, ElementRef } from "@angular/core"; -import { Message, Observer } from "jalhyd"; +import { Message, MessageCode, Observer } from "jalhyd"; import { I18nService } from "../../services/internationalisation.service"; import { NgParameter } from "../../formulaire/elements/ngparam"; @@ -99,6 +99,9 @@ export class NgParamInputComponent extends GenericInputComponentDirective implem msg = "internal error, model undefined"; } else { try { + if (!this._paramDef.allowEmpty && v === undefined) { + throw new Message(MessageCode.ERROR_PARAMDEF_VALUE_UNDEFINED); + } this._paramDef.checkValue(v); valid = true; } catch (e) { @@ -148,6 +151,9 @@ export class NgParamInputComponent extends GenericInputComponentDirective implem } public ngOnDestroy() { + if (!this.isValid && this.getModelValue() !== undefined) { + this.setModelValue(this, undefined); + } this._paramDef.removeObserver(this); } } -- GitLab From b15a323fe49ac39700931b09022f50a055052b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 18 May 2022 15:19:50 +0200 Subject: [PATCH 4/4] fix(e2e): adapt test on invalid parameter value refs #501 --- e2e/valeurs-erronees.e2e-spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/valeurs-erronees.e2e-spec.ts b/e2e/valeurs-erronees.e2e-spec.ts index de0fca39e..d18afcd4f 100644 --- a/e2e/valeurs-erronees.e2e-spec.ts +++ b/e2e/valeurs-erronees.e2e-spec.ts @@ -4,7 +4,7 @@ import { ListPage } from "./list.po"; import { Navbar } from "./navbar.po"; import { PreferencesPage } from "./preferences.po"; -describe("ngHyd - check invalid values are preserved - ", () => { +describe("ngHyd - check invalid values are removed - ", () => { let listPage: ListPage; let prefPage: PreferencesPage; let navBar: Navbar; @@ -46,10 +46,10 @@ describe("ngHyd - check invalid values are preserved - ", () => { await navBar.openNthCalculator(0); await browser.sleep(200); - // check invalid value is still present + // check invalid value is removed const w = await inputW.getAttribute("value"); await browser.sleep(200); - expect(w).toEqual("-1"); + expect(w).toEqual(""); // check that "compute" button is disabled const calcButton = calcPage.getCalculateButton(); -- GitLab