@@ -121,15 +121,48 @@ export class UIInteractions {
121
121
* Clicks an element - native or debug, by dispatching pointerdown, focus, pointerup and click events.
122
122
* @param element - Native or debug element.
123
123
*/
124
- public static clickElement ( element ) {
124
+ public static clickElement (
125
+ element ,
126
+ horizontal : HorizontalAlignment = HorizontalAlignment . Left ,
127
+ vertical : VerticalAlignment = VerticalAlignment . Top ) {
125
128
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 ) ;
128
131
nativeElement . dispatchEvent ( new Event ( 'focus' ) ) ;
129
- UIInteractions . simulatePointerEvent ( 'pointerup' , nativeElement , elementRect . left , elementRect . top ) ;
132
+ UIInteractions . simulatePointerEvent ( 'pointerup' , nativeElement , point . x , point . y ) ;
130
133
nativeElement . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
131
134
}
132
135
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
+
133
166
public static simulateMouseEvent ( eventName : string , element , x , y ) {
134
167
const options : MouseEventInit = {
135
168
view : window ,
0 commit comments