Repository: mozilla/pdf.js
File: test/integration/highlight_editor_spec.mjs (JavaScript)

Code before:
          await waitForSerialized(page, 0);
          await page.waitForSelector("#editorUndoBar", { visible: true });

          await page.waitForSelector("#editorUndoBarCloseButton", {
            visible: true,
          });
          await page.click("#editorUndoBarCloseButton");
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );
    });

    it("must check that the popup disappears when a new annotation is created", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToHighlight(page);

          await highlightSpan(page, 1, "Abstract");
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.deleteButton`);
          await page.click(`${editorSelector} button.deleteButton`);
          await page.waitForSelector("#editorUndoBar", { visible: true });
          await waitForSerialized(page, 0);

          // eslint-disable-next-line no-restricted-syntax
          await waitForTimeout(100);

          await highlightSpan(page, 1, "Introduction");
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );
    });

    it("must check that the popup disappears when the print dialog is opened", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToHighlight(page);

          await highlightSpan(page, 1, "Abstract");
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.deleteButton`);
          await page.click(`${editorSelector} button.deleteButton`);
          await waitForSerialized(page, 0);
          await page.waitForSelector("#editorUndoBar", { visible: true });

          await page.evaluate(() => window.print());
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );

Review comment (bug):
I assume this is done to address the intermittent failure we've seen here on the bots? If so we should probably add a small comment so we can investigate and hopefully fix this properly later because AFAICT this should never fail.

Code after:
          await page.waitForSelector("#editorUndoBarCloseButton", {
            visible: true,
          });
          await page.click("#editorUndoBarCloseButton");
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );
    });

    it("must check that the popup disappears when a new annotation is created", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToHighlight(page);

          await highlightSpan(page, 1, "Abstract");
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.deleteButton`);
          await page.click(`${editorSelector} button.deleteButton`);
          await page.waitForSelector("#editorUndoBar", { visible: true });

          // TODO: remove the timeout and try to figure out a way to ensure that
          // the previous operations are fully processed before creating a new
          // highlight.
          // eslint-disable-next-line no-restricted-syntax
          await waitForTimeout(100);

          await highlightSpan(page, 1, "Introduction");
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );
    });

    it("must check that the popup disappears when the print dialog is opened", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToHighlight(page);

          await highlightSpan(page, 1, "Abstract");
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.deleteButton`);
          await page.click(`${editorSelector} button.deleteButton`);
          await waitForSerialized(page, 0);
          await page.waitForSelector("#editorUndoBar", { visible: true });

          await page.evaluate(() => window.print());
          await page.waitForSelector("#editorUndoBar", { hidden: true });
        })
      );
    });