Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the waitForEvent helper function in the text layer integration tests #18555

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 23 additions & 47 deletions test/integration/text_layer_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/

import {
awaitPromise,
closePages,
closeSinglePage,
getSpanRectFromText,
loadAndWait,
waitForEvent,
} from "./test_utils.mjs";
import { startBrowser } from "../test.mjs";

Expand Down Expand Up @@ -228,34 +228,6 @@ describe("Text layer", () => {
)
);

function waitForClick(page, selector, timeout) {
return page.evaluateHandle(
(sel, timeoutDelay) => {
const element = document.querySelector(sel);
const timeoutSignal = AbortSignal.timeout(timeoutDelay);
return [
new Promise(resolve => {
timeoutSignal.addEventListener(
"abort",
() => resolve(false),
{ once: true }
);
element.addEventListener(
"click",
e => {
e.preventDefault();
resolve(true);
},
{ once: true, signal: timeoutSignal }
);
}),
];
},
selector,
timeout
);
}

it("allows selecting within the link", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
Expand Down Expand Up @@ -315,16 +287,18 @@ describe("Text layer", () => {
await moveInSteps(page, positionStart, positionEnd, 20);
await page.mouse.up();

const clickPromiseHandle = await waitForClick(
await waitForEvent({
page,
"#pdfjs_internal_id_8R",
1000
);

await page.mouse.click(positionEnd.x, positionEnd.y);

const clicked = await awaitPromise(clickPromiseHandle);
expect(clicked).toBeTrue();
eventName: "click",
action: () => page.mouse.click(positionEnd.x, positionEnd.y),
selector: "#pdfjs_internal_id_8R",
validator: e => {
// Don't navigate to the link destination: the `click` event
// firing is enough validation that the link can be clicked.
e.preventDefault();
return true;
},
});
})
);
});
Expand All @@ -348,16 +322,18 @@ describe("Text layer", () => {
await page.keyboard.press("ArrowRight");
await page.keyboard.up("Shift");

const clickPromiseHandle = await waitForClick(
await waitForEvent({
page,
"#pdfjs_internal_id_8R",
1000
);

await page.mouse.click(positionEnd.x, positionEnd.y);

const clicked = await awaitPromise(clickPromiseHandle);
expect(clicked).toBeTrue();
eventName: "click",
action: () => page.mouse.click(positionEnd.x, positionEnd.y),
selector: "#pdfjs_internal_id_8R",
validator: e => {
// Don't navigate to the link destination: the `click` event
// firing is enough validation that the link can be clicked.
e.preventDefault();
return true;
},
});
})
);
});
Expand Down