From 38503d1c5fca979424485ed1ad0c523c617e0a5c Mon Sep 17 00:00:00 2001
From: Calixte Denizet <calixte.denizet@gmail.com>
Date: Sat, 8 May 2021 15:36:16 +0200
Subject: [PATCH] Fix some integration tests

---
 test/integration/annotation_spec.js |  4 ++++
 test/integration/scripting_spec.js  | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/test/integration/annotation_spec.js b/test/integration/annotation_spec.js
index bdf3aa4e5..a2444ea01 100644
--- a/test/integration/annotation_spec.js
+++ b/test/integration/annotation_spec.js
@@ -72,6 +72,10 @@ describe("Checkbox annotation", () => {
         pages.map(async ([browserName, page]) => {
           for (const selector of selectors) {
             await page.click(selector);
+            await page.waitForFunction(
+              `document.querySelector("${selector} > :first-child").checked`
+            );
+
             for (const otherSelector of selectors) {
               const checked = await page.$eval(
                 `${otherSelector} > :first-child`,
diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js
index de950357a..d9fb4f771 100644
--- a/test/integration/scripting_spec.js
+++ b/test/integration/scripting_spec.js
@@ -67,6 +67,10 @@ describe("Interaction", () => {
           await page.type("#\\34 16R", "3.14159", { delay: 200 });
           await page.click("#\\34 19R");
 
+          await page.waitForFunction(
+            `getComputedStyle(document.querySelector("#\\\\34 27R")).visibility !== "hidden"`
+          );
+
           visibility = await page.$eval(
             "#\\34 27R",
             el => getComputedStyle(el).visibility
@@ -80,6 +84,10 @@ describe("Interaction", () => {
           // and leave it
           await page.click("#\\34 19R");
 
+          await page.waitForFunction(
+            `getComputedStyle(document.querySelector("#\\\\34 27R")).visibility !== "visible"`
+          );
+
           visibility = await page.$eval(
             "#\\34 27R",
             el => getComputedStyle(el).visibility
@@ -531,6 +539,7 @@ describe("Interaction", () => {
       await Promise.all(
         pages.map(async ([browserName, page]) => {
           for (const num of [7, 6, 4, 3, 2, 1]) {
+            await clearInput(page, "#\\33 3R");
             await page.click(`option[value=Export${num}]`);
             await page.waitForFunction(
               `document.querySelector("#\\\\33 3R").value !== ""`
@@ -560,6 +569,7 @@ describe("Interaction", () => {
           );
 
           for (const num of [7, 6, 4, 3, 2, 1]) {
+            await clearInput(page, "#\\33 3R");
             await page.click(`option[value=Export${num}]`);
             await page.waitForFunction(
               `document.querySelector("#\\\\33 3R").value !== ""`
@@ -579,6 +589,7 @@ describe("Interaction", () => {
           let len = 6;
           for (const num of [1, 3, 5, 6, 431, -1, 0]) {
             ++len;
+            await clearInput(page, "#\\33 3R");
             await clearInput(page, "#\\33 9R");
             await page.type("#\\33 9R", `${num},Insert${num},Tresni${num}`, {
               delay: 10,
@@ -611,6 +622,7 @@ describe("Interaction", () => {
         pages.map(async ([browserName, page]) => {
           let len = 6;
           // Click on Restore button.
+          await clearInput(page, "#\\33 3R");
           await page.click("[data-annotation-id='37R']");
           await page.waitForFunction(
             `document.querySelector("#\\\\33 0R").children.length === ${len}`