From d0da2a57e9ab21623f2feb06506e0ac8c7f29ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 10 Feb 2023 16:26:11 +0100 Subject: [PATCH 1/3] test(e2e): check that a parameter targeted by a link cannot link to another parameter refs #605 --- e2e/calculate-linked-params.e2e-spec.ts | 40 +++++++++++++++++++++++++ e2e/calculator.po.ts | 8 +++++ 2 files changed, 48 insertions(+) diff --git a/e2e/calculate-linked-params.e2e-spec.ts b/e2e/calculate-linked-params.e2e-spec.ts index 56f8dd05f..12e68d423 100644 --- a/e2e/calculate-linked-params.e2e-spec.ts +++ b/e2e/calculate-linked-params.e2e-spec.ts @@ -304,4 +304,44 @@ describe("ngHyd − calculate with linked parameters", () => { expect(Number(volume)).toBeCloseTo(44.565, 3); }); + it(" − a link target parameter should not be able to link to another parameter", async () => { + debugger + // create 1st PAB-Chute + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // upstream water level should not have link mode (only one calculator) + const Z1_1 = calcPage.getInputById("Z1"); + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(false); + + // create 2nd PAB-Chute + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // back to 1st calculator + await navBar.clickCalculatorTab(0); + await browser.sleep(200); + + // upstream water level should have link mode (now there are 2 calculators) + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(true); + + // back to 2nd calculator + await navBar.clickCalculatorTab(1); + await browser.sleep(200); + + // link upstream water level in 2nd calculator to upstream water level in 1st one + const Z1_2 = calcPage.getInputById("Z1"); + await calcPage.setParamMode(Z1_2, "link"); + + // back to 1st calculator + await navBar.clickCalculatorTab(0); + await browser.sleep(200); + + // upstream water level should not have link mode (already a link target) + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(false); + }); }); diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index ed78fc4e2..af1e1803c 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -184,6 +184,14 @@ export class CalculatorPage { return await button.isPresent(); } + async inputHasLinkModeButton(input: ElementFinder) { + // get parent (div.container) + const container = await this.findParentContainer(input); + // find radio buttons + const button: ElementFinder = container.element(by.css("mat-button-toggle.radio_link > button")); + return await button.isPresent(); + } + /** * @returns true if "fixed mode" button linked to an input is selected */ -- GitLab From b2ca09078a680b5cfcb0158854c30405311bd1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 10 Feb 2023 17:19:52 +0100 Subject: [PATCH 2/3] update jalhyd_branch to 341-un-parametre-cible-d-un-lien-ne-doit-pas-se-lier-a-un-autre-parametre refs #605 --- jalhyd_branch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jalhyd_branch b/jalhyd_branch index 0bd0de843..af02f54ce 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -334-restructurer-lechapt-et-calmon-pour-de-nouvelles-lois-de-pertes-de-charge +341-un-parametre-cible-d-un-lien-ne-doit-pas-se-lier-a-un-autre-parametre -- GitLab From 1a57009870ba194bf69e6873942da098a3d968de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 10 Feb 2023 17:20:10 +0100 Subject: [PATCH 3/3] fix: disable link radio button for a parameter which is a link target refs #605 --- .../param-field-line.component.html | 1 + .../param-field-line.component.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/components/param-field-line/param-field-line.component.html b/src/app/components/param-field-line/param-field-line.component.html index 641d9c4b0..6cc879f86 100644 --- a/src/app/components/param-field-line/param-field-line.component.html +++ b/src/app/components/param-field-line/param-field-line.component.html @@ -41,6 +41,7 @@ <span fxHide.gt-xxs>C</span> </mat-button-toggle> + <!-- (click)="onRadioClick('link')" [checked]="isRadioLinkChecked" [disabled]="isRadioLinkDisabled"> --> <mat-button-toggle class="radio_link" value="radio_link" *ngIf="hasRadioLink()" (click)="onRadioClick('link')" [checked]="isRadioLinkChecked" [disabled]="! canExitCalcMode()"> <span fxHide.xxs>{{ uitextParamLie }}</span> diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index a64528e1f..2dbe5a333 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -4,7 +4,7 @@ import { I18nService } from "../../services/internationalisation.service"; import { NgParameter, ParamRadioConfig } from "../../formulaire/elements/ngparam"; import { NgParamInputComponent } from "../ngparam-input/ngparam-input.component"; import { ServiceFactory } from "../../services/service-factory"; -import { ParamValueMode, ParallelStructure, ParamCalculability, Pab } from "jalhyd"; +import { ParamValueMode, ParallelStructure, ParamCalculability, Pab, Session } from "jalhyd"; import { FormulaireService } from "../../services/formulaire.service"; import { ParamLinkComponent } from "../param-link/param-link.component"; import { ParamValuesComponent } from "../param-values/param-values.component"; @@ -192,7 +192,7 @@ export class ParamFieldLineComponent implements OnChanges { * calcule la présence du radio "paramètre lié" (importé d'un autre module de calcul) */ public hasRadioLink(): boolean { - if (this._formService.formulaires.length > 0) { + if (this._formService.formulaires.length > 0 && !this.isParameterLinkTarget()) { // au moins 2 modules de calcul ouverts if (this._formService.formulaires.length > 1) { return this._formService.getLinkableValues(this.param).length > 0; @@ -254,6 +254,20 @@ export class ParamFieldLineComponent implements OnChanges { return false; } + /** + * @returns true if parameter is a link target + */ + private isParameterLinkTarget(): boolean { + return Session.getInstance().isParameterLinkTarget(this.param.paramDefinition); + } + + /** + * compute link radio button "disabled" status + */ + public get isRadioLinkDisabled(): boolean { + return !this.canExitCalcMode() || this.isParameterLinkTarget(); + } + public get radioCalTitle(): string { if (this.isRadioCalDisabled) { return this.intlService.localizeText("INFO_PARAMFIELD_CANNOT_CALC_LINKS_LOOP"); -- GitLab