mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
AcroForm: Add support for ResetForm action
- it aims to fix #12721. - Thanks to PR #14023, we've now the fieldObjects in the annotation layer so we can easily map fields names on their id if needed. - Reset values in the storage, in the JS sandbox and in the visible html elements.
This commit is contained in:
parent
db7c91e7b1
commit
aecbd7cd89
7 changed files with 302 additions and 15 deletions
|
@ -221,3 +221,133 @@ describe("Annotation and storage", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("ResetForm action", () => {
|
||||
describe("resetform.pdf", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("resetform.pdf", "[data-annotation-id='63R']");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must reset all fields", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const base = "hello world";
|
||||
for (let i = 3; i <= 7; i++) {
|
||||
await page.type(`#\\36 ${i}R`, base);
|
||||
}
|
||||
|
||||
const selectors = [69, 71, 75].map(
|
||||
n => `[data-annotation-id='${n}R']`
|
||||
);
|
||||
for (const selector of selectors) {
|
||||
await page.click(selector);
|
||||
}
|
||||
|
||||
await page.select("#\\37 8R", "b");
|
||||
await page.select("#\\38 1R", "f");
|
||||
|
||||
await page.click("[data-annotation-id='82R']");
|
||||
await page.waitForFunction(
|
||||
`document.querySelector("#\\\\36 3R").value === ""`
|
||||
);
|
||||
|
||||
for (let i = 3; i <= 8; i++) {
|
||||
const text = await page.$eval(`#\\36 ${i}R`, el => el.value);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("");
|
||||
}
|
||||
|
||||
const ids = [69, 71, 72, 73, 74, 75, 76, 77];
|
||||
for (const id of ids) {
|
||||
const checked = await page.$eval(
|
||||
`#\\3${Math.floor(id / 10)} ${id % 10}R`,
|
||||
el => el.checked
|
||||
);
|
||||
expect(checked).withContext(`In ${browserName}`).toEqual(false);
|
||||
}
|
||||
|
||||
let selected = await page.$eval(
|
||||
`#\\37 8R [value="a"]`,
|
||||
el => el.selected
|
||||
);
|
||||
expect(selected).withContext(`In ${browserName}`).toEqual(true);
|
||||
|
||||
selected = await page.$eval(
|
||||
`#\\38 1R [value="d"]`,
|
||||
el => el.selected
|
||||
);
|
||||
expect(selected).withContext(`In ${browserName}`).toEqual(true);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("must reset some fields", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const base = "hello world";
|
||||
for (let i = 3; i <= 8; i++) {
|
||||
await page.type(`#\\36 ${i}R`, base);
|
||||
}
|
||||
|
||||
const selectors = [69, 71, 72, 73, 75].map(
|
||||
n => `[data-annotation-id='${n}R']`
|
||||
);
|
||||
for (const selector of selectors) {
|
||||
await page.click(selector);
|
||||
}
|
||||
|
||||
await page.select("#\\37 8R", "b");
|
||||
await page.select("#\\38 1R", "f");
|
||||
|
||||
await page.click("[data-annotation-id='84R']");
|
||||
await page.waitForFunction(
|
||||
`document.querySelector("#\\\\36 3R").value === ""`
|
||||
);
|
||||
|
||||
for (let i = 3; i <= 8; i++) {
|
||||
const expected = (i - 3) % 2 === 0 ? "" : base;
|
||||
const text = await page.$eval(`#\\36 ${i}R`, el => el.value);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual(expected);
|
||||
}
|
||||
|
||||
let ids = [69, 72, 73, 74, 76, 77];
|
||||
for (const id of ids) {
|
||||
const checked = await page.$eval(
|
||||
`#\\3${Math.floor(id / 10)} ${id % 10}R`,
|
||||
el => el.checked
|
||||
);
|
||||
expect(checked)
|
||||
.withContext(`In ${browserName + id}`)
|
||||
.toEqual(false);
|
||||
}
|
||||
|
||||
ids = [71, 75];
|
||||
for (const id of ids) {
|
||||
const checked = await page.$eval(
|
||||
`#\\3${Math.floor(id / 10)} ${id % 10}R`,
|
||||
el => el.checked
|
||||
);
|
||||
expect(checked).withContext(`In ${browserName}`).toEqual(true);
|
||||
}
|
||||
|
||||
let selected = await page.$eval(
|
||||
`#\\37 8R [value="a"]`,
|
||||
el => el.selected
|
||||
);
|
||||
expect(selected).withContext(`In ${browserName}`).toEqual(true);
|
||||
|
||||
selected = await page.$eval(
|
||||
`#\\38 1R [value="f"]`,
|
||||
el => el.selected
|
||||
);
|
||||
expect(selected).withContext(`In ${browserName}`).toEqual(true);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -385,6 +385,7 @@
|
|||
!IdentityToUnicodeMap_charCodeOf.pdf
|
||||
!PDFJS-9279-reduced.pdf
|
||||
!issue5481.pdf
|
||||
!resetform.pdf
|
||||
!issue5567.pdf
|
||||
!issue5701.pdf
|
||||
!issue6769_no_matrix.pdf
|
||||
|
|
BIN
test/pdfs/resetform.pdf
Normal file
BIN
test/pdfs/resetform.pdf
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue