Newer
Older
import { ListPage } from "./list.po";
import { CalculatorPage } from "./calculator.po";
import { Navbar } from "./navbar.po";
import { browser, by, element } from "protractor";
import { AppPage } from "./app.po";
import { SideNav } from "./sidenav.po";
/**
* Clone calculators
*/
describe("ngHyd − Passe à Bassins", () => {
let startPage: AppPage;
let listPage: ListPage;
let calcPage: CalculatorPage;
let navbar: Navbar;
let sidenav: SideNav;
beforeEach(() => {
startPage = new AppPage();
listPage = new ListPage();
calcPage = new CalculatorPage();
navbar = new Navbar();
sidenav = new SideNav();
});
describe("create PAB - ", async () => {
it("when PAB is created from scratch", async() => {
// create PAB
await startPage.navigateTo();
await listPage.clickMenuEntryForCalcType(15);
// check that pab-table is present
const innerFieldsets = element.all(by.css(".pab-data-table"));
expect(await innerFieldsets.count()).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);
});
});
describe("generate PAB - ", async () => {
it("from a Cloisons among many", async() => {
// create many Cloisons
await startPage.navigateTo();
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.clear();
await Z1.sendKeys("114");
const LB = calcPage.getInputById("LB");
await LB.clear();
await LB.sendKeys("11.5");
const DH = calcPage.getInputById("DH");
await DH.clear();
await DH.sendKeys("0.72");
// 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("1.5");
await debit.clear();
// send "1.6" in 3 movements, because "." triggers an error and Angular can't cope with the subsequent keys
await debit.sendKeys("1");
await browser.sleep(300);
await debit.sendKeys(".");
await browser.sleep(300);
await debit.sendKeys("6");
const coteAmont = calcPage.getInputById("generatePabCoteAmont");
expect(await coteAmont.getAttribute("value")).toBe("114");
await coteAmont.clear();
await coteAmont.sendKeys("115");
const nbBassins = calcPage.getInputById("generatePabNbBassins");
expect(await nbBassins.getAttribute("value")).toBe("6");
await nbBassins.clear();
await nbBassins.sendKeys("5");
// click "Generate"
await element(by.css("dialog-generate-pab button#do-generate")).click();
await browser.sleep(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");
const innerFieldsets = element.all(by.css("td.basin_number"));
expect(await innerFieldsets.count()).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);
// check absence of logs
expect(await calcPage.nbLogEntries()).toBe(0);
});
});
describe("load session files - ", async () => {
it("when PAB is loaded after Cloisons & ParallelStructure", async() => {
await startPage.navigateTo();
// load
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-pab.json");
await browser.sleep(500);
// check existence of the loaded modules
expect(await navbar.getAllCalculatorTabs().count()).toBe(6);
await browser.sleep(700); // sometime fails because of tabs order @see nghyd#197
const P_Q = calcPage.getInputById("Q");
expect(await P_Q.getAttribute("value")).toBe("1.533");
const P_Z2 = calcPage.getInputById("Z2");
expect(await P_Z2.getAttribute("value")).toBe("99.44");
// check number of basins
const innerFieldsets = element.all(by.css(".fieldset-inner"));
expect(await innerFieldsets.count()).toBe(5);
const expectedCloisons = [ "Cloisons 1", "Cloisons 2", "Cloisons", "Cloisons 2", "Cloisons 1" ];
for (let i = 0; i < innerFieldsets.length; i++) {
const inf = innerFieldsets[i];
const smc = inf.element(by.css("mat-select#select_modele_cloisons"));
expect(await calcPage.getSelectValueText(smc)).toEqual(expectedCloisons[i]);
expect(Number(await QA.getAttribute("value"))).toBe(expectedQA[i]);
// check downstream wall
const smca = calcPage.getSelectById("select_modele_cloison_aval");
expect(await calcPage.getSelectValueText(smca)).toEqual("Ouvrages 1");
describe("load regulated variated PAB with calc errors - ", async () => {
it("should display logs", async() => {
await startPage.navigateTo();
// load
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-pab-regulee-variee.json");
await browser.sleep(500);
// check existence of the loaded module
expect(await navbar.getAllCalculatorTabs().count()).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
expect(await calcPage.nbLogEntries()).toBe(2);
// change iteration
const pve = calcPage.getSelectById("pab-variating-element");
calcPage.changeSelectValue(pve, 3);
await browser.sleep(300);
// check absence of logs
expect(await calcPage.nbLogEntries()).toBe(1);
});
});