@@ -3,23 +3,15 @@ import { renderHook } from "@testing-library/react-hooks";
3
3
import { fireEvent , render } from "@testing-library/react" ;
4
4
5
5
import usePressedStates from "../usePressedStates" ;
6
+ import { MergableRippleHandlerNames } from "../ripples/types" ;
6
7
7
8
interface 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 > {
19
10
pressedRef ?: { current : boolean | null } ;
20
11
disableSpacebarClick ?: boolean ;
21
12
}
22
13
const Test : FC < Props > = ( {
14
+ onClick,
23
15
onKeyDown,
24
16
onKeyUp,
25
17
onMouseDown,
@@ -33,6 +25,7 @@ const Test: FC<Props> = ({
33
25
} ) => {
34
26
const { pressed, handlers } = usePressedStates ( {
35
27
handlers : {
28
+ onClick,
36
29
onKeyDown,
37
30
onKeyUp,
38
31
onMouseDown,
@@ -74,7 +67,29 @@ describe("usePressedStates", () => {
74
67
} ) ;
75
68
} ) ;
76
69
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
+
77
91
it ( "should trigger the provided event handlers as normal" , ( ) => {
92
+ const onClick = jest . fn ( ) ;
78
93
const onKeyDown = jest . fn ( ) ;
79
94
const onKeyUp = jest . fn ( ) ;
80
95
const onMouseDown = jest . fn ( ) ;
@@ -86,6 +101,7 @@ describe("usePressedStates", () => {
86
101
87
102
const { getByText } = render (
88
103
< Test
104
+ onClick = { onClick }
89
105
onKeyDown = { onKeyDown }
90
106
onKeyUp = { onKeyUp }
91
107
onMouseDown = { onMouseDown }
@@ -102,6 +118,7 @@ describe("usePressedStates", () => {
102
118
fireEvent . keyUp ( button ) ;
103
119
fireEvent . mouseDown ( button ) ;
104
120
fireEvent . mouseUp ( button ) ;
121
+ fireEvent . click ( button ) ;
105
122
fireEvent . mouseLeave ( button ) ;
106
123
fireEvent . touchStart ( button ) ;
107
124
fireEvent . touchMove ( button ) ;
@@ -111,6 +128,7 @@ describe("usePressedStates", () => {
111
128
expect ( onKeyUp ) . toBeCalledTimes ( 1 ) ;
112
129
expect ( onMouseDown ) . toBeCalledTimes ( 1 ) ;
113
130
expect ( onMouseUp ) . toBeCalledTimes ( 1 ) ;
131
+ expect ( onClick ) . toBeCalledTimes ( 1 ) ;
114
132
expect ( onMouseLeave ) . toBeCalledTimes ( 1 ) ;
115
133
expect ( onTouchStart ) . toBeCalledTimes ( 1 ) ;
116
134
expect ( onTouchMove ) . toBeCalledTimes ( 1 ) ;
0 commit comments