An error occurred while loading the file. Please try again.
-
Mathias Chouet authored546882d4
import { AppPage } from "./app.po";
import { ListPage } from "./list.po";
import { CalculatorPage } from "./calculator.po";
import { Navbar } from "./navbar.po";
import { SideNav } from "./sidenav.po";
import { browser } from "protractor";
/**
* Save and load (serialise and unserialise) calculators to/from JSON files
*/
describe("ngHyd − save and load sessions", () => {
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();
});
it("when loading session-6-calc.test.json file from home page, 6 calculators should be loaded", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-6-calc.test.json");
await browser.sleep(200);
expect(await navbar.getAllCalculatorTabs().count()).toBe(6);
});
it("when loading session-optional-params.test.json file from home page, the calculator should be loaded", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-optional-params.test.json");
await browser.sleep(200);
expect(await navbar.getAllCalculatorTabs().count()).toBe(1);
});
it("when saving a calculator, the current parameter values should be found in the file", async () => {
await startPage.navigateTo();
await listPage.clickMenuEntryForCalcType(2); // Section paramétrée
await browser.sleep(500);
await calcPage.changeSelectValue(calcPage.getSelectById("select_section"), 2); // mode "circulaire"
await calcPage.getInputById("Ks").clear(); // coefficient de Strickler
await browser.sleep(1000);
await calcPage.getInputById("Ks").sendKeys("42");
await browser.sleep(1000);
await calcPage.clickSaveCalcButton();
71727374757677787980818283848586878889909192
// see: https://stackoverflow.com/questions/21935696/protractor-e2e-test-case-for-downloading-pdf-file
const fs = require("fs");
const path = require("path");
const os = require("os");
const filename = path.resolve(os.homedir(), "Téléchargements/session.json");
if (fs.existsSync(filename)) {
// Make sure the browser doesn't have to rename the download.
fs.unlinkSync(filename);
}
await calcPage.getSaveSessionButton().click();
await browser.sleep(1000);
const fileContent = fs.readFileSync(filename, { encoding: "utf8" });
// tslint:disable-next-line:quotemark
expect(fileContent).toContain('"nodeType":3');
// tslint:disable-next-line:quotemark
expect(fileContent).toContain('{"symbol":"Ks","mode":"SINGLE","value":42}');
});
});