Skip to content

Commit

Permalink
Remove waitForTimeout usage from the annotation integration tests
Browse files Browse the repository at this point in the history
This commit replaces all `waitForTimeout` occurrences with the
appropriate `waitForFunction` calls. Note that in some places they were
already present, so in those cases we can simply remove the
`waitForTimeout` call altogether.
  • Loading branch information
timvandermeij committed Apr 18, 2024
1 parent 5ad42c1 commit 53769f9
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions test/integration/annotation_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
getQuerySelector,
getSelector,
loadAndWait,
waitForTimeout,
} from "./test_utils.mjs";

describe("Annotation highlight", () => {
Expand Down Expand Up @@ -170,10 +169,6 @@ describe("Checkbox annotation", () => {
);
for (const selector of selectors) {
await page.click(selector);
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
}
for (const selector of selectors) {
await page.waitForFunction(
`document.querySelector("${selector} > :first-child").checked`
);
Expand Down Expand Up @@ -230,8 +225,9 @@ describe("Text widget", () => {
pages.map(async ([browserName, page]) => {
await page.type(getSelector("22R"), "a");
await page.keyboard.press("Tab");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`${getQuerySelector("22R")}.value !== "Hello world"`
);

const text = await page.$eval(getSelector("22R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("aHello World");
Expand Down Expand Up @@ -517,14 +513,10 @@ describe("ResetForm action", () => {
`document.querySelector("[data-annotation-id='25R']").hidden === false`
);
await page.click("#editorFreeText");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='25R']").hidden === true`
);
await page.click("#editorFreeText");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='25R']").hidden === false`
);
Expand Down Expand Up @@ -587,35 +579,39 @@ describe("ResetForm action", () => {
expect(hidden).withContext(`In ${browserName}`).toEqual(true);
await page.focus("[data-annotation-id='20R']");
await page.keyboard.press("Enter");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='21R']").hidden !== true`
);
hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
);
expect(hidden).withContext(`In ${browserName}`).toEqual(false);

await page.keyboard.press("Enter");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='21R']").hidden !== false`
);
hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
);
expect(hidden).withContext(`In ${browserName}`).toEqual(true);

await page.keyboard.press("Enter");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='21R']").hidden !== true`
);
hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
);
expect(hidden).withContext(`In ${browserName}`).toEqual(false);

await page.keyboard.press("Escape");
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(10);
await page.waitForFunction(
`document.querySelector("[data-annotation-id='21R']").hidden !== false`
);
hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
Expand Down

0 comments on commit 53769f9

Please sign in to comment.