mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-22 16:05:56 +02:00
Introduce a helper function to draw a line in the ink editor integration tests
This commit extracts the logic to draw a line from one coordinate to another to both remove code duplication (8% of the total number of lines in the file are removed) and clarify the intent of the individual tests.
This commit is contained in:
parent
bdf5005203
commit
71140e7d0f
@ -52,6 +52,15 @@ const commit = async page => {
|
|||||||
|
|
||||||
const switchToInk = switchToEditor.bind(null, "Ink");
|
const switchToInk = switchToEditor.bind(null, "Ink");
|
||||||
|
|
||||||
|
const drawLine = async (page, x0, y0, x1, y1) => {
|
||||||
|
const clickHandle = await waitForPointerUp(page);
|
||||||
|
await page.mouse.move(x0, y0);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(x1, y1);
|
||||||
|
await page.mouse.up();
|
||||||
|
await awaitPromise(clickHandle);
|
||||||
|
};
|
||||||
|
|
||||||
describe("Ink Editor", () => {
|
describe("Ink Editor", () => {
|
||||||
describe("Basic operations", () => {
|
describe("Basic operations", () => {
|
||||||
let pages;
|
let pages;
|
||||||
@ -74,13 +83,7 @@ describe("Ink Editor", () => {
|
|||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
const x = rect.x + 100 + i * 100;
|
const x = rect.x + 100 + i * 100;
|
||||||
const y = rect.y + 100 + i * 100;
|
const y = rect.y + 100 + i * 100;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,15 +110,9 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const rectBefore = await getRect(page, ".canvasWrapper .draw");
|
const rectBefore = await getRect(page, ".canvasWrapper .draw");
|
||||||
@ -149,13 +146,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 100;
|
const x = rect.x + 100;
|
||||||
const y = rect.y + 100;
|
const y = rect.y + 100;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -205,13 +196,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await selectAll(page);
|
await selectAll(page);
|
||||||
@ -244,13 +229,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const oneToFourteen = Array.from(new Array(13).keys(), n => n + 2);
|
const oneToFourteen = Array.from(new Array(13).keys(), n => n + 2);
|
||||||
@ -299,12 +278,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await page.mouse.click(rect.x - 10, rect.y + 10);
|
await page.mouse.click(rect.x - 10, rect.y + 10);
|
||||||
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
|
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
|
||||||
@ -331,14 +305,9 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -375,14 +344,9 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -432,14 +396,9 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -483,16 +442,11 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
let xStart = rect.x + 10;
|
let x = rect.x + 10;
|
||||||
const yStart = rect.y + 10;
|
const y = rect.y + 10;
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
x += 70;
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
xStart += 70;
|
|
||||||
}
|
}
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
@ -561,13 +515,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const drawSelector = `.page[data-page-number = "1"] .canvasWrapper .draw`;
|
const drawSelector = `.page[data-page-number = "1"] .canvasWrapper .draw`;
|
||||||
@ -636,12 +584,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
const drawSelector = `.canvasWrapper svg.draw path[d]:not([d=""])`;
|
const drawSelector = `.canvasWrapper svg.draw path[d]:not([d=""])`;
|
||||||
await page.waitForSelector(drawSelector);
|
await page.waitForSelector(drawSelector);
|
||||||
@ -680,12 +623,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.focusedIds = [];
|
window.focusedIds = [];
|
||||||
@ -884,14 +822,9 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await page.waitForSelector(editorSelector);
|
await page.waitForSelector(editorSelector);
|
||||||
@ -918,14 +851,9 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await page.waitForSelector(editorSelector);
|
await page.waitForSelector(editorSelector);
|
||||||
@ -957,14 +885,9 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
const rect = await getRect(page, ".annotationEditorLayer");
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
const xStart = rect.x + 300;
|
const x = rect.x + 300;
|
||||||
const yStart = rect.y + 300;
|
const y = rect.y + 300;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 50, yStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await page.waitForSelector(editorSelector);
|
await page.waitForSelector(editorSelector);
|
||||||
@ -976,14 +899,9 @@ describe("Ink Editor", () => {
|
|||||||
await page.waitForSelector("#editorUndoBar", { visible: true });
|
await page.waitForSelector("#editorUndoBar", { visible: true });
|
||||||
|
|
||||||
const newRect = await getRect(page, ".annotationEditorLayer");
|
const newRect = await getRect(page, ".annotationEditorLayer");
|
||||||
const newXStart = newRect.x + 300;
|
const newX = newRect.x + 300;
|
||||||
const newYStart = newRect.y + 300;
|
const newY = newRect.y + 300;
|
||||||
const newClickHandle = await waitForPointerUp(page);
|
await drawLine(page, newX, newY, newX + 50, newY + 50);
|
||||||
await page.mouse.move(newXStart, newYStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(newXStart + 50, newYStart + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(newClickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await page.waitForSelector(getEditorSelector(1));
|
await page.waitForSelector(getEditorSelector(1));
|
||||||
@ -1014,12 +932,7 @@ describe("Ink Editor", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
|
|
||||||
const svgSelector = ".canvasWrapper svg.draw";
|
const svgSelector = ".canvasWrapper svg.draw";
|
||||||
const strokeWidth = await page.$eval(svgSelector, el =>
|
const strokeWidth = await page.$eval(svgSelector, el =>
|
||||||
@ -1082,14 +995,9 @@ describe("Ink Editor", () => {
|
|||||||
page,
|
page,
|
||||||
`${pageSelector} .annotationEditorLayer`
|
`${pageSelector} .annotationEditorLayer`
|
||||||
);
|
);
|
||||||
const xStart = rect.x + 10;
|
const x = rect.x + 10;
|
||||||
const yStart = rect.y + 10;
|
const y = rect.y + 10;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 10, y + 10);
|
||||||
await page.mouse.move(xStart, yStart);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(xStart + 10, yStart + 10);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1148,15 +1056,10 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
const editorLayerRect = await getRect(page, ".annotationEditorLayer");
|
const editorLayerRect = await getRect(page, ".annotationEditorLayer");
|
||||||
const drawStartX = editorLayerRect.x + 100;
|
|
||||||
const drawStartY = editorLayerRect.y + 100;
|
|
||||||
|
|
||||||
const clickHandle = await waitForPointerUp(page);
|
const x = editorLayerRect.x + 100;
|
||||||
await page.mouse.move(drawStartX, drawStartY);
|
const y = editorLayerRect.y + 100;
|
||||||
await page.mouse.down();
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(drawStartX + 50, drawStartY + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const pageFinalPosition = await getRect(
|
const pageFinalPosition = await getRect(
|
||||||
@ -1257,16 +1160,10 @@ describe("Should switch from an editor and mode to others by double clicking", (
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
const editorLayerRect = await getRect(page, ".annotationEditorLayer");
|
const editorLayerRect = await getRect(page, ".annotationEditorLayer");
|
||||||
const drawStartX = editorLayerRect.x + 100;
|
|
||||||
const drawStartY = editorLayerRect.y + 100;
|
|
||||||
|
|
||||||
const inkSelector = getEditorSelector(0);
|
const x = editorLayerRect.x + 100;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
const y = editorLayerRect.y + 100;
|
||||||
await page.mouse.move(drawStartX, drawStartY);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(drawStartX + 50, drawStartY + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
await switchToEditor("FreeText", page);
|
await switchToEditor("FreeText", page);
|
||||||
@ -1286,6 +1183,7 @@ describe("Should switch from an editor and mode to others by double clicking", (
|
|||||||
|
|
||||||
await page.waitForSelector("#editorInkButton:not(.toggled)");
|
await page.waitForSelector("#editorInkButton:not(.toggled)");
|
||||||
let modeChangedHandle = await waitForAnnotationModeChanged(page);
|
let modeChangedHandle = await waitForAnnotationModeChanged(page);
|
||||||
|
const inkSelector = getEditorSelector(0);
|
||||||
await selectEditor(page, inkSelector, 2);
|
await selectEditor(page, inkSelector, 2);
|
||||||
await awaitPromise(modeChangedHandle);
|
await awaitPromise(modeChangedHandle);
|
||||||
await page.waitForSelector("#editorInkButton.toggled");
|
await page.waitForSelector("#editorInkButton.toggled");
|
||||||
@ -1322,12 +1220,7 @@ describe("Ink must update its color", () => {
|
|||||||
|
|
||||||
const x = rect.x + 20;
|
const x = rect.x + 20;
|
||||||
const y = rect.y + 20;
|
const y = rect.y + 20;
|
||||||
const clickHandle = await waitForPointerUp(page);
|
await drawLine(page, x, y, x + 50, y + 50);
|
||||||
await page.mouse.move(x, y);
|
|
||||||
await page.mouse.down();
|
|
||||||
await page.mouse.move(x + 50, y + 50);
|
|
||||||
await page.mouse.up();
|
|
||||||
await awaitPromise(clickHandle);
|
|
||||||
await commit(page);
|
await commit(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user