@@ -2,7 +2,7 @@ import '@testing-library/jest-dom/extend-expect';
2
2
import React from 'react' ;
3
3
import { render , cleanup , fireEvent } from '@testing-library/react' ;
4
4
5
- import SwipeableListItem from '../SwipeableListItem' ;
5
+ import SwipeableListItem , { ActionAnimation } from '../SwipeableListItem' ;
6
6
import {
7
7
swipeRightMouse ,
8
8
swipeRightTouch ,
@@ -327,3 +327,127 @@ test('start and end callbacks triggered if swipe content is defined', () => {
327
327
expect ( callbackSwipeStart ) . toHaveBeenCalledTimes ( 4 ) ;
328
328
expect ( callbackSwipeEnd ) . toHaveBeenCalledTimes ( 4 ) ;
329
329
} ) ;
330
+
331
+ test ( 'if remove animation is applied' , ( ) => {
332
+ const callbackLeft = jest . fn ( ) ;
333
+ const callbackRight = jest . fn ( ) ;
334
+
335
+ const { getByTestId } = render (
336
+ < SwipeableListItem
337
+ swipeLeft = { {
338
+ content : < span > Left swipe content</ span > ,
339
+ actionAnimation : ActionAnimation . REMOVE ,
340
+ action : callbackLeft
341
+ } }
342
+ swipeRight = { {
343
+ content : < span > Right swipe content</ span > ,
344
+ actionAnimation : ActionAnimation . REMOVE ,
345
+ action : callbackRight
346
+ } }
347
+ >
348
+ < span > Item content</ span >
349
+ </ SwipeableListItem >
350
+ ) ;
351
+
352
+ const contentContainer = getByTestId ( 'content' ) ;
353
+
354
+ swipeLeftMouse ( contentContainer ) ;
355
+ expect ( contentContainer ) . toHaveClass ( 'contentRemove' ) ;
356
+
357
+ swipeLeftTouch ( contentContainer ) ;
358
+ expect ( contentContainer ) . toHaveClass ( 'contentRemove' ) ;
359
+
360
+ swipeRightMouse ( contentContainer ) ;
361
+ expect ( contentContainer ) . toHaveClass ( 'contentRemove' ) ;
362
+
363
+ swipeRightTouch ( contentContainer ) ;
364
+ expect ( contentContainer ) . toHaveClass ( 'contentRemove' ) ;
365
+
366
+ expect ( callbackLeft ) . toBeCalledTimes ( 2 ) ;
367
+ expect ( callbackRight ) . toBeCalledTimes ( 2 ) ;
368
+ } ) ;
369
+
370
+ test ( 'if return animation is applied' , ( ) => {
371
+ const callbackLeft = jest . fn ( ) ;
372
+ const callbackRight = jest . fn ( ) ;
373
+
374
+ const { getByTestId } = render (
375
+ < SwipeableListItem
376
+ swipeLeft = { {
377
+ content : < span > Left swipe content</ span > ,
378
+ actionAnimation : ActionAnimation . RETURN ,
379
+ action : callbackLeft
380
+ } }
381
+ swipeRight = { {
382
+ content : < span > Right swipe content</ span > ,
383
+ action : callbackRight
384
+ } }
385
+ >
386
+ < span > Item content</ span >
387
+ </ SwipeableListItem >
388
+ ) ;
389
+
390
+ const contentContainer = getByTestId ( 'content' ) ;
391
+
392
+ swipeLeftMouse ( contentContainer ) ;
393
+ expect ( contentContainer ) . toHaveClass ( 'contentReturn' ) ;
394
+
395
+ swipeLeftTouch ( contentContainer ) ;
396
+ expect ( contentContainer ) . toHaveClass ( 'contentReturn' ) ;
397
+
398
+ swipeRightMouse ( contentContainer ) ;
399
+ expect ( contentContainer ) . toHaveClass ( 'contentReturn' ) ;
400
+
401
+ swipeRightTouch ( contentContainer ) ;
402
+ expect ( contentContainer ) . toHaveClass ( 'contentReturn' ) ;
403
+
404
+ expect ( callbackLeft ) . toBeCalledTimes ( 2 ) ;
405
+ expect ( callbackRight ) . toBeCalledTimes ( 2 ) ;
406
+ } ) ;
407
+
408
+ test ( 'if none animation is applied' , ( ) => {
409
+ const callbackLeft = jest . fn ( ) ;
410
+ const callbackRight = jest . fn ( ) ;
411
+
412
+ const { getByTestId } = render (
413
+ < SwipeableListItem
414
+ swipeLeft = { {
415
+ content : < span > Left swipe content</ span > ,
416
+ actionAnimation : ActionAnimation . NONE ,
417
+ action : callbackLeft
418
+ } }
419
+ swipeRight = { {
420
+ content : < span > Right swipe content</ span > ,
421
+ actionAnimation : ActionAnimation . NONE ,
422
+ action : callbackRight
423
+ } }
424
+ >
425
+ < span > Item content</ span >
426
+ </ SwipeableListItem >
427
+ ) ;
428
+
429
+ const contentContainer = getByTestId ( 'content' ) ;
430
+
431
+ swipeLeftMouse ( contentContainer ) ;
432
+ expect ( contentContainer ) . toHaveClass ( 'content' ) ;
433
+ expect ( contentContainer ) . not . toHaveClass ( 'contentReturn' ) ;
434
+ expect ( contentContainer ) . not . toHaveClass ( 'contentRemove' ) ;
435
+
436
+ swipeLeftTouch ( contentContainer ) ;
437
+ expect ( contentContainer ) . toHaveClass ( 'content' ) ;
438
+ expect ( contentContainer ) . not . toHaveClass ( 'contentReturn' ) ;
439
+ expect ( contentContainer ) . not . toHaveClass ( 'contentRemove' ) ;
440
+
441
+ swipeRightMouse ( contentContainer ) ;
442
+ expect ( contentContainer ) . toHaveClass ( 'content' ) ;
443
+ expect ( contentContainer ) . not . toHaveClass ( 'contentReturn' ) ;
444
+ expect ( contentContainer ) . not . toHaveClass ( 'contentRemove' ) ;
445
+
446
+ swipeRightTouch ( contentContainer ) ;
447
+ expect ( contentContainer ) . toHaveClass ( 'content' ) ;
448
+ expect ( contentContainer ) . not . toHaveClass ( 'contentReturn' ) ;
449
+ expect ( contentContainer ) . not . toHaveClass ( 'contentRemove' ) ;
450
+
451
+ expect ( callbackLeft ) . toBeCalledTimes ( 2 ) ;
452
+ expect ( callbackRight ) . toBeCalledTimes ( 2 ) ;
453
+ } ) ;
0 commit comments