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

Code before:
          await page.mouse.up();
          await awaitPromise(clickHandle);
          await commit(page);

          await page.waitForSelector(editorSelector);
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.delete`);
          await page.click(`${editorSelector} button.delete`);
          await waitForSerialized(page, 0);
          await page.waitForSelector("#editorUndoBar:not([hidden])");

          const newRect = await getRect(page, ".annotationEditorLayer");
          const newXStart = newRect.x + 300;
          const newYStart = newRect.y + 300;
          const newClickHandle = await waitForPointerUp(page);
          await page.mouse.move(newXStart, newYStart);
          await page.mouse.down();
          await page.mouse.move(newXStart + 50, newYStart + 50);
          await page.mouse.up();
          await awaitPromise(newClickHandle);
          await commit(page);

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

  describe("Ink must update its stroke width when not the current active layer", () => {
    let pages;

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

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

    it("must check that the stroke width has been updated after zooming", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToInk(page);

          const rect = await getRect(page, ".annotationEditorLayer");

          const x = rect.x + 20;

Review comment (refactor):
Note that we already wait for this selector just above this line, so this duplicate definition can simply be removed.

Code after:
          await page.mouse.move(xStart, yStart);
          await page.mouse.down();
          await page.mouse.move(xStart + 50, yStart + 50);
          await page.mouse.up();
          await awaitPromise(clickHandle);
          await commit(page);

          await page.waitForSelector(editorSelector);
          await waitForSerialized(page, 1);

          await page.waitForSelector(`${editorSelector} button.delete`);
          await page.click(`${editorSelector} button.delete`);
          await waitForSerialized(page, 0);
          await page.waitForSelector("#editorUndoBar:not([hidden])");

          const newRect = await getRect(page, ".annotationEditorLayer");
          const newXStart = newRect.x + 300;
          const newYStart = newRect.y + 300;
          const newClickHandle = await waitForPointerUp(page);
          await page.mouse.move(newXStart, newYStart);
          await page.mouse.down();
          await page.mouse.move(newXStart + 50, newYStart + 50);
          await page.mouse.up();
          await awaitPromise(newClickHandle);
          await commit(page);

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

  describe("Ink must update its stroke width when not the current active layer", () => {
    let pages;

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

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

    it("must check that the stroke width has been updated after zooming", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await switchToInk(page);

          const rect = await getRect(page, ".annotationEditorLayer");