diff --git a/e2e/calculate-button-validation.e2e-spec.ts b/e2e/calculate-button-validation.e2e-spec.ts index c6c29ec75f1ca2546274ac4415d6b98aea5bb9fa..137071d830e0addd09d5f2f0df79d50930c58b91 100644 --- a/e2e/calculate-button-validation.e2e-spec.ts +++ b/e2e/calculate-button-validation.e2e-spec.ts @@ -1,7 +1,7 @@ import { ListPage } from "./list.po"; import { CalculatorPage } from "./calculator.po"; import { Navbar } from "./navbar.po"; -import { browser } from "protractor"; +import { browser, by, element } from "protractor"; import { PreferencesPage } from "./preferences.po"; describe("Calculate button - ", () => { @@ -71,4 +71,75 @@ describe("Calculate button - ", () => { disabledStateClone = await calcButtonClone.getAttribute("disabled"); expect(disabledStateClone).toBe("true"); }); + + describe("check button status in prébarrages - ", () => { + it("invalid data in Q input", async () => { + // start page + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + + // open prébarrages calculator + await listPage.clickMenuEntryForCalcType(30); + await browser.sleep(200); + + // Q input + const inputQ = element(by.id("Q")); + await inputQ.clear(); + await browser.sleep(200); + await inputQ.sendKeys("-1"); + await browser.sleep(200); + + calcPage.checkCalcButtonEnabled(false); + + // upstream item + const upstream = element(by.id("amont")); + // should be displayed in error + expect(await upstream.getAttribute('class')).toContain("node-error"); + }); + + it("add basin, invalid data in Q input", async () => { + // start page + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + + // open prébarrages calculator + await listPage.clickMenuEntryForCalcType(30); + await browser.sleep(200); + + // "add basin" button + const addBasinBtn = element(by.id("add-basin")); + await addBasinBtn.click(); + await browser.sleep(200); + + // upstream item + const upstream = element(by.id("amont")); + await upstream.click(); + await browser.sleep(200); + + // invalid data in Q input + const inputQ = element(by.id("Q")); + await inputQ.clear(); + await browser.sleep(200); + await inputQ.sendKeys("-1"); + await browser.sleep(200); + + // calculate button disabled ? + calcPage.checkCalcButtonEnabled(false); + + // upstream item displayed in error ? + expect(await upstream.getAttribute('class')).toContain("node-error"); + + // valid data in Q input + await inputQ.clear(); + await browser.sleep(200); + await inputQ.sendKeys("1"); + await browser.sleep(200); + + // calculate button still disabled ? (the basin is not connected to anything) + calcPage.checkCalcButtonEnabled(false); + + // upstream item displayed not in error ? + expect(await upstream.getAttribute('class')).not.toContain("node-error"); + }); + }); }); diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index 4be6378862b7589d86a2314e73a9f1a00ffa8b34..757a2fa707aec856605435c2f14dd7cd7dda971a 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -221,6 +221,13 @@ export class CalculatorPage { return await cloneButton.click(); } + // check that "compute" button is in given enabled/disabled state + checkCalcButtonEnabled(enabled: boolean) { + const calcButton = this.getCalculateButton(); + expect(calcButton.isEnabled()).toBe(enabled); + return calcButton; + } + async changeSelectValue(elt: ElementFinder, index: number) { await elt.click(); const optionId = ".cdk-overlay-container mat-option:nth-of-type(" + (index + 1) + ")";