diff --git a/test/integration/annotation_spec.js b/test/integration/annotation_spec.js index ba798461e..40971ddd5 100644 --- a/test/integration/annotation_spec.js +++ b/test/integration/annotation_spec.js @@ -13,49 +13,72 @@ * limitations under the License. */ +const { closePages, loadAndWait } = require("./test_utils.js"); + describe("Annotation highlight", () => { describe("annotation-highlight.pdf", () => { let pages; beforeAll(async () => { - pages = await Promise.all( - global.integrationSessions.map(async session => { - const page = await session.browser.newPage(); - await page.goto( - `${global.integrationBaseUrl}?file=/test/pdfs/annotation-highlight.pdf` - ); - await page.bringToFront(); - await page.waitForSelector("[data-annotation-id='19R']", { - timeout: 0, - }); - return page; - }) + pages = await loadAndWait( + "annotation-highlight.pdf", + "[data-annotation-id='19R']" ); }); afterAll(async () => { - await Promise.all( - pages.map(async page => { - await page.close(); - }) - ); + await closePages(pages); }); it("must show a popup on mouseover", async () => { await Promise.all( - pages.map(async page => { + pages.map(async ([browserName, page]) => { let hidden = await page.$eval( "[data-annotation-id='21R']", el => el.hidden ); - expect(hidden).toEqual(true); + expect(hidden).withContext(`In ${browserName}`).toEqual(true); await page.hover("[data-annotation-id='19R']"); await page.waitForTimeout(100); hidden = await page.$eval( "[data-annotation-id='21R']", el => el.hidden ); - expect(hidden).toEqual(false); + expect(hidden).withContext(`In ${browserName}`).toEqual(false); + }) + ); + }); + }); +}); + +describe("Checkbox annotation", () => { + describe("issue12706.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue12706.pdf", "[data-annotation-id='63R']"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must let checkboxes with the same name behave like radio buttons", async () => { + const selectors = [63, 70, 79].map(n => `[data-annotation-id='${n}R']`); + await Promise.all( + pages.map(async ([browserName, page]) => { + for (const selector of selectors) { + await page.click(selector); + for (const otherSelector of selectors) { + const checked = await page.$eval( + `${otherSelector} > :first-child`, + el => el.checked + ); + expect(checked) + .withContext(`In ${browserName}`) + .toBe(selector === otherSelector); + } + } }) ); }); diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 67835bfbb..ae9999837 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -13,52 +13,38 @@ * limitations under the License. */ +const { closePages, loadAndWait } = require("./test_utils.js"); + describe("Interaction", () => { describe("in 160F-2019.pdf", () => { let pages; beforeAll(async () => { - pages = await Promise.all( - global.integrationSessions.map(async session => { - const page = await session.browser.newPage(); - await page.goto( - `${global.integrationBaseUrl}?file=/test/pdfs/160F-2019.pdf` - ); - await page.bringToFront(); - await page.waitForSelector("#\\34 16R", { - timeout: 0, - }); - return [session.name, page]; - }) - ); + pages = await loadAndWait("160F-2019.pdf", "#\\34 16R"); }); afterAll(async () => { - await Promise.all( - pages.map(async ([_, page]) => { - await page.close(); - }) - ); + await closePages(pages); }); it("must format the field with 2 digits and leave field with a click", async () => { await Promise.all( - pages.map(async ([name, page]) => { + pages.map(async ([browserName, page]) => { await page.type("#\\34 16R", "3.14159", { delay: 200 }); await page.click("#\\34 19R"); const text = await page.$eval("#\\34 16R", el => el.value); - expect(text).withContext(`In ${name}`).toEqual("3,14"); + expect(text).withContext(`In ${browserName}`).toEqual("3,14"); }) ); }); it("must format the field with 2 digits and leave field with a TAB", async () => { await Promise.all( - pages.map(async ([name, page]) => { + pages.map(async ([browserName, page]) => { await page.type("#\\34 22R", "2.7182818", { delay: 200 }); await page.keyboard.press("Tab"); const text = await page.$eval("#\\34 22R", el => el.value); - expect(text).withContext(`In ${name}`).toEqual("2,72"); + expect(text).withContext(`In ${browserName}`).toEqual("2,72"); }) ); }); diff --git a/test/integration/test_utils.js b/test/integration/test_utils.js new file mode 100644 index 000000000..bb22fb97a --- /dev/null +++ b/test/integration/test_utils.js @@ -0,0 +1,36 @@ +/* Copyright 2020 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +exports.loadAndWait = (filename, selector) => + Promise.all( + global.integrationSessions.map(async session => { + const page = await session.browser.newPage(); + await page.goto( + `${global.integrationBaseUrl}?file=/test/pdfs/${filename}` + ); + await page.bringToFront(); + await page.waitForSelector(selector, { + timeout: 0, + }); + return [session.name, page]; + }) + ); + +exports.closePages = pages => + Promise.all( + pages.map(async ([_, page]) => { + await page.close(); + }) + ); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 7ec52a915..e4fca428a 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -331,6 +331,7 @@ !issue5334.pdf !annotation-caret-ink.pdf !bug1186827.pdf +!issue12706.pdf !issue215.pdf !issue5044.pdf !issue1512r.pdf diff --git a/test/pdfs/issue12706.pdf b/test/pdfs/issue12706.pdf new file mode 100644 index 000000000..40bd9e4d4 Binary files /dev/null and b/test/pdfs/issue12706.pdf differ