From 5e8b87b3d9fa879a1e14862e3bb69909c9b4186f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Mon, 6 Mar 2023 10:02:45 +0100
Subject: [PATCH] test(e2e): add check of Mathjax formula in calculator help

refs #608
---
 e2e/calculator.po.ts          |  7 +++++
 e2e/documentation.e2e-spec.ts | 55 +++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 e2e/documentation.e2e-spec.ts

diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts
index f2b98b2d9..91878a738 100644
--- a/e2e/calculator.po.ts
+++ b/e2e/calculator.po.ts
@@ -441,4 +441,11 @@ export class CalculatorPage {
             n++;
         }
     }
+
+    /**
+     * get help button related to calculator
+     */
+    getCalculatorHelpButton() {
+        return element(by.css("#help-calc"));
+    }
 }
diff --git a/e2e/documentation.e2e-spec.ts b/e2e/documentation.e2e-spec.ts
new file mode 100644
index 000000000..ea30f5ab5
--- /dev/null
+++ b/e2e/documentation.e2e-spec.ts
@@ -0,0 +1,55 @@
+import { ListPage } from "./list.po";
+import { CalculatorPage } from "./calculator.po";
+import { Navbar } from "./navbar.po";
+import { browser, by, element } from "protractor";
+import { PreferencesPage } from "./preferences.po";
+
+describe("documentation − ", () => {
+    let listPage: ListPage;
+    let calcPage: CalculatorPage;
+    let prefPage: PreferencesPage;
+    let navbar: Navbar;
+
+    beforeAll(() => {
+        calcPage = new CalculatorPage();
+        prefPage = new PreferencesPage();
+        navbar = new Navbar();
+        listPage = new ListPage();
+
+        // browser.manage().window().setPosition(2000, 30);
+    });
+
+    async function checkMathjaxInHelp(lang: number) {
+        // change setup to French
+        await prefPage.navigateTo();
+        await prefPage.changeLanguage(lang);
+        await browser.sleep(200);
+
+        // start page
+        await navbar.clickNewCalculatorButton();
+
+        // open "fish ladder: fall" calculator
+        await listPage.clickMenuEntryForCalcType(12);
+        await browser.sleep(200);
+
+        // click help
+        await calcPage.getCalculatorHelpButton().click();
+        await browser.sleep(200);
+
+        browser.getAllWindowHandles().then(async (handles) => {
+            browser.ignoreSynchronization = true; // deprecated but the only solution to work in the newly opened tab
+            browser.switchTo().window(handles[1]).then(async () => {
+                // check Mathjax element is present
+                expect(element.all(by.css("mjx-container")).isPresent()).toBe(true);
+            });
+        });
+    }
+
+    it("check Mathjax formula are displayed in calculator French help", async () => {
+        await checkMathjaxInHelp(1); // fr
+    });
+
+    it("check Mathjax formula are displayed in calculator English help", async () => {
+        await checkMathjaxInHelp(0); // en
+    });
+});
-- 
GitLab