@@ -3,23 +3,15 @@ import { renderHook } from "@testing-library/react-hooks";
33import { fireEvent , render } from "@testing-library/react" ;
44
55import usePressedStates from "../usePressedStates" ;
6+ import { MergableRippleHandlerNames } from "../ripples/types" ;
67
78interface Props
8- extends Pick <
9- HTMLAttributes < HTMLButtonElement > ,
10- | "onKeyDown"
11- | "onKeyUp"
12- | "onMouseDown"
13- | "onMouseUp"
14- | "onMouseLeave"
15- | "onTouchStart"
16- | "onTouchMove"
17- | "onTouchEnd"
18- > {
9+ extends Pick < HTMLAttributes < HTMLButtonElement > , MergableRippleHandlerNames > {
1910 pressedRef ?: { current : boolean | null } ;
2011 disableSpacebarClick ?: boolean ;
2112}
2213const Test : FC < Props > = ( {
14+ onClick,
2315 onKeyDown,
2416 onKeyUp,
2517 onMouseDown,
@@ -33,6 +25,7 @@ const Test: FC<Props> = ({
3325} ) => {
3426 const { pressed, handlers } = usePressedStates ( {
3527 handlers : {
28+ onClick,
3629 onKeyDown,
3730 onKeyUp,
3831 onMouseDown,
@@ -74,7 +67,29 @@ describe("usePressedStates", () => {
7467 } ) ;
7568 } ) ;
7669
70+ it ( "should include the `onClick` in the handlers result if it was passed as an option even though the functionality is not updated" , ( ) => {
71+ const onClick = jest . fn ( ) ;
72+ const { result } = renderHook ( ( ) =>
73+ usePressedStates ( { handlers : { onClick } } )
74+ ) ;
75+ expect ( result . current ) . toEqual ( {
76+ pressed : false ,
77+ handlers : {
78+ onClick,
79+ onTouchStart : expect . any ( Function ) ,
80+ onTouchMove : expect . any ( Function ) ,
81+ onTouchEnd : expect . any ( Function ) ,
82+ onMouseDown : expect . any ( Function ) ,
83+ onMouseUp : expect . any ( Function ) ,
84+ onMouseLeave : expect . any ( Function ) ,
85+ onKeyDown : expect . any ( Function ) ,
86+ onKeyUp : expect . any ( Function ) ,
87+ } ,
88+ } ) ;
89+ } ) ;
90+
7791 it ( "should trigger the provided event handlers as normal" , ( ) => {
92+ const onClick = jest . fn ( ) ;
7893 const onKeyDown = jest . fn ( ) ;
7994 const onKeyUp = jest . fn ( ) ;
8095 const onMouseDown = jest . fn ( ) ;
@@ -86,6 +101,7 @@ describe("usePressedStates", () => {
86101
87102 const { getByText } = render (
88103 < Test
104+ onClick = { onClick }
89105 onKeyDown = { onKeyDown }
90106 onKeyUp = { onKeyUp }
91107 onMouseDown = { onMouseDown }
@@ -102,6 +118,7 @@ describe("usePressedStates", () => {
102118 fireEvent . keyUp ( button ) ;
103119 fireEvent . mouseDown ( button ) ;
104120 fireEvent . mouseUp ( button ) ;
121+ fireEvent . click ( button ) ;
105122 fireEvent . mouseLeave ( button ) ;
106123 fireEvent . touchStart ( button ) ;
107124 fireEvent . touchMove ( button ) ;
@@ -111,6 +128,7 @@ describe("usePressedStates", () => {
111128 expect ( onKeyUp ) . toBeCalledTimes ( 1 ) ;
112129 expect ( onMouseDown ) . toBeCalledTimes ( 1 ) ;
113130 expect ( onMouseUp ) . toBeCalledTimes ( 1 ) ;
131+ expect ( onClick ) . toBeCalledTimes ( 1 ) ;
114132 expect ( onMouseLeave ) . toBeCalledTimes ( 1 ) ;
115133 expect ( onTouchStart ) . toBeCalledTimes ( 1 ) ;
116134 expect ( onTouchMove ) . toBeCalledTimes ( 1 ) ;
0 commit comments