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

Code before:
 */

import {
  cleanupEditing,
  closePages,
  getEditorSelector,
  loadAndWait,
  switchToEditor,
  waitForTimeout,
} from "./test_utils.mjs";

const switchToSignature = switchToEditor.bind(null, "Signature");

describe("Signature Editor", () => {
  const descriptionInputSelector = "#addSignatureDescription > input";
  const addButtonSelector = "#addSignatureAddButton";

  describe("Basic operations", () => {
    let pages;

    beforeAll(async () => {
      pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", null, {
        eventBusSetup: eventBus => {
          eventBus.on("annotationeditoruimanager", ({ uiManager }) => {
            window.uiManager = uiManager;
          });
        },
      });
    });

    afterEach(async () => {
      await cleanupEditing(pages, switchToSignature);
    });

    afterAll(async () => {
      await closePages(pages);
    });

    it("must check that the editor has been removed when the dialog is cancelled", async () => {
      await Promise.all(
        pages.map(async ([_, page]) => {
          await switchToSignature(page);
          await page.click("#editorSignatureAddSignature");

          await page.waitForSelector("#addSignatureDialog", {
            visible: true,
          });

          // An invisible editor is created but invisible.
          const editorSelector = getEditorSelector(0);
          await page.waitForSelector(editorSelector, { visible: false });

Review comment (suggestion):
Given the current push (done by @timvandermeij) to get the integration-tests to run in a random order, would it perhaps be better to "properly" isolate each test instead?
```suggestion
    beforeEach(async () => {
      pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", null, {
        eventBusSetup: eventBus => {
          eventBus.on("annotationeditoruimanager", ({ uiManager }) => {
            window.uiManager = uiManager;
          });
        },
      });
    });

    afterEach(async () => {
      await closePages(pages);
    });
```

Code after:
 */

import {
  closePages,
  getEditorSelector,
  loadAndWait,
  switchToEditor,
  waitForTimeout,
} from "./test_utils.mjs";

const switchToSignature = switchToEditor.bind(null, "Signature");

describe("Signature Editor", () => {
  const descriptionInputSelector = "#addSignatureDescription > input";
  const addButtonSelector = "#addSignatureAddButton";

  describe("Basic operations", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
    });

    afterEach(async () => {
      await closePages(pages);
    });

    it("must check that the editor has been removed when the dialog is cancelled", async () => {
      await Promise.all(
        pages.map(async ([_, page]) => {
          await switchToSignature(page);
          await page.click("#editorSignatureAddSignature");

          await page.waitForSelector("#addSignatureDialog", {
            visible: true,
          });

          // An invisible editor is created but invisible.
          const editorSelector = getEditorSelector(0);
          await page.waitForSelector(editorSelector, { visible: false });

          await page.click("#addSignatureCancelButton");

          // The editor should have been removed.
          await page.waitForSelector(`:not(${editorSelector})`);
        })
      );
    });

    it("must check that the basic and common elements are working as expected", async () => {
      await Promise.all(