Fix keyboard shortcuts on mac and for some tests make sure that all
the page is displayed in using page-fit in order to make all tested elements visible.
This commit is contained in:
parent
34781121cd
commit
517a262fb1
@ -15,6 +15,8 @@
|
||||
|
||||
import {
|
||||
closePages,
|
||||
kbCopy,
|
||||
kbSelectAll,
|
||||
loadAndWait,
|
||||
mockClipboard,
|
||||
waitForEvent,
|
||||
@ -23,9 +25,7 @@ import {
|
||||
|
||||
const selectAll = async page => {
|
||||
const promise = waitForEvent(page, "selectionchange");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await promise;
|
||||
|
||||
await page.waitForFunction(() => {
|
||||
@ -64,9 +64,7 @@ describe("Copy and paste", () => {
|
||||
await selectAll(page);
|
||||
|
||||
const promise = waitForEvent(page, "copy");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
await kbCopy(page);
|
||||
await promise;
|
||||
|
||||
await page.waitForFunction(
|
||||
@ -173,9 +171,7 @@ describe("Copy and paste", () => {
|
||||
await selectAll(page);
|
||||
|
||||
const promise = waitForEvent(page, "copy");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
await kbCopy(page);
|
||||
await promise;
|
||||
|
||||
await page.waitForFunction(
|
||||
|
@ -21,6 +21,20 @@ import {
|
||||
getFirstSerialized,
|
||||
getSelectedEditors,
|
||||
getSerialized,
|
||||
hover,
|
||||
kbBigMoveDown,
|
||||
kbBigMoveLeft,
|
||||
kbBigMoveRight,
|
||||
kbBigMoveUp,
|
||||
kbCopy,
|
||||
kbGoToBegin,
|
||||
kbGoToEnd,
|
||||
kbModifierDown,
|
||||
kbModifierUp,
|
||||
kbPaste,
|
||||
kbRedo,
|
||||
kbSelectAll,
|
||||
kbUndo,
|
||||
loadAndWait,
|
||||
scrollIntoView,
|
||||
waitForEvent,
|
||||
@ -33,24 +47,18 @@ import { PNG } from "pngjs";
|
||||
|
||||
const copyPaste = async page => {
|
||||
let promise = waitForEvent(page, "copy");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
await kbCopy(page);
|
||||
await promise;
|
||||
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
promise = waitForEvent(page, "paste");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await kbPaste(page);
|
||||
await promise;
|
||||
};
|
||||
|
||||
const selectAll = async page => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.waitForFunction(
|
||||
() => !document.querySelector(".freeTextEditor:not(.selectedEditor)")
|
||||
);
|
||||
@ -264,9 +272,7 @@ describe("FreeText Editor", () => {
|
||||
visible: true,
|
||||
});
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await page.waitForFunction(
|
||||
sel => !document.querySelector(sel),
|
||||
{},
|
||||
@ -275,17 +281,13 @@ describe("FreeText Editor", () => {
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const promise = waitForEvent(page, "paste");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await kbPaste(page);
|
||||
await promise;
|
||||
await page.waitForSelector(getEditorSelector(5 + i));
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await page.waitForFunction(
|
||||
sel => !document.querySelector(sel),
|
||||
{},
|
||||
@ -473,26 +475,20 @@ describe("FreeText Editor", () => {
|
||||
page.$eval(`${getEditorSelector(9)} .internal`, el => el.innerText);
|
||||
|
||||
// We're in the middle of the text.
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForTextChange(prevText);
|
||||
|
||||
let text = (prevText = await getText());
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("AAAA");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForTextChange(prevText);
|
||||
|
||||
text = prevText = await getText();
|
||||
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("AAA");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("y");
|
||||
await page.keyboard.up("Control");
|
||||
await kbRedo(page);
|
||||
await waitForTextChange(prevText);
|
||||
|
||||
text = prevText = await getText();
|
||||
@ -500,9 +496,7 @@ describe("FreeText Editor", () => {
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("AAAA");
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
if (i < 3) {
|
||||
await waitForTextChange(prevText);
|
||||
prevText = await getText();
|
||||
@ -513,9 +507,7 @@ describe("FreeText Editor", () => {
|
||||
() => !document.querySelector(".selectedEditor")
|
||||
);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("y");
|
||||
await page.keyboard.up("Control");
|
||||
await kbRedo(page);
|
||||
await page.waitForSelector(getEditorSelector(9), {
|
||||
visible: true,
|
||||
});
|
||||
@ -570,16 +562,16 @@ describe("FreeText Editor", () => {
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
// With Chrome something is wrong when serializing a DomRect,
|
||||
// hence we extract the values and just return them.
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
return { x, y };
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
});
|
||||
|
||||
const editorCenters = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const data = `FreeText ${i}`;
|
||||
await page.mouse.click(
|
||||
rect.x + (i + 1) * 100,
|
||||
rect.y + (i + 1) * 100
|
||||
rect.x + ((i + 1) * rect.width) / 10,
|
||||
rect.y + ((i + 1) * rect.height) / 10
|
||||
);
|
||||
await page.waitForSelector(getEditorSelector(i), {
|
||||
visible: true,
|
||||
@ -617,7 +609,7 @@ describe("FreeText Editor", () => {
|
||||
.toEqual([0, 1, 2, 3]);
|
||||
|
||||
// Unselect the editor.
|
||||
await page.keyboard.down("Control");
|
||||
await kbModifierDown(page);
|
||||
await page.mouse.click(editorCenters[1].x, editorCenters[1].y);
|
||||
await waitForUnselectedEditor(page, getEditorSelector(1));
|
||||
|
||||
@ -633,7 +625,7 @@ describe("FreeText Editor", () => {
|
||||
.toEqual([0, 3]);
|
||||
|
||||
await page.mouse.click(editorCenters[1].x, editorCenters[1].y);
|
||||
await page.keyboard.up("Control");
|
||||
await kbModifierUp(page);
|
||||
await waitForSelectedEditor(page, getEditorSelector(1));
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
@ -663,7 +655,7 @@ describe("FreeText Editor", () => {
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([1]);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await kbModifierDown(page);
|
||||
|
||||
await page.mouse.click(editorCenters[3].x, editorCenters[3].y);
|
||||
await waitForSelectedEditor(page, getEditorSelector(3));
|
||||
@ -671,7 +663,7 @@ describe("FreeText Editor", () => {
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([1, 3]);
|
||||
|
||||
await page.keyboard.up("Control");
|
||||
await kbModifierUp(page);
|
||||
|
||||
// Delete 1 and 3.
|
||||
await page.keyboard.press("Backspace");
|
||||
@ -688,7 +680,10 @@ describe("FreeText Editor", () => {
|
||||
.toEqual([0, 2, 4, 5, 6]);
|
||||
|
||||
// Create an empty editor.
|
||||
await page.mouse.click(rect.x + 700, rect.y + 100);
|
||||
await page.mouse.click(
|
||||
rect.x + (rect.width / 10) * 7,
|
||||
rect.y + rect.height / 10
|
||||
);
|
||||
await page.waitForSelector(getEditorSelector(7), {
|
||||
visible: true,
|
||||
});
|
||||
@ -704,7 +699,10 @@ describe("FreeText Editor", () => {
|
||||
.toEqual([2]);
|
||||
|
||||
// Create an empty editor.
|
||||
await page.mouse.click(rect.x + 700, rect.y + 100);
|
||||
await page.mouse.click(
|
||||
rect.x + (rect.width / 10) * 8,
|
||||
rect.y + rect.height / 10
|
||||
);
|
||||
await page.waitForSelector(getEditorSelector(8), {
|
||||
visible: true,
|
||||
});
|
||||
@ -1057,9 +1055,7 @@ describe("FreeText Editor", () => {
|
||||
`${getEditorSelector(0)} .overlay:not(.enabled)`
|
||||
);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.up("Control");
|
||||
await kbGoToEnd(page);
|
||||
await page.waitForFunction(
|
||||
sel =>
|
||||
document.getSelection().anchorOffset ===
|
||||
@ -1113,19 +1109,14 @@ describe("FreeText Editor", () => {
|
||||
await switchToFreeText(page);
|
||||
await page.focus(".annotationEditorLayer");
|
||||
|
||||
// Undo.
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForSerialized(page, 0);
|
||||
|
||||
editorIds = await getEditors(page, "freeText");
|
||||
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(6);
|
||||
|
||||
// Undo again.
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
// Nothing should happen, it's why we can't wait for something
|
||||
// specific!
|
||||
await page.waitForTimeout(200);
|
||||
@ -1224,10 +1215,7 @@ describe("FreeText Editor", () => {
|
||||
await switchToFreeText(page);
|
||||
await page.focus(".annotationEditorLayer");
|
||||
|
||||
// Undo.
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForSerialized(page, 0);
|
||||
})
|
||||
);
|
||||
@ -1322,7 +1310,11 @@ describe("FreeText Editor", () => {
|
||||
it("must not remove an empty annotation", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.hover("[data-annotation-id='23R']");
|
||||
await page.waitForSelector("[data-annotation-id='23R']");
|
||||
// Cannot use page.hover with Firefox on Mac because of a bug.
|
||||
// TODO: remove this when we switch to BiDi.
|
||||
await hover(page, "[data-annotation-id='23R']");
|
||||
|
||||
// Wait for the popup to be displayed.
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
@ -1341,7 +1333,8 @@ describe("FreeText Editor", () => {
|
||||
`.annotationEditorLayer:not(.freetextEditing)`
|
||||
);
|
||||
|
||||
await page.hover("[data-annotation-id='23R']");
|
||||
// TODO: remove this when we switch to BiDi.
|
||||
await hover(page, "[data-annotation-id='23R']");
|
||||
// Wait for the popup to be displayed.
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
@ -1592,11 +1585,7 @@ describe("FreeText Editor", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait(
|
||||
"issue16633.pdf",
|
||||
".annotationEditorLayer",
|
||||
100
|
||||
);
|
||||
pages = await loadAndWait("issue16633.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@ -1944,10 +1933,7 @@ describe("FreeText Editor", () => {
|
||||
);
|
||||
|
||||
await page.focus("#editorFreeTextColor");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
|
||||
await page.waitForFunction(
|
||||
sel => !document.querySelector(sel),
|
||||
@ -1955,9 +1941,7 @@ describe("FreeText Editor", () => {
|
||||
getEditorSelector(0)
|
||||
);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("y");
|
||||
await page.keyboard.up("Control");
|
||||
await kbRedo(page);
|
||||
await page.waitForFunction(
|
||||
sel => !!document.querySelector(sel),
|
||||
{},
|
||||
@ -2046,9 +2030,7 @@ describe("FreeText Editor", () => {
|
||||
.toEqual(Math.round(pageY - 20));
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveLeft(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2062,9 +2044,7 @@ describe("FreeText Editor", () => {
|
||||
.toEqual(Math.round(pageY - 20));
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveUp(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2164,9 +2144,7 @@ describe("FreeText Editor", () => {
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveDown(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2178,25 +2156,19 @@ describe("FreeText Editor", () => {
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveUp(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveRight(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveLeft(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2342,7 +2314,7 @@ describe("FreeText Editor", () => {
|
||||
`${getEditorSelector(1)} .overlay.enabled`
|
||||
);
|
||||
|
||||
await page.mouse.click(rect.x + 115, rect.y + 155);
|
||||
await page.mouse.click(rect.x + 111, rect.y + 151);
|
||||
await waitForSelectedEditor(page, getEditorSelector(1));
|
||||
|
||||
const pos = n =>
|
||||
@ -2361,12 +2333,21 @@ describe("FreeText Editor", () => {
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(1);
|
||||
|
||||
const getY = selector =>
|
||||
page.evaluate(
|
||||
sel => document.querySelector(sel).getBoundingClientRect().y,
|
||||
selector
|
||||
);
|
||||
const height = await page.evaluate(
|
||||
sel => document.querySelector(sel).getBoundingClientRect().height,
|
||||
getEditorSelector(0)
|
||||
);
|
||||
|
||||
const y0 = await getY(getEditorSelector(0));
|
||||
const selectorEditor = getEditorSelector(1);
|
||||
let xy = await getXY(page, selectorEditor);
|
||||
for (let i = 0; i < 6; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
while ((await getY(selectorEditor)) > y0 - height) {
|
||||
await kbBigMoveUp(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2448,12 +2429,12 @@ describe("FreeText Editor", () => {
|
||||
return { x, y };
|
||||
});
|
||||
const oldPos = allPositions[i];
|
||||
expect(Math.round(pos.x - oldPos.x))
|
||||
expect(Math.abs(Math.round(pos.x - oldPos.x) - 39))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(39);
|
||||
expect(Math.round(pos.y - oldPos.y))
|
||||
.toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(Math.round(pos.y - oldPos.y) - 74))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(74);
|
||||
.toBeLessThanOrEqual(1);
|
||||
}
|
||||
})
|
||||
);
|
||||
@ -2505,6 +2486,7 @@ describe("FreeText Editor", () => {
|
||||
visible: true,
|
||||
});
|
||||
await page.type(`${getEditorSelector(0)} .internal`, data);
|
||||
|
||||
// Commit.
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForSelector(
|
||||
@ -2669,7 +2651,7 @@ describe("FreeText Editor", () => {
|
||||
);
|
||||
|
||||
// Go to the last page.
|
||||
await page.keyboard.press("End");
|
||||
await kbGoToEnd(page);
|
||||
await page.waitForSelector(
|
||||
`.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`,
|
||||
{
|
||||
@ -2681,7 +2663,7 @@ describe("FreeText Editor", () => {
|
||||
await clearAll(page);
|
||||
|
||||
// Go to the first page.
|
||||
await page.keyboard.press("Home");
|
||||
await kbGoToBegin(page);
|
||||
await page.waitForSelector(page1Selector, {
|
||||
visible: true,
|
||||
timeout: 0,
|
||||
@ -2690,10 +2672,7 @@ describe("FreeText Editor", () => {
|
||||
// Make sure that nothing has be added.
|
||||
await waitForStorageEntries(page, 0);
|
||||
|
||||
// Undo.
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForSerialized(page, 1);
|
||||
|
||||
await page.waitForSelector(getEditorSelector(0), {
|
||||
@ -2832,9 +2811,7 @@ describe("FreeText Editor", () => {
|
||||
|
||||
let xy = await getXY(page, selectorEditor);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveUp(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2867,9 +2844,7 @@ describe("FreeText Editor", () => {
|
||||
|
||||
xy = await getXY(page, selectorEditor);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveDown(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2904,9 +2879,7 @@ describe("FreeText Editor", () => {
|
||||
|
||||
let xy = await getXY(page, selectorEditor);
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveLeft(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
@ -2936,9 +2909,7 @@ describe("FreeText Editor", () => {
|
||||
|
||||
xy = await getXY(page, selectorEditor);
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveRight(page);
|
||||
await waitForPositionChange(page, selectorEditor, xy);
|
||||
xy = await getXY(page, selectorEditor);
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
import {
|
||||
closePages,
|
||||
getSelectedEditors,
|
||||
kbRedo,
|
||||
kbSelectAll,
|
||||
kbUndo,
|
||||
loadAndWait,
|
||||
waitForStorageEntries,
|
||||
} from "./test_utils.mjs";
|
||||
@ -29,9 +32,7 @@ const waitForPointerUp = page =>
|
||||
);
|
||||
|
||||
const selectAll = async page => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.waitForFunction(
|
||||
() => !document.querySelector(".inkEditor.disabled:not(.selectedEditor)")
|
||||
);
|
||||
@ -39,9 +40,7 @@ const selectAll = async page => {
|
||||
|
||||
const clearAll = async page => {
|
||||
await selectAll(page);
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Control");
|
||||
await waitForStorageEntries(page, 0);
|
||||
};
|
||||
|
||||
@ -89,9 +88,7 @@ describe("Ink Editor", () => {
|
||||
|
||||
await clearAll(page);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await kbUndo(page);
|
||||
await waitForStorageEntries(page, 3);
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
@ -130,16 +127,9 @@ describe("Ink Editor", () => {
|
||||
});
|
||||
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await kbUndo(page);
|
||||
await waitForStorageEntries(page, 0);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("y");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await kbRedo(page);
|
||||
await waitForStorageEntries(page, 1);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ import {
|
||||
getFirstSerialized,
|
||||
getQuerySelector,
|
||||
getSelector,
|
||||
kbDeleteLastWord,
|
||||
kbSelectAll,
|
||||
loadAndWait,
|
||||
scrollIntoView,
|
||||
} from "./test_utils.mjs";
|
||||
@ -1228,9 +1230,7 @@ describe("Interaction", () => {
|
||||
|
||||
await page.type(getSelector("27R"), " ", { delay: 200 });
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Control");
|
||||
await kbDeleteLastWord(page);
|
||||
|
||||
await page.waitForFunction(
|
||||
`${getQuerySelector("27R")}.value !== "HELLO WORDL "`
|
||||
@ -1654,9 +1654,7 @@ describe("Interaction", () => {
|
||||
value = await page.$eval(getSelector("28R"), el => el.value);
|
||||
expect(value).withContext(`In ${browserName}`).toEqual("abcdef");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("A");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.keyboard.press("Backspace");
|
||||
|
||||
await page.keyboard.press("Enter");
|
||||
@ -1962,9 +1960,7 @@ describe("Interaction", () => {
|
||||
await page.waitForTimeout(10);
|
||||
await page.click(getSelector("26R"));
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("A");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.keyboard.press("Backspace");
|
||||
|
||||
await page.click(getSelector("23R"));
|
||||
|
@ -18,6 +18,10 @@ import {
|
||||
getEditorDimensions,
|
||||
getEditorSelector,
|
||||
getFirstSerialized,
|
||||
kbBigMoveDown,
|
||||
kbBigMoveRight,
|
||||
kbPaste,
|
||||
kbSelectAll,
|
||||
loadAndWait,
|
||||
serializeBitmapDimensions,
|
||||
waitForAnnotationEditorLayer,
|
||||
@ -31,9 +35,7 @@ import path from "path";
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const selectAll = async page => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.waitForFunction(
|
||||
() => !document.querySelector(".stampEditor:not(.selectedEditor)")
|
||||
);
|
||||
@ -41,9 +43,7 @@ const selectAll = async page => {
|
||||
|
||||
const clearAll = async page => {
|
||||
await selectAll(page);
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Control");
|
||||
await waitForStorageEntries(page, 0);
|
||||
};
|
||||
|
||||
@ -101,9 +101,7 @@ const copyImage = async (page, imagePath, number) => {
|
||||
})
|
||||
),
|
||||
]);
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await kbPaste(page);
|
||||
hasPasteEvent = await promise;
|
||||
}
|
||||
|
||||
@ -521,9 +519,7 @@ describe("Stamp Editor", () => {
|
||||
.toEqual(true);
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveRight(page);
|
||||
await waitForDimsChange(prevWidth, prevHeight);
|
||||
[prevWidth, prevHeight] = await getDims();
|
||||
}
|
||||
@ -554,9 +550,7 @@ describe("Stamp Editor", () => {
|
||||
.toEqual(true);
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.up("Control");
|
||||
await kbBigMoveDown(page);
|
||||
await waitForDimsChange(prevWidth, prevHeight);
|
||||
[prevWidth, prevHeight] = await getDims();
|
||||
}
|
||||
|
@ -13,6 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import os from "os";
|
||||
const isMac = os.platform() === "darwin";
|
||||
|
||||
function loadAndWait(filename, selector, zoom, pageSetup) {
|
||||
return Promise.all(
|
||||
global.integrationSessions.map(async session => {
|
||||
@ -33,10 +36,10 @@ function loadAndWait(filename, selector, zoom, pageSetup) {
|
||||
});
|
||||
});
|
||||
|
||||
let url = `${global.integrationBaseUrl}?file=/test/pdfs/${filename}`;
|
||||
if (zoom) {
|
||||
url += `#zoom=${zoom}`;
|
||||
}
|
||||
const url = `${
|
||||
global.integrationBaseUrl
|
||||
}?file=/test/pdfs/${filename}#zoom=${zoom ?? "page-fit"}`;
|
||||
|
||||
await page.goto(url);
|
||||
if (pageSetup) {
|
||||
await pageSetup(page);
|
||||
@ -63,9 +66,7 @@ function closePages(pages) {
|
||||
|
||||
async function clearInput(page, selector) {
|
||||
await page.click(selector);
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("A");
|
||||
await page.keyboard.up("Control");
|
||||
await kbSelectAll(page);
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.waitForTimeout(10);
|
||||
}
|
||||
@ -285,6 +286,137 @@ async function scrollIntoView(page, selector) {
|
||||
);
|
||||
}
|
||||
|
||||
async function hover(page, selector) {
|
||||
const rect = await page.$eval(selector, el => {
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
});
|
||||
await page.mouse.move(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
||||
}
|
||||
|
||||
const modifier = isMac ? "Meta" : "Control";
|
||||
async function kbCopy(page) {
|
||||
await page.keyboard.down(modifier);
|
||||
await page.keyboard.press("c", { commands: ["Copy"] });
|
||||
await page.keyboard.up(modifier);
|
||||
}
|
||||
async function kbPaste(page) {
|
||||
await page.keyboard.down(modifier);
|
||||
await page.keyboard.press("v", { commands: ["Paste"] });
|
||||
await page.keyboard.up(modifier);
|
||||
}
|
||||
async function kbUndo(page) {
|
||||
await page.keyboard.down(modifier);
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up(modifier);
|
||||
}
|
||||
async function kbRedo(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Meta");
|
||||
await page.keyboard.down("Shift");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Shift");
|
||||
await page.keyboard.up("Meta");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("y");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbSelectAll(page) {
|
||||
await page.keyboard.down(modifier);
|
||||
await page.keyboard.press("a", { commands: ["SelectAll"] });
|
||||
await page.keyboard.up(modifier);
|
||||
}
|
||||
async function kbModifierDown(page) {
|
||||
await page.keyboard.down(modifier);
|
||||
}
|
||||
async function kbModifierUp(page) {
|
||||
await page.keyboard.up(modifier);
|
||||
}
|
||||
async function kbGoToEnd(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Meta");
|
||||
await page.keyboard.press("ArrowDown", {
|
||||
commands: ["MoveToEndOfDocument"],
|
||||
});
|
||||
await page.keyboard.up("Meta");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbGoToBegin(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Meta");
|
||||
await page.keyboard.press("ArrowUp", {
|
||||
commands: ["MoveToBeginningOfDocument"],
|
||||
});
|
||||
await page.keyboard.up("Meta");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbBigMoveLeft(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Shift");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.up("Shift");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbBigMoveRight(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Shift");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.up("Shift");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbBigMoveUp(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Shift");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Shift");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
async function kbBigMoveDown(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Shift");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.up("Shift");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
|
||||
async function kbDeleteLastWord(page) {
|
||||
if (isMac) {
|
||||
await page.keyboard.down("Alt");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Alt");
|
||||
} else {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Control");
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
clearInput,
|
||||
closePages,
|
||||
@ -298,6 +430,21 @@ export {
|
||||
getSelectedEditors,
|
||||
getSelector,
|
||||
getSerialized,
|
||||
hover,
|
||||
kbBigMoveDown,
|
||||
kbBigMoveLeft,
|
||||
kbBigMoveRight,
|
||||
kbBigMoveUp,
|
||||
kbCopy,
|
||||
kbDeleteLastWord,
|
||||
kbGoToBegin,
|
||||
kbGoToEnd,
|
||||
kbModifierDown,
|
||||
kbModifierUp,
|
||||
kbPaste,
|
||||
kbRedo,
|
||||
kbSelectAll,
|
||||
kbUndo,
|
||||
loadAndWait,
|
||||
mockClipboard,
|
||||
scrollIntoView,
|
||||
|
Loading…
Reference in New Issue
Block a user