Skip to content

Commit b5e53db

Browse files
committed
Add playwright test for copy button covering annotation marker
Since the code-copy scaffold moved the copy button out of the pre, the rule that shifted it clear of the annotation gutter no longer matches, so the button sits on top of the marker and swallows its hover. The test checks that the marker is the element under its own center and that the annotation tooltip opens. It fails in chromium, firefox and webkit until the CSS is fixed. Refs #13444
1 parent 0f6912c commit b5e53db

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Code copy button and code annotation marker"
3+
format: html
4+
code-annotations: hover
5+
---
6+
7+
```{.python}
8+
import polars as pl # <1>
9+
```
10+
11+
1. This is a code block with a copy button and an annotation.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect, test } from "@playwright/test";
2+
import { getUrl } from "../src/utils";
3+
4+
// Regression test for #13444. The code copy button sits in the top-right
5+
// corner of the code block, where the annotation gutter shows the marker of
6+
// an annotated first line. The button must stay clear of the gutter so the
7+
// marker can still be hovered to show its annotation.
8+
test("code copy button does not cover the code annotation marker", async ({
9+
page,
10+
}) => {
11+
await page.goto(getUrl("html/code-annotation-copy-button.html"), {
12+
waitUntil: "load",
13+
});
14+
15+
const anchor = page.locator("button.code-annotation-anchor");
16+
await expect(anchor).toHaveCount(1);
17+
const box = await anchor.boundingBox();
18+
expect(box).not.toBeNull();
19+
const x = box!.x + box!.width / 2;
20+
const y = box!.y + box!.height / 2;
21+
22+
// Hovering the code block reveals the copy button, so check the marker is
23+
// still the top-most element at its own center while the button is shown.
24+
await page.mouse.move(x, y);
25+
const hit = await page.evaluate(
26+
([px, py]) =>
27+
document.elementFromPoint(px, py)?.closest(
28+
".code-annotation-anchor, .code-copy-button",
29+
)?.className ?? null,
30+
[x, y],
31+
);
32+
expect(hit).toContain("code-annotation-anchor");
33+
34+
await expect(page.locator(".code-annotation-tip-content")).toBeVisible();
35+
});

0 commit comments

Comments
 (0)