Skip to content

Commit

Permalink
Add test for mouse selection (previously failing in Chrome)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 17, 2024
1 parent 7962e43 commit a4e6ad9
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/integration/highlight_editor_spec.mjs
Expand Up @@ -1760,4 +1760,64 @@ describe("Highlight Editor", () => {
);
});
});

describe("Text selection", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
`.page[data-page-number = "1"] .endOfContent`
);
});

afterAll(async () => {
await closePages(pages);
});

it("doesn't jump when hovering on an empty area", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const [rectStart, rectEnd] = await Promise.all([
getSpanRectFromText(
page,
1,
"(frequently executed) bytecode sequences, records"
),
getSpanRectFromText(
page,
1,
"them, and compiles them to fast native code. We call such a se-"
),
]);

await page.mouse.move(
rectStart.x + rectStart.width / 2,
rectStart.y + rectStart.height / 2
);
await page.mouse.down();
await page.mouse.move(
rectEnd.x + rectEnd.width,
rectEnd.y + rectEnd.height * 1.5,
{ steps: 10 }
);
await page.mouse.up();

const selectedText = await page.evaluate(() =>
window.getSelection().toString()
);

expect(selectedText)
.withContext(`In ${browserName}`)
.toBe(
browserName === "chrome"
? "code sequences, records\n" +
"them, and compiles them to fast native code. We call such a se-"
: "ecode sequences, records\n" +
"them, and compiles them to fast native code. We call such "
);
})
);
});
});
});

0 comments on commit a4e6ad9

Please sign in to comment.