@@ -203,6 +203,26 @@ describe('Carousel', () => {
203
203
expect ( spySlide ) . not . toHaveBeenCalled ( )
204
204
} )
205
205
206
+ it ( 'should not slide if arrow key is pressed and carousel is sliding' , ( ) => {
207
+ fixtureEl . innerHTML = '<div></div>'
208
+
209
+ const carouselEl = fixtureEl . querySelector ( 'div' )
210
+ const carousel = new Carousel ( carouselEl , { } )
211
+
212
+ spyOn ( carousel , '_triggerSlideEvent' )
213
+
214
+ carousel . _isSliding = true ;
215
+
216
+ [ 'ArrowLeft' , 'ArrowRight' ] . forEach ( key => {
217
+ const keydown = createEvent ( 'keydown' )
218
+ keydown . key = key
219
+
220
+ carouselEl . dispatchEvent ( keydown )
221
+ } )
222
+
223
+ expect ( carousel . _triggerSlideEvent ) . not . toHaveBeenCalled ( )
224
+ } )
225
+
206
226
it ( 'should wrap around from end to start when wrap option is true' , done => {
207
227
fixtureEl . innerHTML = [
208
228
'<div id="myCarousel" class="carousel slide">' ,
@@ -487,6 +507,49 @@ describe('Carousel', () => {
487
507
} )
488
508
} )
489
509
510
+ it ( 'should not slide when swiping and carousel is sliding' , done => {
511
+ Simulator . setType ( 'touch' )
512
+ clearPointerEvents ( )
513
+ document . documentElement . ontouchstart = ( ) => { }
514
+
515
+ fixtureEl . innerHTML = [
516
+ '<div class="carousel" data-bs-interval="false">' ,
517
+ ' <div class="carousel-inner">' ,
518
+ ' <div id="item" class="carousel-item active">' ,
519
+ ' <img alt="">' ,
520
+ ' </div>' ,
521
+ ' <div class="carousel-item">' ,
522
+ ' <img alt="">' ,
523
+ ' </div>' ,
524
+ ' </div>' ,
525
+ '</div>'
526
+ ] . join ( '' )
527
+
528
+ const carouselEl = fixtureEl . querySelector ( '.carousel' )
529
+ const carousel = new Carousel ( carouselEl )
530
+ carousel . _isSliding = true
531
+
532
+ spyOn ( carousel , '_triggerSlideEvent' )
533
+
534
+ Simulator . gestures . swipe ( carouselEl , {
535
+ deltaX : 300 ,
536
+ deltaY : 0
537
+ } )
538
+
539
+ Simulator . gestures . swipe ( carouselEl , {
540
+ pos : [ 300 , 10 ] ,
541
+ deltaX : - 300 ,
542
+ deltaY : 0
543
+ } )
544
+
545
+ setTimeout ( ( ) => {
546
+ expect ( carousel . _triggerSlideEvent ) . not . toHaveBeenCalled ( )
547
+ delete document . documentElement . ontouchstart
548
+ restorePointerEvents ( )
549
+ done ( )
550
+ } , 300 )
551
+ } )
552
+
490
553
it ( 'should not allow pinch with touch events' , done => {
491
554
Simulator . setType ( 'touch' )
492
555
clearPointerEvents ( )
@@ -552,12 +615,12 @@ describe('Carousel', () => {
552
615
const carouselEl = fixtureEl . querySelector ( 'div' )
553
616
const carousel = new Carousel ( carouselEl , { } )
554
617
555
- spyOn ( carousel , '_slide ' )
618
+ spyOn ( carousel , '_triggerSlideEvent ' )
556
619
557
620
carousel . _isSliding = true
558
621
carousel . next ( )
559
622
560
- expect ( carousel . _slide ) . not . toHaveBeenCalled ( )
623
+ expect ( carousel . _triggerSlideEvent ) . not . toHaveBeenCalled ( )
561
624
} )
562
625
563
626
it ( 'should not fire slid when slide is prevented' , done => {
@@ -763,12 +826,12 @@ describe('Carousel', () => {
763
826
const carouselEl = fixtureEl . querySelector ( 'div' )
764
827
const carousel = new Carousel ( carouselEl , { } )
765
828
766
- spyOn ( carousel , '_slide ' )
829
+ spyOn ( carousel , '_triggerSlideEvent ' )
767
830
768
831
carousel . _isSliding = true
769
832
carousel . prev ( )
770
833
771
- expect ( carousel . _slide ) . not . toHaveBeenCalled ( )
834
+ expect ( carousel . _triggerSlideEvent ) . not . toHaveBeenCalled ( )
772
835
} )
773
836
} )
774
837
0 commit comments