1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 23:58:07 +02:00

JS -- Send events to the sandbox from annotation layer

This commit is contained in:
Calixte Denizet 2020-11-18 14:59:57 +01:00
parent 640a08444c
commit 6502ae889d
11 changed files with 647 additions and 113 deletions

View file

@ -27,6 +27,44 @@ describe("Interaction", () => {
await closePages(pages);
});
it("must show a text field and then make in invisible when content is removed", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
let visibility = await page.$eval(
"#\\34 27R",
el => getComputedStyle(el).visibility
);
expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
await page.type("#\\34 16R", "3.14159", { delay: 200 });
await page.click("#\\34 19R");
visibility = await page.$eval(
"#\\34 27R",
el => getComputedStyle(el).visibility
);
expect(visibility)
.withContext(`In ${browserName}`)
.toEqual("visible");
// Clear the textfield
await page.click("#\\34 16R");
await page.keyboard.down("Control");
await page.keyboard.press("A");
await page.keyboard.up("Control");
await page.keyboard.press("Backspace");
// and leave it
await page.click("#\\34 19R");
visibility = await page.$eval(
"#\\34 27R",
el => getComputedStyle(el).visibility
);
expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
})
);
});
it("must format the field with 2 digits and leave field with a click", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
@ -34,6 +72,35 @@ describe("Interaction", () => {
await page.click("#\\34 19R");
const text = await page.$eval("#\\34 16R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("3,14");
const sum = await page.$eval("#\\34 27R", el => el.value);
expect(sum).withContext(`In ${browserName}`).toEqual("3,14");
})
);
});
it("must format the field with 2 digits, leave field with a click and again", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.type("#\\34 48R", "61803", { delay: 200 });
await page.click("#\\34 19R");
let text = await page.$eval("#\\34 48R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("61.803,00");
await page.click("#\\34 48R");
text = await page.$eval("#\\34 48R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("61803");
// Clear the textfield
await page.keyboard.down("Control");
await page.keyboard.press("A");
await page.keyboard.up("Control");
await page.keyboard.press("Backspace");
await page.type("#\\34 48R", "1.61803", { delay: 200 });
await page.click("#\\34 19R");
text = await page.$eval("#\\34 48R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("1,62");
})
);
});
@ -45,6 +112,67 @@ describe("Interaction", () => {
await page.keyboard.press("Tab");
const text = await page.$eval("#\\34 22R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("2,72");
const sum = await page.$eval("#\\34 27R", el => el.value);
expect(sum).withContext(`In ${browserName}`).toEqual("5,86");
})
);
});
it("must format the field with 2 digits and hit ESC", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
let sum = await page.$eval("#\\34 71R", el => el.value);
expect(sum).withContext(`In ${browserName}`).toEqual("4,24");
await page.type("#\\34 36R", "0.69314", { delay: 200 });
await page.keyboard.press("Escape");
const text = await page.$eval("#\\34 36R", el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("0.69314");
sum = await page.$eval("#\\34 71R", el => el.value);
expect(sum).withContext(`In ${browserName}`).toEqual("3,55");
})
);
});
it("must format the field with 2 digits on key ENTER", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.type("#\\34 19R", "0.577215", { delay: 200 });
await page.keyboard.press("Enter");
const text = await page.$eval("#\\34 19R", el => el.value);
expect(text).toEqual("0.577215");
const sum = await page.$eval("#\\34 27R", el => el.value);
expect(sum).toEqual("6,44");
})
);
});
it("must reset all", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
// this field has no actions but it must be cleared on reset
await page.type("#\\34 05R", "employee", { delay: 200 });
// click on reset button
await page.click("[data-annotation-id='402R']");
let text = await page.$eval("#\\34 16R", el => el.value);
expect(text).toEqual("");
text = await page.$eval("#\\34 22R", el => el.value);
expect(text).toEqual("");
text = await page.$eval("#\\34 19R", el => el.value);
expect(text).toEqual("");
text = await page.$eval("#\\34 05R", el => el.value);
expect(text).toEqual("");
const sum = await page.$eval("#\\34 27R", el => el.value);
expect(sum).toEqual("");
})
);
});

View file

@ -84,7 +84,7 @@ describe("Scripting", function () {
return s;
}
const number = 123;
const expected = ((number - 1) * number) / 2;
const expected = (((number - 1) * number) / 2).toString();
const refId = getId();
const data = {
@ -1094,7 +1094,7 @@ describe("Scripting", function () {
expect(send_queue.get(refIds[3])).toEqual({
id: refIds[3],
value: 1,
valueAsString: 1,
valueAsString: "1",
});
await sandbox.dispatchEventInSandbox({
@ -1107,7 +1107,7 @@ describe("Scripting", function () {
expect(send_queue.get(refIds[3])).toEqual({
id: refIds[3],
value: 3,
valueAsString: 3,
valueAsString: "3",
});
await sandbox.dispatchEventInSandbox({
@ -1120,7 +1120,7 @@ describe("Scripting", function () {
expect(send_queue.get(refIds[3])).toEqual({
id: refIds[3],
value: 6,
valueAsString: 6,
valueAsString: "6",
});
done();