Skip to content

Commit

Permalink
refactor and fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bayheck committed May 6, 2024
1 parent ddab883 commit 15c7572
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/native-automation/client/event-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,27 @@ export default class CDPEventDescriptor {
};
}

public static async createMouseEventOptions (type: string, options: any): Promise<any> {
const boxes = options.element?.getClientRects();
let clientX;
let clientY;

if (boxes) {
clientX = boxes[0].x + boxes[0].width / 2;
clientY = boxes[0].y + boxes[0].height / 2;
public static async createMouseEventOptions (type: string, eventOptions: any): Promise<any> {
const { x, y } = await calculateIFrameTopLeftPoint();
const { element, options } = eventOptions;
let multilineClientX;
let multilineClientY;

if (element) {
const clientRects = element.getClientRects();
const computedStyle = window.getComputedStyle(element);

if (clientRects && computedStyle.display === 'inline') {
multilineClientX = clientRects[0].x + clientRects[0].width / 2;
multilineClientY = clientRects[0].y + clientRects[0].height / 2;
}
}

const { x, y } = await calculateIFrameTopLeftPoint();

return utils.extend({
x: (clientX ?? options.options.clientX) + x,
y: (clientY ?? options.options.clientY) + y,
modifiers: calculateKeyModifiersValue(options.options),
button: calculateMouseButtonValue(options.options),
x: (multilineClientX ?? options.clientX) + x,
y: (multilineClientY ?? options.clientY) + y,
modifiers: calculateKeyModifiersValue(options),
button: calculateMouseButtonValue(options),
type,
}, MOUSE_EVENT_OPTIONS);
}
Expand Down

0 comments on commit 15c7572

Please sign in to comment.