pab-cloisons-empty-fields.e2e-spec.ts 4.20 KiB
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, "Q");
        await fillInput(calcPage, "Z1");
        await fillInput(calcPage, "LB");
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
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); // 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, "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]); }); });