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

Code before:
      pages = await loadAndWait("issue16473.pdf", "[data-annotation-id='22R']");
    });

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

    it("must reset a formatted value after a change", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await page.type(getSelector("22R"), "a");
          await page.keyboard.press("Tab");
          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");
        })
      );
    });
  });
});

describe("Link annotations with internal destinations", () => {
  describe("pdf.pdf", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait(
        "pdf.pdf",
        ".page[data-page-number='1'] .annotationLayer"
      );
    });

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

    it("must click on a link and check if it navigates to the correct page", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const pageFiveSelector = ".page[data-page-number='5']";
          await scrollIntoView(page, pageFiveSelector);
          const linkSelector = `${pageFiveSelector} #pdfjs_internal_id_3928R`;
          await page.waitForSelector(linkSelector);
          const linkTitle = await page.$eval(linkSelector, el => el.title);
          expect(linkTitle)
            .withContext(`In ${browserName}`)
            .toEqual("Chapter 1: Introduction 25");
          await page.click(linkSelector);

Review comment (suggestion):
Is it possible to choose a non-linked PDF here, or create a very minimal one ourselves with two pages where one links to the other? Not only are non-linked PDF easier to manage because we don't have to download them which also helps for running on GitHub Actions in upcoming work, but this is also a pretty big PDF file which can increase integration tests runtime.

Code after:
    });

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

    it("must reset a formatted value after a change", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          await page.type(getSelector("22R"), "a");
          await page.keyboard.press("Tab");
          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");
        })
      );
    });
  });
});

describe("Link annotations with internal destinations", () => {
  describe("bug1708041.pdf", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait(
        "bug1708041.pdf",
        ".page[data-page-number='1'] .annotationLayer"
      );
    });

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

    it("must click on a link and check if it navigates to the correct page", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const pageOneSelector = ".page[data-page-number='1']";
          const linkSelector = `${pageOneSelector} #pdfjs_internal_id_42R`;
          await page.waitForSelector(linkSelector);
          const linkTitle = await page.$eval(linkSelector, el => el.title);
          expect(linkTitle)
            .withContext(`In ${browserName}`)
            .toEqual("Go to the last page");
          await page.click(linkSelector);
          const pageSixTextLayerSelector =
            ".page[data-page-number='6'] .textLayer";