@@ -2454,129 +2454,6 @@ describe('Event responder: Press', () => {
24542454 } ,
24552455 ) ;
24562456
2457- describe ( 'onContextMenu' , ( ) => {
2458- it ( 'is called after a right mouse click' , ( ) => {
2459- const onContextMenu = jest . fn ( ) ;
2460- const ref = React . createRef ( ) ;
2461- const Component = ( ) => {
2462- const listener = usePressResponder ( { onContextMenu} ) ;
2463-
2464- return < div ref = { ref } listeners = { listener } /> ;
2465- } ;
2466- ReactDOM . render ( < Component /> , container ) ;
2467-
2468- ref . current . dispatchEvent (
2469- createEvent ( 'pointerdown' , { pointerType : 'mouse' , button : 2 } ) ,
2470- ) ;
2471- ref . current . dispatchEvent ( createEvent ( 'contextmenu' ) ) ;
2472- expect ( onContextMenu ) . toHaveBeenCalledTimes ( 1 ) ;
2473- expect ( onContextMenu ) . toHaveBeenCalledWith (
2474- expect . objectContaining ( { pointerType : 'mouse' , type : 'contextmenu' } ) ,
2475- ) ;
2476- } ) ;
2477-
2478- it ( 'is called after a left mouse click + ctrl key on Mac' , ( ) => {
2479- jest . resetModules ( ) ;
2480- const platformGetter = jest . spyOn ( global . navigator , 'platform' , 'get' ) ;
2481- platformGetter . mockReturnValue ( 'MacIntel' ) ;
2482- init ( ) ;
2483-
2484- const onContextMenu = jest . fn ( ) ;
2485- const ref = React . createRef ( ) ;
2486-
2487- const Component = ( ) => {
2488- const listener = usePressResponder ( { onContextMenu} ) ;
2489-
2490- return < div ref = { ref } listeners = { listener } /> ;
2491- } ;
2492- ReactDOM . render ( < Component /> , container ) ;
2493-
2494- ref . current . dispatchEvent (
2495- createEvent ( 'pointerdown' , {
2496- pointerType : 'mouse' ,
2497- button : 0 ,
2498- ctrlKey : true ,
2499- } ) ,
2500- ) ;
2501- ref . current . dispatchEvent ( createEvent ( 'contextmenu' ) ) ;
2502- expect ( onContextMenu ) . toHaveBeenCalledTimes ( 1 ) ;
2503- expect ( onContextMenu ) . toHaveBeenCalledWith (
2504- expect . objectContaining ( { pointerType : 'mouse' , type : 'contextmenu' } ) ,
2505- ) ;
2506- platformGetter . mockClear ( ) ;
2507- } ) ;
2508-
2509- it ( 'is not called after a left mouse click + ctrl key on Windows' , ( ) => {
2510- jest . resetModules ( ) ;
2511- const platformGetter = jest . spyOn ( global . navigator , 'platform' , 'get' ) ;
2512- platformGetter . mockReturnValue ( 'Win32' ) ;
2513- init ( ) ;
2514-
2515- const onContextMenu = jest . fn ( ) ;
2516- const ref = React . createRef ( ) ;
2517-
2518- const Component = ( ) => {
2519- const listener = usePressResponder ( { onContextMenu} ) ;
2520-
2521- return < div ref = { ref } listeners = { listener } /> ;
2522- } ;
2523- ReactDOM . render ( < Component /> , container ) ;
2524-
2525- ref . current . dispatchEvent (
2526- createEvent ( 'pointerdown' , {
2527- pointerType : 'mouse' ,
2528- button : 0 ,
2529- ctrlKey : true ,
2530- } ) ,
2531- ) ;
2532- ref . current . dispatchEvent ( createEvent ( 'contextmenu' ) ) ;
2533- expect ( onContextMenu ) . toHaveBeenCalledTimes ( 0 ) ;
2534- platformGetter . mockClear ( ) ;
2535- } ) ;
2536-
2537- it ( 'is not called after a right mouse click occurs during an active press' , ( ) => {
2538- const onContextMenu = jest . fn ( ) ;
2539- const ref = React . createRef ( ) ;
2540-
2541- const Component = ( ) => {
2542- const listener = usePressResponder ( { onContextMenu} ) ;
2543-
2544- return < div ref = { ref } listeners = { listener } /> ;
2545- } ;
2546- ReactDOM . render ( < Component /> , container ) ;
2547-
2548- ref . current . dispatchEvent (
2549- createEvent ( 'pointerdown' , { pointerType : 'mouse' , button : 0 } ) ,
2550- ) ;
2551- ref . current . dispatchEvent ( createEvent ( 'contextmenu' ) ) ;
2552- expect ( onContextMenu ) . toHaveBeenCalledTimes ( 0 ) ;
2553- } ) ;
2554-
2555- it ( 'is still called if "preventContextMenu" is true' , ( ) => {
2556- const onContextMenu = jest . fn ( ) ;
2557- const ref = React . createRef ( ) ;
2558-
2559- const Component = ( ) => {
2560- const listener = usePressResponder ( {
2561- onContextMenu,
2562- preventContextMenu : true ,
2563- } ) ;
2564-
2565- return < div ref = { ref } listeners = { listener } /> ;
2566- } ;
2567- ReactDOM . render ( < Component /> , container ) ;
2568-
2569- ref . current . dispatchEvent (
2570- createEvent ( 'pointerdown' , { pointerType : 'mouse' , button : 2 } ) ,
2571- ) ;
2572- ref . current . dispatchEvent ( createEvent ( 'contextmenu' ) ) ;
2573- expect ( onContextMenu ) . toHaveBeenCalledTimes ( 1 ) ;
2574- expect ( onContextMenu ) . toHaveBeenCalledWith (
2575- expect . objectContaining ( { defaultPrevented : true } ) ,
2576- ) ;
2577- } ) ;
2578- } ) ;
2579-
25802457 it ( 'should work correctly with stopPropagation set to true' , ( ) => {
25812458 const ref = React . createRef ( ) ;
25822459 const pointerDownEvent = jest . fn ( ) ;
0 commit comments