Commit a852698c authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '516-cloisons-generer-une-pab-vider-les-champs' into 'devel'

Resolve "Cloisons > Générer une PAB: vider les champs"

Closes #516

See merge request !126
parents 4a32a491 2d2f00d0
Pipeline #35722 passed with stages
in 48 minutes and 56 seconds
......@@ -53,9 +53,10 @@ describe("ngHyd − example sessions −", async () => {
if (examples.length > i) {
// click example #i
await examples[i].click();
await browser.sleep(50);
await browser.sleep(200);
const nbModules = await navbar.getCalculatorEntriesCount();
await browser.sleep(200);
for (let j = 0; j < nbModules; j++) {
// select module
await navbar.openNthCalculator(j);
......
......@@ -58,4 +58,97 @@ describe("ngHyd - Check that examples fields are not empty with 'empty fields on
const emptys = [false, false, false, false, false];
await checkFields(inputIds, emptys);
});
it("calculated parameter initial value when discharge law is modified", async () => {
// start page
await navBar.clickNewCalculatorButton();
await browser.sleep(200);
// open 1st example
const examples = await element.all(by.css("#examples-list .load-example"));
await examples[0].click();
await browser.sleep(50);
// select wall module
await navBar.openNthCalculator(4);
await browser.sleep(50);
// modify 1st structure discharge law
const dischargeSelect = calcPage.getSelectById("select_loidebit");
await calcPage.changeSelectValue(dischargeSelect, 1);
await browser.sleep(200);
// open initial dialog
const initDlgButton = element(by.className("param-computed-more"));
await initDlgButton.click();
await browser.sleep(200);
// check input value is not null
const input = calcPage.getInputById("initval-input");
const underlyingInput = input.element(by.id("0_h1"));
const txt = await underlyingInput.getAttribute("value");
expect(txt === "").toEqual(false);
});
});
describe("ngHyd - Check that examples work with 'empty fields on calculator creation' enabled - ", () => {
let prefPage: PreferencesPage;
let navBar: Navbar;
let calcPage: CalculatorPage;
beforeEach(async () => {
prefPage = new PreferencesPage();
navBar = new Navbar();
calcPage = new CalculatorPage();
// enable evil option "empty fields on module creation"
await prefPage.navigateTo();
await browser.sleep(200);
await prefPage.enableEvilEmptyFields();
await browser.sleep(200);
});
it("when calculation is run on a generated fish ladder calculator", async () => {
debugger
// start page
await navBar.clickNewCalculatorButton();
await browser.sleep(200);
// open 1st example
const examples = await element.all(by.css("#examples-list .load-example"));
await examples[0].click();
await browser.sleep(50);
// select wall module
await navBar.openNthCalculator(4);
await browser.sleep(50);
// run calculation
const calcButton = calcPage.getCalculateButton();
await calcButton.click();
await browser.sleep(200);
// click "generate PAB" button
const genButton = calcPage.getGeneratePabButton();
await genButton.click();
await browser.sleep(200);
// write "6" in basin count input
const nbBassins = calcPage.getInputById("generatePabNbBassins");
await nbBassins.sendKeys("6");
await browser.sleep(50);
// click "Generate PAB"
await element(by.css("dialog-generate-pab button#do-generate")).click();
await browser.sleep(1000);
// calculate PAB
const calcButtonPAB = calcPage.getCalculateButton();
await calcButtonPAB.click();
await browser.sleep(200);
// check that result is not empty
const hasResults = await calcPage.hasResults();
expect(hasResults).toBe(true);
});
});
......@@ -2,40 +2,44 @@ import { ListPage } from "./list.po";
import { browser, by, element } from "protractor";
import { CalculatorPage } from "./calculator.po";
import { AppPage } from "./app.po";
import { PreferencesPage } from "./preferences.po";
import { Navbar } from "./navbar.po";
/**
* Check that created/cloned structures have empty fields when
* "empty fields on calculator creation" is enabled
*/
describe("ngHyd - check that created/cloned structures have empty fields - ", () => {
//let prefPage: PreferencesPage;
let startPage: AppPage;
let prefPage: PreferencesPage;
let listPage: ListPage;
let calcPage: CalculatorPage;
let navBar: Navbar;
beforeAll(() => {
//prefPage = new PreferencesPage();
startPage = new AppPage();
prefPage = new PreferencesPage();
listPage = new ListPage();
calcPage = new CalculatorPage();
navBar = new Navbar();
browser.manage().window().setPosition(2000, 30);
});
beforeEach(async () => {
// enable evil option "empty fields on module creation"
// await prefPage.navigateTo();
// await prefPage.enableEvilEmptyFields(); // message "stale element reference: element is not attached to the page document"
// await browser.sleep(200);
// assume that "empty fields on module creation" is true by default
await prefPage.navigateTo();
await browser.sleep(200);
await prefPage.enableEvilEmptyFields();
await browser.sleep(200);
});
async function setup() {
// start page
await startPage.navigateTo();
await navBar.clickNewCalculatorButton();
await browser.sleep(200);
// open structures calculator
await listPage.clickMenuEntryForCalcType(8);
await browser.sleep(200);
});
}
/**
* check that a input set is in a given (empty/filled) state
......@@ -53,9 +57,11 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
}
it("when a structure calculator is created", async () => {
await setup();
// check 1st structure empty fields
const inputIds = ["Q", "calc_Z1", "Z2", "0_ZDV", "0_L", "0_W", "0_CdGR"];
const emptys = [true, false, true, true, true, true, false];
const inputIds = ["Q", "Z1", "Z2", "0_ZDV", "0_L", "0_W", "0_CdGR"];
const emptys = [true, true, true, true, true, true, false];
await checkFields(inputIds, emptys);
// change 1st structure type to rectangular weir
......@@ -64,12 +70,14 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
await browser.sleep(200);
// check 1st structure empty fields
const inputIds2 = ["Q", "calc_Z1", "Z2", "0_ZDV", "0_L", "0_CdWR"];
const emptys2 = [true, false, true, true, true, false];
const inputIds2 = ["Q", "Z1", "Z2", "0_ZDV", "0_L", "0_CdWR"];
const emptys2 = [true, true, true, true, true, false];
await checkFields(inputIds2, emptys2);
});
it("when a structure is added", async () => {
await setup();
// add structure
const addStruct = calcPage.getAddStructureButton();
await addStruct.click();
......@@ -81,6 +89,8 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
});
it("when a structure is copied", async () => {
await setup();
// copy structure
const addStruct = calcPage.getCopyStructureButton();
await addStruct.click();
......@@ -91,7 +101,9 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
await checkFields(inputIds, emptys);
});
it("when a modified structure is copied", async () => {
it("when a modified structure is copied (type)", async () => {
await setup();
// change 1st structure type to rectangular weir
const structSelect = calcPage.getSelectById("select_structure");
await calcPage.changeSelectValue(structSelect, 1);
......@@ -103,7 +115,8 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
await browser.sleep(200);
// change 2nd structure type to rectangular gate
const structSelect2 = element(by.className("ng-tns-c3-47"));
const selects = await element.all(by.css("mat-select#select_structure"));
const structSelect2 = selects[1];
await calcPage.changeSelectValue(structSelect2, 4);
await browser.sleep(200);
......@@ -113,7 +126,28 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", ()
await checkFields(inputIds, emptys);
});
it("when a modified structure is copied (input)", async () => {
await setup();
// fill
const inp = calcPage.getInputById("0_ZDV");
await inp.clear();
await inp.sendKeys("1");
// copy structure
const addStruct = calcPage.getCopyStructureButton();
await addStruct.click();
await browser.sleep(200);
// check empty fields
const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"];
const emptys = [false, true, true, false];
await checkFields(inputIds, emptys);
});
it("except for discharge coefficient when a Larinier weir is used", async () => {
await setup();
// change 1st structure type to rectangular weir
const structSelect = calcPage.getSelectById("select_structure");
await calcPage.changeSelectValue(structSelect, 1);
......
import { ListPage } from "./list.po";
import { PreferencesPage } from "./preferences.po";
import { browser, by, element } from "protractor";
import { CalculatorPage } from "./calculator.po";
import { AppPage } from "./app.po";
import { Navbar } from "./navbar.po";
/**
* enable evil option "empty fields on module creation"
*/
async function enableEmptyFieldsOption(prefPage: PreferencesPage) {
await prefPage.navigateTo();
await browser.sleep(200);
await prefPage.enableEvilEmptyFields();
await browser.sleep(200);
}
/**
* check that a input set is in a given (empty/filled) state
* @param inputIds id of the inputs to check
* @param emptys empty/not empty state array
*/
async function checkFields(calcPage: CalculatorPage, inputIds: string[], emptys: boolean[]) {
let n = 0;
for (const id of inputIds) {
const inp = await calcPage.getInputById(id);
const txt = await inp.getAttribute("value");
expect(txt === "").toEqual(emptys[n]);
n++;
}
}
async function fillInput(calcPage: CalculatorPage, symbol: string) {
const inp = calcPage.getInputById(symbol);
await inp.clear();
await inp.sendKeys("1");
}
/**
* Check that when "empty fields on calculator creation" is enabled
* fields are empty in the "generate fish ladder" dialog of the
* cross walls calculator
*/
describe("ngHyd - check the cross walls calculator has empty fields - ", () => {
let prefPage: PreferencesPage;
let listPage: ListPage;
let calcPage: CalculatorPage;
let navBar: Navbar;
beforeAll(() => {
prefPage = new PreferencesPage();
listPage = new ListPage();
calcPage = new CalculatorPage();
navBar = new Navbar();
});
beforeEach(async () => {
await enableEmptyFieldsOption(prefPage);
});
it("in the 'generate fish ladder' dialog", async () => {
// open cross walls calculator
await navBar.clickNewCalculatorButton();
await listPage.clickMenuEntryForCalcType(10);
await browser.sleep(200);
// fill inputs
await fillInput(calcPage, "Z1");
await fillInput(calcPage, "LB");
await fillInput(calcPage, "BB");
await fillInput(calcPage, "PB");
await fillInput(calcPage, "DH");
await fillInput(calcPage, "0_h1");
await fillInput(calcPage, "0_L");
await fillInput(calcPage, "0_CdWSL");
// calculate
const calcButton = calcPage.getCalculateButton();
await calcButton.click();
await browser.sleep(200);
// click "generate PAB" button
const genButton = calcPage.getGeneratePabButton();
await genButton.click();
await browser.sleep(200);
await checkFields(calcPage, ["generatePabNbBassins"], [true]);
});
});
/**
* Check that when "empty fields on calculator creation" is enabled
* fields are not empty after calculation
*/
describe("ngHyd - check the cross walls calculator has no empty field - ", () => {
let prefPage: PreferencesPage;
let listPage: ListPage;
let calcPage: CalculatorPage;
let navBar: Navbar;
beforeAll(() => {
prefPage = new PreferencesPage();
listPage = new ListPage();
calcPage = new CalculatorPage();
navBar = new Navbar();
});
beforeEach(async () => {
await enableEmptyFieldsOption(prefPage);
});
it("after calculation", async () => {
// open cross walls calculator
await navBar.clickNewCalculatorButton();
await listPage.clickMenuEntryForCalcType(10);
await browser.sleep(200);
// fill inputs
await fillInput(calcPage, "Z1");
await fillInput(calcPage, "LB");
await fillInput(calcPage, "BB");
await fillInput(calcPage, "PB");
await fillInput(calcPage, "DH");
await fillInput(calcPage, "0_h1");
await fillInput(calcPage, "0_L");
await fillInput(calcPage, "0_CdWSL");
// calculate
const calcButton = calcPage.getCalculateButton();
await calcButton.click();
await browser.sleep(200);
await checkFields(calcPage, ["Z1", "LB", "BB", "PB", "DH", "0_h1", "0_L", "0_CdWSL"], [false, false, false, false, false, false, false, false]);
});
});
307-courbe-de-remous-crash-de-l-application-sur-donnees-erronees
\ No newline at end of file
devel
\ No newline at end of file
......@@ -15,7 +15,7 @@ export class NgBaseParam extends Observable {
constructor(symb: string, d: ParamDomain | ParamDomainValue, val: number, unit?: string) {
super();
this._param = new ParamDefinition(null, symb, d, unit, val);
this._param = new ParamDefinition(null, symb, d, unit, val, undefined, undefined, false);
}
public get param() {
......
......@@ -181,10 +181,6 @@ export class CalculatorListComponent implements OnInit {
}
}
}
if (this.appSetupService.enableEmptyFieldsOnFormInit) {
f.emptyFields();
}
}
public get nbOpenCalculators() {
......
......@@ -3,7 +3,7 @@
<form>
<div mat-dialog-content>
<ngparam-input [title]="param.title"></ngparam-input>
<ngparam-input id="initval-input" [title]="param.title"></ngparam-input>
</div>
<div mat-dialog-actions [attr.align]="'end'">
......
......@@ -18,8 +18,6 @@ export class DialogGeneratePABComponent {
public coteAmont = 102;
public chute: number;
public nbBassins = 6;
constructor(
......@@ -29,21 +27,18 @@ export class DialogGeneratePABComponent {
@Inject(MAT_DIALOG_DATA) public data: any
) {
const nDigits = this.appSetupService.displayPrecision;
this.coteAmont = round(data.coteAmont, nDigits);
this.debit = round(data.debit, nDigits);
this.chute = round(data.chute, nDigits);
this.coteAmont = data.coteAmont ? round(data.coteAmont, nDigits) : undefined;
this.debit = data.debit ? round(data.debit, nDigits) : undefined;
this.nbBassins = data.nbBassins;
}
public generatePAB() {
// calculate downstream elevation
const coteAval = this.coteAmont - (this.chute * this.nbBassins);
// create PAB
this.dialogRef.close({
generate: true,
debit: this.debit,
coteAmont: this.coteAmont,
coteAval: coteAval,
nbBassins: this.nbBassins
debit: +this.debit,
coteAmont: +this.coteAmont,
nbBassins: +this.nbBassins
});
}
......
import { Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren,
QueryList, AfterViewChecked, ElementRef, Inject, forwardRef, isDevMode } from "@angular/core";
import {
Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren,
QueryList, AfterViewChecked, ElementRef, Inject, forwardRef, isDevMode
} from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import {
......@@ -58,6 +60,7 @@ import { MatomoTracker } from "ngx-matomo";
import { sprintf } from "sprintf-js";
import * as XLSX from "xlsx";
import { ServiceFactory } from "app/services/service-factory";
@Component({
selector: "hydrocalc",
......@@ -307,7 +310,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
}
public get quicknavItems() {
const elts = [ "input", "results" ];
const elts = ["input", "results"];
if (this.isWide && this.hasResults) {
elts.push("charts");
}
......@@ -328,7 +331,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
* the UI validity state)
*/
ngDoCheck() {
this.isCalculateDisabled = ! this._isUIValid;
this.isCalculateDisabled = !this._isUIValid;
}
ngOnDestroy() {
......@@ -362,7 +365,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
}
public ngAfterViewChecked() {
if (! this.firstViewChecked) {
if (!this.firstViewChecked) {
this.firstViewChecked = true;
this.afterFirstViewChecked();
}
......@@ -393,7 +396,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
}
public doCompute() {
if (! isDevMode()) {
if (!isDevMode()) {
this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]);
}
this._formulaire.resetResults([]);
......@@ -444,7 +447,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
try {
this.appComponent.scrollToQuicknav("results");
} catch (e) {
const element = document.getElementById ("fake-results-anchor");
const element = document.getElementById("fake-results-anchor");
if (element) {
element.scrollIntoView();
}
......@@ -471,7 +474,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
*/
private updateUIValidity() {
this._isUIValid = false;
if (! this._formulaire.calculateDisabled) {
if (!this._formulaire.calculateDisabled) {
// all fieldsets must be valid
this._isUIValid = true;
if (this._fieldsetComponents !== undefined) {
......@@ -694,14 +697,14 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
private allParamsAreFixed(except: string[] = []) {
let ret = true;
for (const p of this._formulaire.currentNub.parameterIterator) {
if (! except.includes(p.symbol)) {
if (!except.includes(p.symbol)) {
if (p.valueMode === ParamValueMode.LINK) {
ret = ret && (! p.hasMultipleValues);
ret = ret && (!p.hasMultipleValues);
} else {
// avoid calling hasMultipleValues here, because changing parameter mode in GUI
// switches valueMode before setting min/max/step or valuesList, and iterator
// checker fails to count values that do not exist yet
ret = ret && (! [ ParamValueMode.LISTE, ParamValueMode.MINMAX ].includes(p.valueMode));
ret = ret && (![ParamValueMode.LISTE, ParamValueMode.MINMAX].includes(p.valueMode));
}
}
}
......@@ -716,10 +719,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
}
public get uitextGeneratePabTitle() {
if (! this.hasResults) {
if (!this.hasResults) {
return this.intlService.localizeText("INFO_CALCULATE_FIRST");
}
if (! this.allParamsAreFixed()) {
if (!this.allParamsAreFixed()) {
return this.intlService.localizeText("INFO_PARAMETRES_FIXES");
}
return "";
......@@ -731,41 +734,48 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
public generatePAB() {
// création du dialogue de génération d'une passe à bassin
const cloisons = (this._formulaire.currentNub as Cloisons);
const chute = cloisons.prms.DH.V;
const debit = cloisons.prms.Q.V;
const zAmont = cloisons.prms.Z1.V;
const nbBassins = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit ? undefined : 6;
const dialogRef = this.generatePABDialog.open(
DialogGeneratePABComponent,
{
data: {
chute: cloisons.prms.DH.V,
debit: cloisons.prms.Q.V,
coteAmont: cloisons.prms.Z1.V
},
disableClose: false
}
DialogGeneratePABComponent,
{
data: {
debit: debit,