@@ -82,28 +82,39 @@ describe("PictureInPictureDragger", () => {
82
82
} ) ;
83
83
} ) ;
84
84
85
- it ( "doesn't leak drag events to children as clicks" , async ( ) => {
86
- const clickSpy = jest . fn ( ) ;
87
- render (
88
- < PictureInPictureDragger draggable = { true } >
89
- { [
90
- ( { onStartMoving } ) => (
91
- < div onMouseDown = { onStartMoving } onClick = { clickSpy } >
92
- Hello
93
- </ div >
94
- ) ,
95
- ] }
96
- </ PictureInPictureDragger > ,
97
- ) ;
98
- const target = screen . getByText ( "Hello" ) ;
99
-
100
- // A click without a drag motion should go through
101
- await userEvent . pointer ( [ { keys : "[MouseLeft>]" , target } , { keys : "[/MouseLeft]" } ] ) ;
102
- expect ( clickSpy ) . toHaveBeenCalled ( ) ;
103
-
104
- // A drag motion should not trigger a click
105
- clickSpy . mockClear ( ) ;
106
- await userEvent . pointer ( [ { keys : "[MouseLeft>]" , target } , { coords : { x : 60 , y : 60 } } , "[/MouseLeft]" ] ) ;
107
- expect ( clickSpy ) . not . toHaveBeenCalled ( ) ;
85
+ describe ( "when rendering the dragger" , ( ) => {
86
+ let clickSpy ;
87
+ let target ;
88
+
89
+ beforeEach ( ( ) => {
90
+ clickSpy = jest . fn ( ) ;
91
+ render (
92
+ < PictureInPictureDragger draggable = { true } >
93
+ { [
94
+ ( { onStartMoving } ) => (
95
+ < div onMouseDown = { onStartMoving } onClick = { clickSpy } >
96
+ Hello
97
+ </ div >
98
+ ) ,
99
+ ] }
100
+ </ PictureInPictureDragger > ,
101
+ ) ;
102
+ target = screen . getByText ( "Hello" ) ;
103
+ } ) ;
104
+
105
+ it ( "and clicking without a drag motion, it should pass the click to children" , async ( ) => {
106
+ await userEvent . pointer ( [ { keys : "[MouseLeft>]" , target } , { keys : "[/MouseLeft]" } ] ) ;
107
+ expect ( clickSpy ) . toHaveBeenCalled ( ) ;
108
+ } ) ;
109
+
110
+ it ( "and clicking with a drag motion above the threshold of 5px, it should not pass the click to children" , async ( ) => {
111
+ await userEvent . pointer ( [ { keys : "[MouseLeft>]" , target } , { coords : { x : 60 , y : 2 } } , "[/MouseLeft]" ] ) ;
112
+ expect ( clickSpy ) . not . toHaveBeenCalled ( ) ;
113
+ } ) ;
114
+
115
+ it ( "and clickign with a drag motion below the threshold of 5px, it should pass the click to the children" , async ( ) => {
116
+ await userEvent . pointer ( [ { keys : "[MouseLeft>]" , target } , { coords : { x : 4 , y : 4 } } , "[/MouseLeft]" ] ) ;
117
+ expect ( clickSpy ) . toHaveBeenCalled ( ) ;
118
+ } ) ;
108
119
} ) ;
109
120
} ) ;
0 commit comments