Skip to content

Commit 5c2b2d1

Browse files
committed
test(*): allow UIInteraction to click everywhere, #6471
1 parent 72a0584 commit 5c2b2d1

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

projects/igniteui-angular/src/lib/test-utils/ui-interactions.spec.ts

+37-4
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,48 @@ export class UIInteractions {
121121
* Clicks an element - native or debug, by dispatching pointerdown, focus, pointerup and click events.
122122
* @param element - Native or debug element.
123123
*/
124-
public static clickElement(element) {
124+
public static clickElement(
125+
element,
126+
horizontal: HorizontalAlignment = HorizontalAlignment.Left,
127+
vertical: VerticalAlignment = VerticalAlignment.Top) {
125128
const nativeElement = element.nativeElement ? element.nativeElement : element;
126-
const elementRect = nativeElement.getBoundingClientRect();
127-
UIInteractions.simulatePointerEvent('pointerdown', nativeElement, elementRect.left, elementRect.top);
129+
const point: Point = this.elementPointFromDirection(nativeElement, horizontal, vertical);
130+
UIInteractions.simulatePointerEvent('pointerdown', nativeElement, point.x, point.y);
128131
nativeElement.dispatchEvent(new Event('focus'));
129-
UIInteractions.simulatePointerEvent('pointerup', nativeElement, elementRect.left, elementRect.top);
132+
UIInteractions.simulatePointerEvent('pointerup', nativeElement, point.x, point.y);
130133
nativeElement.dispatchEvent(new Event('click', { bubbles: true }));
131134
}
132135

136+
public static elementPointFromDirection (element: Element, horizontal: HorizontalAlignment, vertical: VerticalAlignment): Point {
137+
const elementRect = element.getBoundingClientRect();
138+
const point: Point = { x: 0, y: 0};
139+
switch (horizontal) {
140+
case HorizontalAlignment.Left:
141+
point.x = elementRect.left;
142+
break;
143+
case HorizontalAlignment.Center:
144+
point.x = elementRect.left + elementRect.width / 2;
145+
break;
146+
case HorizontalAlignment.Right:
147+
point.x = elementRect.right;
148+
break;
149+
}
150+
151+
switch (vertical) {
152+
case VerticalAlignment.Top:
153+
point.y = elementRect.top;
154+
break;
155+
case VerticalAlignment.Middle:
156+
point.y = elementRect.top + elementRect.height / 2;
157+
break;
158+
case VerticalAlignment.Bottom:
159+
point.y = elementRect.bottom;
160+
break;
161+
}
162+
163+
return point;
164+
}
165+
133166
public static simulateMouseEvent(eventName: string, element, x, y) {
134167
const options: MouseEventInit = {
135168
view: window,

0 commit comments

Comments
 (0)