Skip to content
Snippets Groups Projects
Commit 44eea74e authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '501-prebarrages-les-valeurs-erronees-ne-sont-pas-conservees' into 'devel'

Resolve "PréBarrages: les valeurs erronées ne sont pas conservées"

Closes #501

See merge request !141
parents 60386354 b15a323f
No related branches found
No related tags found
1 merge request!141Resolve "PréBarrages: les valeurs erronées ne sont pas conservées"
Pipeline #139573 passed
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 removed - ", () => {
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 removed
const w = await inputW.getAttribute("value");
await browser.sleep(200);
expect(w).toEqual("");
// 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);
});
});
......@@ -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 {
......
......@@ -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);
}
}
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment