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

Code before:

    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";
          await page.waitForSelector(`${pageSixTextLayerSelector}`, {
            visible: true,
          });
          await page.waitForFunction(
            sel => {
              const textLayer = document.querySelector(sel);
              return document.activeElement === textLayer;
            },
            {},
            pageSixTextLayerSelector
          );
        })
      );
    });
  });
});

describe("Annotation and storage", () => {
  describe("issue14023.pdf", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("issue14023.pdf", "[data-annotation-id='64R']");
    });

    afterEach(async () => {

Review comment (suggestion):
The template string can be replaced with a direct variable reference here:

`await page.waitForSelector(pageSixTextLayerSelector,`

Code after:

    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";
          await page.waitForSelector(pageSixTextLayerSelector, {
            visible: true,
          });
          await page.waitForFunction(
            sel => {
              const textLayer = document.querySelector(sel);
              return document.activeElement === textLayer;
            },
            {},
            pageSixTextLayerSelector
          );
        })
      );
    });
  });
});

describe("Annotation and storage", () => {
  describe("issue14023.pdf", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("issue14023.pdf", "[data-annotation-id='64R']");
    });

    afterEach(async () => {