@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import React from "react" ;
17+ import React , { MouseEventHandler } from "react" ;
1818import { screen , render , RenderResult } from "@testing-library/react" ;
1919import userEvent from "@testing-library/user-event" ;
2020
@@ -82,28 +82,39 @@ describe("PictureInPictureDragger", () => {
8282 } ) ;
8383 } ) ;
8484
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 : jest . Mocked < MouseEventHandler > ;
87+ let target : HTMLElement ;
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+ } ) ;
108119 } ) ;
109120} ) ;
0 commit comments