@@ -14,6 +14,7 @@ import {
14
14
} from '../lib' ;
15
15
import {
16
16
createArtificialReactEvent ,
17
+ getCurrentPosition ,
17
18
isMouseEvent ,
18
19
isPointerEvent ,
19
20
isRecognisableEvent ,
@@ -26,7 +27,13 @@ import {
26
27
TestComponent ,
27
28
TestComponentProps ,
28
29
} from './TestComponent' ;
29
- import { TouchEvent as ReactTouchEvent , TouchList as ReactTouchList } from 'react' ;
30
+ import {
31
+ TouchEvent as ReactTouchEvent ,
32
+ PointerEvent as ReactPointerEvent ,
33
+ MouseEvent as ReactMouseEvent ,
34
+ TouchList as ReactTouchList ,
35
+ Touch as ReactTouch ,
36
+ } from 'react' ;
30
37
import { afterEach , beforeEach , describe , expect , MockedFunction , test } from 'vitest' ;
31
38
import {
32
39
emptyContext ,
@@ -137,9 +144,63 @@ describe('Hook handlers', () => {
137
144
⌞____________________________________________________________________________________________________
138
145
*/
139
146
describe ( 'Different environment compatibility' , ( ) => {
140
- test ( 'Properly detect TouchEvent event even if browser doesnt provide it' , ( ) => {
141
- const touchEvent = { touches : { } as ReactTouchList , nativeEvent : { touches : { } as TouchList } } as ReactTouchEvent ;
142
- expect ( isRecognisableEvent ( touchEvent ) ) . toBe ( true ) ;
147
+ describe ( 'Event absence' , ( ) => {
148
+ test ( 'Properly detect MouseEvent event even if browser doesnt provide it' , ( ) => {
149
+ const mouseEvent = {
150
+ nativeEvent : {
151
+ type : 'mouseup' ,
152
+ } ,
153
+ } as ReactMouseEvent ;
154
+ expect ( isRecognisableEvent ( mouseEvent ) ) . toBe ( true ) ;
155
+ } ) ;
156
+ test ( 'Properly detect TouchEvent event even if browser doesnt provide it' , ( ) => {
157
+ const touchEvent = {
158
+ nativeEvent : {
159
+ type : 'touchstart' ,
160
+ } ,
161
+ } as ReactTouchEvent ;
162
+ expect ( isRecognisableEvent ( touchEvent ) ) . toBe ( true ) ;
163
+ } ) ;
164
+ test ( 'Properly detect PointerEvent event even if browser doesnt provide it' , ( ) => {
165
+ const pointerEvent = {
166
+ nativeEvent : {
167
+ type : 'pointerup' ,
168
+ pointerId : 0 ,
169
+ } ,
170
+ } as ReactPointerEvent ;
171
+ expect ( isRecognisableEvent ( pointerEvent ) ) . toBe ( true ) ;
172
+ } ) ;
173
+ } ) ;
174
+
175
+ describe ( 'Reading position from event without it' , ( ) => {
176
+ test ( 'Return null for mouse-like event' , ( ) => {
177
+ const mouseEvent = {
178
+ nativeEvent : {
179
+ type : 'mouseup' ,
180
+ } ,
181
+ } as ReactMouseEvent ;
182
+ expect ( isRecognisableEvent ( mouseEvent ) ) . toBe ( true ) ;
183
+ expect ( getCurrentPosition ( mouseEvent ) ) . toBe ( null ) ;
184
+ } ) ;
185
+ test ( 'Return null for touch-like event' , ( ) => {
186
+ const touchEvent = {
187
+ nativeEvent : {
188
+ type : 'touchstart' ,
189
+ } ,
190
+ } as ReactTouchEvent ;
191
+ expect ( isRecognisableEvent ( touchEvent ) ) . toBe ( true ) ;
192
+ expect ( getCurrentPosition ( touchEvent ) ) . toBe ( null ) ;
193
+ } ) ;
194
+ test ( 'Return null for pointer-like event' , ( ) => {
195
+ const pointerEvent = {
196
+ nativeEvent : {
197
+ type : 'pointerup' ,
198
+ pointerId : 0 ,
199
+ } ,
200
+ } as ReactPointerEvent ;
201
+ expect ( isRecognisableEvent ( pointerEvent ) ) . toBe ( true ) ;
202
+ expect ( getCurrentPosition ( pointerEvent ) ) . toBe ( null ) ;
203
+ } ) ;
143
204
} ) ;
144
205
145
206
describe ( 'Without window' , ( ) => {
@@ -1422,11 +1483,19 @@ describe('Utils', () => {
1422
1483
1423
1484
test . each ( [
1424
1485
[ 'mouseDown' as const ] ,
1486
+ [ 'mouseMove' as const ] ,
1425
1487
[ 'mouseUp' as const ] ,
1488
+ [ 'mouseLeave' as const ] ,
1489
+ [ 'mouseOut' as const ] ,
1426
1490
[ 'touchStart' as const ] ,
1491
+ [ 'touchMove' as const ] ,
1427
1492
[ 'touchEnd' as const ] ,
1493
+ [ 'touchCancel' as const ] ,
1428
1494
[ 'pointerDown' as const ] ,
1495
+ [ 'pointerMove' as const ] ,
1429
1496
[ 'pointerUp' as const ] ,
1497
+ [ 'pointerLeave' as const ] ,
1498
+ [ 'pointerOut' as const ] ,
1430
1499
] ) ( 'Create recognisable artificial %s react event' , ( eventName ) => {
1431
1500
const event = createEvent [ eventName ] ( window ) ;
1432
1501
const reactEvent = createArtificialReactEvent ( event as LongPressDomEvents ) ;
0 commit comments