From 16502913f57d7ff1060887441a9f60eaa4f99a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 26 Apr 2022 08:19:19 +0200 Subject: [PATCH] test: check cross walls calculator has no empty field after calculation refs #516 --- e2e/pab-cloisons-empty-fields.e2e-spec.ts | 122 +++++++++++++++------- 1 file changed, 87 insertions(+), 35 deletions(-) diff --git a/e2e/pab-cloisons-empty-fields.e2e-spec.ts b/e2e/pab-cloisons-empty-fields.e2e-spec.ts index 1782869db..c7305027a 100644 --- a/e2e/pab-cloisons-empty-fields.e2e-spec.ts +++ b/e2e/pab-cloisons-empty-fields.e2e-spec.ts @@ -5,6 +5,37 @@ 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 @@ -24,34 +55,9 @@ describe("ngHyd - check the cross walls calculator has empty fields - ", () => { }); beforeEach(async () => { - // enable evil option "empty fields on module creation" - await prefPage.navigateTo(); - await browser.sleep(200); - await prefPage.enableEvilEmptyFields(); - await browser.sleep(200); + await enableEmptyFieldsOption(prefPage); }); - /** - * 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(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(symbol: string) { - const inp = calcPage.getInputById(symbol); - await inp.clear(); - await inp.sendKeys("1"); - } - it("in the 'generate fish ladder' dialog", async () => { // open cross walls calculator await navBar.clickNewCalculatorButton(); @@ -59,14 +65,14 @@ describe("ngHyd - check the cross walls calculator has empty fields - ", () => { await browser.sleep(200); // fill inputs - await fillInput("Q"); - await fillInput("Z1"); - await fillInput("LB"); - await fillInput("BB"); - await fillInput("PB"); - await fillInput("0_h1"); - await fillInput("0_L"); - await fillInput("0_CdWSL"); + await fillInput(calcPage, "Q"); + await fillInput(calcPage, "Z1"); + await fillInput(calcPage, "LB"); + await fillInput(calcPage, "BB"); + await fillInput(calcPage, "PB"); + await fillInput(calcPage, "0_h1"); + await fillInput(calcPage, "0_L"); + await fillInput(calcPage, "0_CdWSL"); // calculate const calcButton = calcPage.getCalculateButton(); @@ -78,6 +84,52 @@ describe("ngHyd - check the cross walls calculator has empty fields - ", () => { await genButton.click(); await browser.sleep(200); - await checkFields(["generatePabNbBassins"], [true]); + 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, "Q"); + await fillInput(calcPage, "Z1"); + await fillInput(calcPage, "LB"); + await fillInput(calcPage, "BB"); + await fillInput(calcPage, "PB"); + 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, ["Q", "Z1", "LB", "BB", "PB", "0_h1", "0_L", "0_CdWSL"], [false, false, false, false, false, false, false, false]); }); }); -- GitLab