@@ -8,7 +8,7 @@ interface Coordinates {
88 y : number
99}
1010
11- export const createMouseEvent = ( type : string ) => ( coords : Coordinates ) => {
11+ export const createMouseEvent = ( type : string , coords : Coordinates ) => {
1212 const event = new MouseEvent ( type , {
1313 clientX : coords . x ,
1414 clientY : coords . y ,
@@ -18,20 +18,22 @@ export const createMouseEvent = (type: string) => (coords: Coordinates) => {
1818 return event
1919}
2020
21- export const createMouseMoveEvent = createMouseEvent ( 'mousemove' )
22- export const createClickEvent = createMouseEvent ( 'click' )
23-
2421const invalidPosition = ( { line, character } : Position , message : string ) =>
2522 `Invalid postion L${ line } :${ character } . ${ message } . Remember, LSP Positions are 0-indexed.`
2623
2724/**
28- * Click the given position in a code element. This is impure because the current hoverifier implementation
29- * requires the click event to come from the already tokenized DOM elements. Ideally we would not rely on this at all.
25+ * Dispatch a mouse event at the given position in a code element. This is impure because the current hoverifier
26+ * implementation requires the click event to come from the already tokenized DOM elements. Ideally we would not
27+ * rely on this at all.
3028 *
3129 * @param codeViewProps the codeViewProps props from the test cases.
32- * @param position the position to click .
30+ * @param position the position of the event .
3331 */
34- export const clickPositionImpure = ( { codeView, getCodeElementFromLineNumber } : CodeViewProps , position : Position ) => {
32+ export const dispatchMouseEventAtPositionImpure = (
33+ eventType : 'click' | 'mouseover' | 'mousemove' ,
34+ { codeView, getCodeElementFromLineNumber } : CodeViewProps ,
35+ position : Position
36+ ) => {
3537 const line = getCodeElementFromLineNumber ( codeView , position . line )
3638 if ( ! line ) {
3739 throw new Error ( invalidPosition ( position , 'Line not found' ) )
@@ -52,7 +54,7 @@ export const clickPositionImpure = ({ codeView, getCodeElementFromLineNumber }:
5254 const rect = line . getBoundingClientRect ( )
5355 const { top, height, left, width } = rect
5456
55- const event = createClickEvent ( {
57+ const event = createMouseEvent ( eventType , {
5658 x : left + width / 2 ,
5759 y : top + height / 2 ,
5860 } )
@@ -88,7 +90,7 @@ export const clickPosition = ({ codeView, getCodeElementFromLineNumber }: CodeVi
8890 const top = rect . top
8991 const height = rect . height
9092
91- const event = createClickEvent ( {
93+ const event = createMouseEvent ( 'click' , {
9294 x : left + width / 2 ,
9395 y : top + height / 2 ,
9496 } )
0 commit comments