Skip to content
Snippets Groups Projects
pab.e2e-spec.ts 12 KiB
Newer Older
import { ListPage } from "./list.po";
import { CalculatorPage } from "./calculator.po";
import { Navbar } from "./navbar.po";
import { AppPage } from "./app.po";
import { SideNav } from "./sidenav.po";
import { PreferencesPage } from "./preferences.po";
import { changeSelectValue, scrollPageToTop } from "./util.po";

/**
 * Clone calculators
 */
describe("ngHyd − Passe à Bassins", () => {
mathias.chouet's avatar
mathias.chouet committed
    let startPage: AppPage;
    let listPage: ListPage;
    let calcPage: CalculatorPage;
    let navbar: Navbar;
    let sidenav: SideNav;
    let prefPage: PreferencesPage;

    beforeAll(() => {
mathias.chouet's avatar
mathias.chouet committed
        startPage = new AppPage();
        listPage = new ListPage();
        calcPage = new CalculatorPage();
        navbar = new Navbar();
        sidenav = new SideNav();
        prefPage = new PreferencesPage();
    describe("create PAB - ", () => {
mathias.chouet's avatar
mathias.chouet committed
        beforeEach(async () => {
            // disable evil option "empty fields on module creation"
            await prefPage.navigateTo();
            await prefPage.disableEvilEmptyFields();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
        });

        it("when PAB is created from scratch", async () => {
            // create PAB
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(15);
            // check that pab-table is present
            const innerFieldsets = $$(".pab-data-table");
            expect(await innerFieldsets.length).toBe(1);
mathias.chouet's avatar
mathias.chouet committed

            // calculate PAB
            const calcButton = calcPage.getCalculateButton();
            await calcButton.click();
            // check that result is not empty
            const hasResults = await calcPage.hasResults();
            expect(hasResults).toBe(true);

            // check absence of logs
            expect(await calcPage.nbLogEntries()).toBe(0);
        });

        it("complete example of all PAB modules", async () => {
            // PAB - chute
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(12);
            const c_Z1 = calcPage.getInputById("Z1");
            await c_Z1.clearValue();
            await c_Z1.setValue("78.27");
mathias.chouet's avatar
mathias.chouet committed
            const c_Z2 = calcPage.getInputById("Z1");
            await c_Z2.clearValue();
            await c_Z2.setValue("74.86");
mathias.chouet's avatar
mathias.chouet committed

            // PAB - nombre
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(13);
            const n_DHT = calcPage.getInputById("DHT");
            await calcPage.setParamMode(n_DHT, "link");
            const n_DH = calcPage.getInputById("DH");
            await calcPage.setParamMode(n_DH, "cal");
            const n_N = calcPage.getInputById("N");
            await n_N.clearValue();
            await n_N.setValue("15");
mathias.chouet's avatar
mathias.chouet committed

            // PAB - dimensions
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(5);
            const d_V = calcPage.getInputById("V");
            await calcPage.setParamMode(d_V, "cal");
            const d_Y = calcPage.getInputById("Y");
            await d_Y.clearValue();
            await d_Y.setValue("1.5");
mathias.chouet's avatar
mathias.chouet committed
            const d_L = calcPage.getInputById("L");
            await d_L.clearValue();
            await d_L.setValue("3.100");
mathias.chouet's avatar
mathias.chouet committed
            const d_W = calcPage.getInputById("W");
            await d_W.clearValue();
            await d_W.setValue("2.5");
mathias.chouet's avatar
mathias.chouet committed

            // PAB - puissance dissipée (volume)
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(6);
            const p_DH = calcPage.getInputById("DH");
            await calcPage.setParamMode(p_DH, "link");
            const p_Q = calcPage.getInputById("Q");
            await calcPage.setParamMode(p_Q, "cal");
            const p_V = calcPage.getInputById("V");
            await calcPage.setParamMode(p_V, "link");
            const p_PV = calcPage.getInputById("PV");
            await p_PV.clearValue();
            await p_PV.setValue("150");
mathias.chouet's avatar
mathias.chouet committed

            // PAB - cloisons
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(10);
            const cl_LB = calcPage.getInputById("LB");
            await calcPage.setParamMode(cl_LB, "link");
            const cl_BB = calcPage.getInputById("BB");
            await calcPage.setParamMode(cl_BB, "link");
            const cl_DH = calcPage.getInputById("DH");
            await calcPage.setParamMode(cl_DH, "link");
            const cl_Z1 = calcPage.getInputById("Z1");
            await calcPage.setParamMode(cl_Z1, "link");
            const cl_PB = calcPage.getInputById("PB");
            await cl_PB.clearValue();
            await cl_PB.setValue("1.5");
mathias.chouet's avatar
mathias.chouet committed

            // calculate Cloisons
            const calcButtonCl = calcPage.getCalculateButton();
            await calcButtonCl.click();

            // make sure "Generate PAB" button is visible (it might be hidden behind navbar)
            await scrollPageToTop();
mathias.chouet's avatar
mathias.chouet committed
            // generate PAB
            const genButton = calcPage.getGeneratePabButton();
            await genButton.isExisting();
mathias.chouet's avatar
mathias.chouet committed
            await genButton.isDisplayed();
            await genButton.click();
            const nbBassins = calcPage.getInputById("generatePabNbBassins");
            await nbBassins.clearValue();
            await nbBassins.setValue("9");
mathias.chouet's avatar
mathias.chouet committed

            // click "Generate"
            await $("dialog-generate-pab button#do-generate").click();
            await browser.pause(1000);
mathias.chouet's avatar
mathias.chouet committed

            // calculate PAB
            const calcButtonPAB = calcPage.getCalculateButton();
            await calcButtonPAB.click();
            // check that result is not empty
            const hasResults = await calcPage.hasResults();
            expect(hasResults).toBe(true);
        });
    describe("generate PAB - ", () => {
mathias.chouet's avatar
mathias.chouet committed

        beforeEach(async () => {
            // disable evil option "empty fields on module creation"
            await prefPage.navigateTo();
            await prefPage.disableEvilEmptyFields();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
        });

        it("from a Cloisons among many", async () => {
            // create many Cloisons
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(10);
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(10);
            await navbar.clickNewCalculatorButton();
            await listPage.clickMenuEntryForCalcType(10);
            // choose one of them and change its parameters
            await navbar.clickCalculatorTab(1);
            const Z1 = calcPage.getInputById("Z1");
            await Z1.clearValue();
            await Z1.setValue("114");
mathias.chouet's avatar
mathias.chouet committed
            const LB = calcPage.getInputById("LB");
            await LB.clearValue();
            await LB.setValue("11.5");
mathias.chouet's avatar
mathias.chouet committed
            const DH = calcPage.getInputById("DH");
            await DH.clearValue();
            await DH.setValue("0.72");
mathias.chouet's avatar
mathias.chouet committed

            // calculate Cloisons
            const calcButtonCl = calcPage.getCalculateButton();
            await calcButtonCl.click();

            // make sure "Generate PAB" button is visible (it might be hidden behind navbar)
            await scrollPageToTop();
mathias.chouet's avatar
mathias.chouet committed
            // create PAB from it, changing modal parameters
            const genButton = calcPage.getGeneratePabButton();
            await genButton.click();
            const debit = calcPage.getInputById("generatePabDebit");
            expect(await debit.getAttribute("value")).toBe("0.564");
            await debit.clearValue();
            await browser.pause(300);
mathias.chouet's avatar
mathias.chouet committed
            // send "1.6" in 3 movements, because "." triggers an error and Angular can't cope with the subsequent keys
            await debit.setValue("1");
            await browser.pause(300);
            await debit.setValue(".");
            await browser.pause(300);
            await debit.setValue("6");
            await browser.pause(300);
mathias.chouet's avatar
mathias.chouet committed
            const coteAmont = calcPage.getInputById("generatePabCoteAmont");
            expect(await coteAmont.getAttribute("value")).toBe("114");
            await coteAmont.clearValue();
            await coteAmont.setValue("115");
mathias.chouet's avatar
mathias.chouet committed
            const nbBassins = calcPage.getInputById("generatePabNbBassins");
            expect(await nbBassins.getAttribute("value")).toBe("6");
            await nbBassins.clearValue();
            await nbBassins.setValue("5");
mathias.chouet's avatar
mathias.chouet committed

            // click "Generate"
            await $("dialog-generate-pab button#do-generate").click();
            await browser.pause(1000);
mathias.chouet's avatar
mathias.chouet committed

            // check parameters values
            const P_Q = calcPage.getInputById("Q");
            expect(await P_Q.getAttribute("value")).toBe("1.6");
            const P_Z2 = calcPage.getInputById("Z2");
            expect(await P_Z2.getAttribute("value")).toBe("111.4");

            // check number of basins
            const innerFieldsets = $$("td.basin_number");
            expect(await innerFieldsets.length).toBe(5);
mathias.chouet's avatar
mathias.chouet committed

            // calculate PAB
            const calcButton = calcPage.getCalculateButton();
            await calcButton.click();
            // check that result is not empty
            const hasResults = await calcPage.hasResults();
            expect(hasResults).toBe(true);
        });
    describe("load session files - ", () => {
mathias.chouet's avatar
mathias.chouet committed
        it("complete example of all PAB modules", async () => {
            await startPage.navigateTo();
            // load
            await navbar.clickMenuButton();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
            await sidenav.clickLoadSessionButton();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
            await sidenav.loadSessionFile("./session/session-pab-complete.json");
            await browser.pause(500);
mathias.chouet's avatar
mathias.chouet committed
            // check existence of the loaded modules
            expect(await navbar.getAllCalculatorTabs().length).toBe(6);
mathias.chouet's avatar
mathias.chouet committed

            // check parameters values
            await navbar.clickCalculatorTab(5);
            await browser.pause(700);
mathias.chouet's avatar
mathias.chouet committed
            const P_Q = calcPage.getInputById("Q");
            expect(await P_Q.getAttribute("value")).toBe("0.275");
            const P_Z2 = calcPage.getInputById("Z2");
            expect(await P_Z2.getAttribute("value")).toBe("74.865");
            // check number of basins
            const innerFieldsets = $$("td.basin_number");
            expect(await innerFieldsets.length).toBe(15);
mathias.chouet's avatar
mathias.chouet committed

            // calculate PAB
            const calcButton = calcPage.getCalculateButton();
            await calcButton.click();
            // check that result is not empty
            const hasResults = await calcPage.hasResults();
            expect(hasResults).toBe(true);

            // check absence of logs
            expect(await calcPage.nbLogEntries()).toBe(0);
        });
    describe("load regulated variated PAB with calc errors - ", () => {
mathias.chouet's avatar
mathias.chouet committed
        it("should display logs", async () => {
            await startPage.navigateTo();
            // load
            await navbar.clickMenuButton();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
            await sidenav.clickLoadSessionButton();
            await browser.pause(200);
mathias.chouet's avatar
mathias.chouet committed
            await sidenav.loadSessionFile("./session/session-pab-regulee-variee.json");
            await browser.pause(500);
mathias.chouet's avatar
mathias.chouet committed
            // check existence of the loaded module
            expect(await navbar.getAllCalculatorTabs().length).toBe(1);
mathias.chouet's avatar
mathias.chouet committed
            await navbar.clickCalculatorTab(0);

            // calculate
            const calcButton = calcPage.getCalculateButton();
            await calcButton.click();
            // check that result is not empty
            const hasResults = await calcPage.hasResults();
            expect(hasResults).toBe(true);

            // check presence of logs
            await browser.pause(300);
mathias.chouet's avatar
mathias.chouet committed
            expect(await calcPage.nbLogEntries()).toBe(2);

            // change iteration
            const pve = calcPage.getSelectById("pab-variating-element");
            await changeSelectValue(pve, 3);
            await browser.pause(300);
mathias.chouet's avatar
mathias.chouet committed
            // check absence of logs
            expect(await calcPage.nbLogEntries()).toBe(2);
        });
    });