ohif-viewer/tests/utils/simulateClicksOnElement.ts
Joe Boccanfuso 24e0263fb9
chore: recovery 2 (#5014) merge to 3.11 (#5175)
Co-authored-by: Alireza <ar.sedghi@gmail.com>
Co-authored-by: Dan Rukas <dan.rukas@gmail.com>
Co-authored-by: Tang Cheng <45505657+tctco@users.noreply.github.com>
2025-07-03 14:08:46 -04:00

66 lines
1.8 KiB
TypeScript

import { Locator } from 'playwright';
/**
*
* @parm locator - The locator to click on
* @param points - The points to click on
* @returns Promise<void>
*/
export async function simulateClicksOnElement({
locator,
points,
}: {
locator: Locator;
points: { x: number; y: number }[];
}) {
for (const { x, y } of points) {
await locator.click({ delay: 100, position: { x, y } });
}
}
/**
* Simulates clicks on an element at a normalized point.
*
* @param locator - The locator to click on.
* @param normalizedPoint - The point with x and y coordinates, normalized to the element's bounding box.
* @param button - The mouse button to use for the click (default is 'left').
*/
export async function simulateNormalizedClickOnElement({
locator,
normalizedPoint,
button = 'left',
}: {
locator: Locator;
normalizedPoint: { x: number; y: number };
button?: 'left' | 'right' | 'middle';
}) {
const bBox = await locator.boundingBox();
const position = { x: normalizedPoint.x * bBox.width, y: normalizedPoint.y * bBox.height };
await locator.click({ delay: 100, position, button });
}
/**
* Simulates clicks on an element at normalized points.
*
* @param locator - The locator to click on.
* @param normalizedPoints - An array of points with x and y coordinates, normalized to the element's bounding box.
* @param button - The mouse button to use for the click (default is 'left').
*/
export async function simulateNormalizedClicksOnElement({
locator,
normalizedPoints,
button = 'left',
}: {
locator: Locator;
normalizedPoints: { x: number; y: number }[];
button?: 'left' | 'right' | 'middle';
}) {
for (const normalizedPoint of normalizedPoints) {
await simulateNormalizedClickOnElement({
locator,
normalizedPoint,
button,
});
}
}