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", () => { let startPage: AppPage; let listPage: ListPage; let calcPage: CalculatorPage; let navbar: Navbar; let sidenav: SideNav; let prefPage: PreferencesPage; beforeAll(() => { startPage = new AppPage(); listPage = new ListPage(); calcPage = new CalculatorPage(); navbar = new Navbar(); sidenav = new SideNav(); prefPage = new PreferencesPage(); }); describe("create PAB - ", () => { beforeEach(async () => { // disable evil option "empty fields on module creation" await prefPage.navigateTo(); await prefPage.disableEvilEmptyFields(); await browser.pause(200); }); 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); // 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"); const c_Z2 = calcPage.getInputById("Z1"); await c_Z2.clearValue(); await c_Z2.setValue("74.86"); // 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"); // 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"); const d_L = calcPage.getInputById("L"); await d_L.clearValue(); await d_L.setValue("3.100"); const d_W = calcPage.getInputById("W"); await d_W.clearValue(); await d_W.setValue("2.5"); // 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"); // 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"); // calculate Cloisons const calcButtonCl = calcPage.getCalculateButton(); await calcButtonCl.click(); // make sure "Generate PAB" button is visible (it might be hidden behind navbar) await scrollPageToTop(); // generate PAB const genButton = calcPage.getGeneratePabButton(); await genButton.isExisting(); await genButton.isDisplayed(); await genButton.click(); const nbBassins = calcPage.getInputById("generatePabNbBassins"); await nbBassins.clearValue(); await nbBassins.setValue("9"); // click "Generate" await $("dialog-generate-pab button#do-generate").click(); await browser.pause(1000); // 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 - ", () => { beforeEach(async () => { // disable evil option "empty fields on module creation" await prefPage.navigateTo(); await prefPage.disableEvilEmptyFields(); await browser.pause(200); }); 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"); const LB = calcPage.getInputById("LB"); await LB.clearValue(); await LB.setValue("11.5"); const DH = calcPage.getInputById("DH"); await DH.clearValue(); await DH.setValue("0.72"); // calculate Cloisons const calcButtonCl = calcPage.getCalculateButton(); await calcButtonCl.click(); // make sure "Generate PAB" button is visible (it might be hidden behind navbar) await scrollPageToTop(); // 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); // 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); const coteAmont = calcPage.getInputById("generatePabCoteAmont"); expect(await coteAmont.getAttribute("value")).toBe("114"); await coteAmont.clearValue(); await coteAmont.setValue("115"); const nbBassins = calcPage.getInputById("generatePabNbBassins"); expect(await nbBassins.getAttribute("value")).toBe("6"); await nbBassins.clearValue(); await nbBassins.setValue("5"); // click "Generate" await $("dialog-generate-pab button#do-generate").click(); await browser.pause(1000); // 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); // 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 - ", () => { it("complete example of all PAB modules", async () => { await startPage.navigateTo(); // load await navbar.clickMenuButton(); await browser.pause(200); await sidenav.clickLoadSessionButton(); await browser.pause(200); await sidenav.loadSessionFile("./session/session-pab-complete.json"); await browser.pause(500); // check existence of the loaded modules expect(await navbar.getAllCalculatorTabs().length).toBe(6); // check parameters values await navbar.clickCalculatorTab(5); await browser.pause(700); 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); // 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 - ", () => { it("should display logs", async () => { await startPage.navigateTo(); // load await navbar.clickMenuButton(); await browser.pause(200); await sidenav.clickLoadSessionButton(); await browser.pause(200); await sidenav.loadSessionFile("./session/session-pab-regulee-variee.json"); await browser.pause(500); // check existence of the loaded module expect(await navbar.getAllCalculatorTabs().length).toBe(1); 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); expect(await calcPage.nbLogEntries()).toBe(2); // change iteration const pve = calcPage.getSelectById("pab-variating-element"); await changeSelectValue(pve, 3); await browser.pause(300); // check absence of logs expect(await calcPage.nbLogEntries()).toBe(2); }); }); });