Files
kandev/apps/web/e2e/helpers/markdown-preview.ts
T
José Almeida 12ed7123ab fix: support markdown preview comments (#1648)
* fix: support markdown preview comments

* fix: address markdown preview review feedback

* fix: address markdown preview comment scope

* fix: address markdown preview follow-up feedback

* fix: preserve markdown preview run action in file tabs

* fix: ignore svg clicks in markdown preview controls

* fix: ignore svg markdown preview selection targets
2026-07-10 14:03:32 +01:00

46 lines
1.4 KiB
TypeScript

import type { Locator } from "@playwright/test";
export async function selectMarkdownPreviewText(target: Locator): Promise<void> {
await target.evaluate((element) => {
const range = document.createRange();
range.selectNodeContents(element);
const selection = window.getSelection();
if (!selection) throw new Error("Browser selection is unavailable");
selection.removeAllRanges();
selection.addRange(range);
const rect = element.getBoundingClientRect();
element.dispatchEvent(
new MouseEvent("mouseup", {
bubbles: true,
clientX: rect.left + rect.width / 2,
clientY: rect.bottom,
}),
);
});
}
export async function selectMarkdownPreviewRange(start: Locator, end: Locator): Promise<void> {
await start.evaluate(
(startElement, endElement) => {
const range = document.createRange();
range.setStartBefore(startElement);
range.setEndAfter(endElement);
const selection = window.getSelection();
if (!selection) throw new Error("Browser selection is unavailable");
selection.removeAllRanges();
selection.addRange(range);
const rect = endElement.getBoundingClientRect();
endElement.dispatchEvent(
new MouseEvent("mouseup", {
bubbles: true,
clientX: rect.left + rect.width / 2,
clientY: rect.bottom,
}),
);
},
await end.elementHandle(),
);
}