From 59c6168d1be3b078b5cda4be91d909a8c9d61a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 7 Oct 2022 14:44:04 +0200 Subject: [PATCH] refactor(e2e): move empty input checking functions to calculator.po refs #569 --- e2e/calculator.po.ts | 27 +++++++++++++++++++- e2e/examples-empty-fields.e2e-spec.ts | 17 +------------ e2e/ouvrages-empty-fields.e2e-spec.ts | 31 ++++++----------------- e2e/pab-cloisons-empty-fields.e2e-spec.ts | 19 ++------------ e2e/predam-empty-fields.e2e-spec.ts | 22 ++++++---------- 5 files changed, 45 insertions(+), 71 deletions(-) diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index cb46ead62..5fc98c54e 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -329,10 +329,35 @@ export class CalculatorPage { if (!hasDot && !hasExponent && !isN) { keys = "." + keys; } - if (! isOb && await i.getAttribute("disabled") === null) { + if (!isOb && await i.getAttribute("disabled") === null) { await i.sendKeys(keys); } } }); } + + /** + * check that an input is empty + * @param id input id (parameter name) + */ + async checkEmptyInput(id: string) { + const inp = this.getInputById(id); + const val = await inp.getAttribute("value"); + expect(val).toEqual(""); + } + + /** + * 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 checkEmptyOrFilledFields(inputIds: string[], emptys: boolean[]) { + let n = 0; + for (const id of inputIds) { + const inp = await this.getInputById(id); + const txt = await inp.getAttribute("value"); + expect(txt === "").toEqual(emptys[n]); + n++; + } + } } diff --git a/e2e/examples-empty-fields.e2e-spec.ts b/e2e/examples-empty-fields.e2e-spec.ts index 4356743a2..08f40c467 100644 --- a/e2e/examples-empty-fields.e2e-spec.ts +++ b/e2e/examples-empty-fields.e2e-spec.ts @@ -24,21 +24,6 @@ describe("ngHyd - Check that examples fields are not empty with 'empty fields on 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(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++; - } - } - it("when a standard fish ladder calculator is created", async () => { // start page await navBar.clickNewCalculatorButton(); @@ -56,7 +41,7 @@ describe("ngHyd - Check that examples fields are not empty with 'empty fields on // check fields are not empty const inputIds = ["Z1", "LB", "PB", "0_L", "0_CdWSL"]; const emptys = [false, false, false, false, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("calculated parameter initial value when discharge law is modified", async () => { diff --git a/e2e/ouvrages-empty-fields.e2e-spec.ts b/e2e/ouvrages-empty-fields.e2e-spec.ts index d653ecbc3..60f2512f6 100644 --- a/e2e/ouvrages-empty-fields.e2e-spec.ts +++ b/e2e/ouvrages-empty-fields.e2e-spec.ts @@ -41,28 +41,13 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () 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(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++; - } - } - it("when a structure calculator is created", async () => { await setup(); // check 1st structure empty fields 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); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); // change 1st structure type to rectangular weir const structSelect = calcPage.getSelectById("select_structure"); @@ -72,7 +57,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check 1st structure empty fields const inputIds2 = ["Q", "Z1", "Z2", "0_ZDV", "0_L", "0_CdWR"]; const emptys2 = [true, true, true, true, true, false]; - await checkFields(inputIds2, emptys2); + await calcPage.checkEmptyOrFilledFields(inputIds2, emptys2); }); it("when a structure is added", async () => { @@ -85,7 +70,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check 2nd structure empty fields const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"]; const emptys = [true, true, true, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("when a structure is copied", async () => { @@ -98,7 +83,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check 2nd structure empty fields const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"]; const emptys = [true, true, true, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("when a modified structure is copied (type)", async () => { @@ -123,7 +108,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check empty fields const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"]; const emptys = [true, true, true, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("when a modified structure is copied (input)", async () => { @@ -142,7 +127,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check empty fields const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"]; const emptys = [false, true, true, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("except for discharge coefficient when a Larinier weir is used", async () => { @@ -161,7 +146,7 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check empty fields const inputIds = ["0_ZDV", "0_L", "0_CdWSL"]; const emptys = [true, true, true]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); it("when a structure is modified (input) and then a structure is added", async () => { @@ -180,6 +165,6 @@ describe("ngHyd - check that created/cloned structures have empty fields - ", () // check empty fields const inputIds = ["1_ZDV", "1_L", "1_W", "1_CdGR"]; const emptys = [true, true, true, false]; - await checkFields(inputIds, emptys); + await calcPage.checkEmptyOrFilledFields(inputIds, emptys); }); }); diff --git a/e2e/pab-cloisons-empty-fields.e2e-spec.ts b/e2e/pab-cloisons-empty-fields.e2e-spec.ts index 7e99a7de4..6b19d4c3e 100644 --- a/e2e/pab-cloisons-empty-fields.e2e-spec.ts +++ b/e2e/pab-cloisons-empty-fields.e2e-spec.ts @@ -15,21 +15,6 @@ async function enableEmptyFieldsOption(prefPage: PreferencesPage) { 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(); @@ -84,7 +69,7 @@ describe("ngHyd - check the cross walls calculator has empty fields - ", () => { await genButton.click(); await browser.sleep(200); - await checkFields(calcPage, ["generatePabNbBassins"], [true]); + await calcPage.checkEmptyOrFilledFields(["generatePabNbBassins"], [true]); }); }); @@ -130,6 +115,6 @@ describe("ngHyd - check the cross walls calculator has no empty field - ", () => 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]); + await calcPage.checkEmptyOrFilledFields(["Z1", "LB", "BB", "PB", "DH", "0_h1", "0_L", "0_CdWSL"], [false, false, false, false, false, false, false, false]); }); }); diff --git a/e2e/predam-empty-fields.e2e-spec.ts b/e2e/predam-empty-fields.e2e-spec.ts index 6618d97cb..8c1cfb79b 100644 --- a/e2e/predam-empty-fields.e2e-spec.ts +++ b/e2e/predam-empty-fields.e2e-spec.ts @@ -26,12 +26,6 @@ describe("ngHyd − check that predam fields are empty", () => { await browser.sleep(200); }); - async function checkEmptyInput(id: string) { - const inp = calcPage.getInputById(id); - const val = await inp.getAttribute("value"); - expect(val).toEqual(""); - } - it("on creation", async () => { //browser.manage().window().setPosition(2000, 30); // open predam calculator @@ -40,16 +34,16 @@ describe("ngHyd − check that predam fields are empty", () => { await browser.sleep(200); // check upstream inputs - await checkEmptyInput("Q"); + await calcPage.checkEmptyInput("Q"); // Z1 is calculated - await checkEmptyInput("Z2"); + await calcPage.checkEmptyInput("Z2"); // check basin 1 inputs let node = element(by.css("g.node.basin")); await node.click(); await browser.sleep(200); - await checkEmptyInput("0_S"); - await checkEmptyInput("0_ZF"); + await calcPage.checkEmptyInput("0_S"); + await calcPage.checkEmptyInput("0_ZF"); // check walls inputs const walls = element.all(by.css("g.node.wall")); @@ -57,17 +51,17 @@ describe("ngHyd − check that predam fields are empty", () => { await walls.each(async (w) => { await w.click(); await browser.sleep(200); - await checkEmptyInput("0_ZDV"); - await checkEmptyInput("0_L"); + await calcPage.checkEmptyInput("0_ZDV"); + await calcPage.checkEmptyInput("0_L"); }); // check downstream basin inputs node = element(by.css("g[id^='flowchart-aval-']")); // Mermaid generated id await node.click(); await browser.sleep(200); - checkEmptyInput("Q"); + calcPage.checkEmptyInput("Q"); // Z1 is calculated - checkEmptyInput("Z2"); + calcPage.checkEmptyInput("Z2"); }); it("when a basin is added", async () => { -- GitLab