Skip to content

Commit

Permalink
Follow-up of mozilla#12707: Add an integration test for checkboxes as…
Browse files Browse the repository at this point in the history
… radio buttons

 * Integration tests: Add a function to load a pdf and wait for a selected element
 * Integration tests: Add a function to close all the open pages
  • Loading branch information
calixteman committed Dec 14, 2020
1 parent 959dc37 commit 5334933
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 42 deletions.
63 changes: 43 additions & 20 deletions test/integration/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 browserName 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);
}
}
})
);
});
Expand Down
30 changes: 8 additions & 22 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
);
});
Expand Down
36 changes: 36 additions & 0 deletions test/integration/test_utils.js
Original file line number Diff line number Diff line change
@@ -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();
})
);
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
!issue5334.pdf
!annotation-caret-ink.pdf
!bug1186827.pdf
!issue12706.pdf
!issue215.pdf
!issue5044.pdf
!issue1512r.pdf
Expand Down
Binary file added test/pdfs/issue12706.pdf
Binary file not shown.

0 comments on commit 5334933

Please sign in to comment.