Skip to content

Commit

Permalink
Introduce a getRect utility function for the integration tests
Browse files Browse the repository at this point in the history
Over time the number of integration tests that get the rectangle for a
given selector has increased quite a bit, and the code to do so has
consequently become duplicated.

This commit refactors the integration tests to move the rectangle
fetching code to a single place, which reduces the code by over 400
lines and makes the individual tests simpler.
  • Loading branch information
timvandermeij committed May 23, 2024
1 parent 0c562f0 commit 145d660
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 467 deletions.
13 changes: 5 additions & 8 deletions test/integration/caret_browsing_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { closePages, loadAndWait } from "./test_utils.mjs";
import { closePages, getRect, loadAndWait } from "./test_utils.mjs";

const waitForSelectionChange = (page, selection) =>
page.waitForFunction(
Expand All @@ -38,13 +38,10 @@ describe("Caret browsing", () => {
it("must move the caret down and check the selection", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const spanRect = await page.evaluate(() => {
const span = document.querySelector(
`.page[data-page-number="1"] > .textLayer > span`
);
const { x, y, width, height } = span.getBoundingClientRect();
return { x, y, width, height };
});
const spanRect = await getRect(
page,
`.page[data-page-number="1"] > .textLayer > span`
);
await page.mouse.click(
spanRect.x + 1,
spanRect.y + spanRect.height / 2,
Expand Down
Loading

0 comments on commit 145d660

Please sign in to comment.