4
4
TestBed ,
5
5
ComponentFixture ,
6
6
fakeAsync ,
7
- tick
7
+ tick ,
8
+ flush
8
9
} from '@angular/core/testing' ;
9
10
import { By } from '@angular/platform-browser' ;
10
11
import {
@@ -19,6 +20,8 @@ import { configureTestSuite } from '../test-utils/configure-suite';
19
20
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
20
21
import { IgxSlideComponent } from './slide.component' ;
21
22
23
+ declare var Simulator : any ;
24
+
22
25
describe ( 'Carousel' , ( ) => {
23
26
configureTestSuite ( ) ;
24
27
let fixture ;
@@ -427,7 +430,7 @@ describe('Carousel', () => {
427
430
expect ( carousel . onSlideChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
428
431
} ) ;
429
432
430
- it ( 'should stop/play on mouse enter/leave and on tab key ' , ( ) => {
433
+ it ( 'should stop/play on mouse enter/leave ' , ( ) => {
431
434
carousel . interval = 1000 ;
432
435
carousel . play ( ) ;
433
436
fixture . detectChanges ( ) ;
@@ -450,17 +453,64 @@ describe('Carousel', () => {
450
453
expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 1 ) ;
451
454
expect ( carousel . onCarouselPaused . emit ) . toHaveBeenCalledTimes ( 1 ) ;
452
455
453
- UIInteractions . triggerKeyDownEvtUponElem ( 'Tab' , carousel . nativeElement , true ) ;
456
+ // When the carousel is stopped mouseleave does not start playing
457
+ carousel . stop ( ) ;
454
458
fixture . detectChanges ( ) ;
455
459
456
460
expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
461
+ expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 1 ) ;
457
462
expect ( carousel . onCarouselPaused . emit ) . toHaveBeenCalledTimes ( 2 ) ;
458
463
459
- UIInteractions . triggerKeyDownEvtUponElem ( 'Tab' , carousel . nativeElement , true ) ;
464
+ UIInteractions . hoverElement ( carousel . nativeElement , true ) ;
460
465
fixture . detectChanges ( ) ;
466
+
467
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
468
+
469
+ UIInteractions . unhoverElement ( carousel . nativeElement , true ) ;
470
+ fixture . detectChanges ( ) ;
471
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
472
+ expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 1 ) ;
473
+ } ) ;
474
+
475
+ it ( 'should stop/play on tap ' , async ( ) => {
476
+ carousel . interval = 1000 ;
477
+ carousel . play ( ) ;
478
+ fixture . detectChanges ( ) ;
479
+
480
+ spyOn ( carousel . onCarouselPaused , 'emit' ) ;
481
+ spyOn ( carousel . onCarouselPlaying , 'emit' ) ;
482
+
461
483
expect ( carousel . isPlaying ) . toBeTruthy ( ) ;
462
- expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 2 ) ;
463
- expect ( carousel . onCarouselPaused . emit ) . toHaveBeenCalledTimes ( 2 ) ;
484
+
485
+ Simulator . gestures . press ( carousel . nativeElement , { duration : 180 } ) ;
486
+ fixture . detectChanges ( ) ;
487
+ await wait ( 200 ) ;
488
+
489
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
490
+
491
+ Simulator . gestures . press ( carousel . nativeElement , { duration : 180 } ) ;
492
+ fixture . detectChanges ( ) ;
493
+ await wait ( 200 ) ;
494
+
495
+ expect ( carousel . isPlaying ) . toBeTruthy ( ) ;
496
+
497
+ // When the carousel is stopped tap does not start playing
498
+ carousel . stop ( ) ;
499
+ fixture . detectChanges ( ) ;
500
+
501
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
502
+
503
+ Simulator . gestures . press ( carousel . nativeElement , { duration : 180 } ) ;
504
+ fixture . detectChanges ( ) ;
505
+ await wait ( 200 ) ;
506
+
507
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
508
+
509
+ Simulator . gestures . press ( carousel . nativeElement , { duration : 180 } ) ;
510
+ fixture . detectChanges ( ) ;
511
+ await wait ( 200 ) ;
512
+
513
+ expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
464
514
} ) ;
465
515
} ) ;
466
516
@@ -601,19 +651,19 @@ describe('Carousel', () => {
601
651
HelperTestFunctions . verifyActiveSlide ( carousel , 0 ) ;
602
652
} ) ) ;
603
653
604
- it ( 'should add slides to the carousel when collection is changed' , fakeAsync ( ( ) => {
654
+ it ( 'should add slides to the carousel when collection is changed' , fakeAsync ( ( ) => {
605
655
tick ( ) ;
606
656
spyOn ( carousel . onSlideAdded , 'emit' ) ;
607
657
608
658
// add a slide
609
- slides . push ( { text : 'Slide 5' } ) ;
659
+ slides . push ( { text : 'Slide 5' } ) ;
610
660
fixture . detectChanges ( ) ;
611
661
612
662
HelperTestFunctions . verifyActiveSlide ( carousel , 2 ) ;
613
663
expect ( carousel . total ) . toEqual ( 5 ) ;
614
664
615
665
// add an active slide
616
- slides . push ( { text : 'Slide 6' , active : true } ) ;
666
+ slides . push ( { text : 'Slide 6' , active : true } ) ;
617
667
fixture . detectChanges ( ) ;
618
668
tick ( 100 ) ;
619
669
@@ -623,7 +673,7 @@ describe('Carousel', () => {
623
673
expect ( carousel . onSlideAdded . emit ) . toHaveBeenCalledTimes ( 2 ) ;
624
674
} ) ) ;
625
675
626
- it ( 'should remove slides in the carousel' , fakeAsync ( ( ) => {
676
+ it ( 'should remove slides in the carousel' , fakeAsync ( ( ) => {
627
677
tick ( ) ;
628
678
spyOn ( carousel . onSlideRemoved , 'emit' ) ;
629
679
@@ -646,7 +696,7 @@ describe('Carousel', () => {
646
696
expect ( carousel . onSlideRemoved . emit ) . toHaveBeenCalledTimes ( 2 ) ;
647
697
} ) ) ;
648
698
649
- it ( 'should not render navigation buttons and indicators when carousel does not have slides' , fakeAsync ( ( ) => {
699
+ it ( 'should not render navigation buttons and indicators when carousel does not have slides' , fakeAsync ( ( ) => {
650
700
fixture . componentInstance . removeAllSlides ( ) ;
651
701
fixture . detectChanges ( ) ;
652
702
tick ( 200 ) ;
@@ -657,13 +707,13 @@ describe('Carousel', () => {
657
707
expect ( HelperTestFunctions . getNextButton ( fixture ) . hidden ) . toBeTruthy ( ) ;
658
708
expect ( HelperTestFunctions . getPreviousButton ( fixture ) . hidden ) . toBeTruthy ( ) ;
659
709
660
- // add a slide
661
- fixture . componentInstance . addSlides ( ) ;
662
- fixture . detectChanges ( ) ;
663
- tick ( 200 ) ;
710
+ // add a slide
711
+ fixture . componentInstance . addSlides ( ) ;
712
+ fixture . detectChanges ( ) ;
713
+ tick ( 200 ) ;
664
714
665
- expect ( carousel . total ) . toEqual ( 2 ) ;
666
- expect ( HelperTestFunctions . getIndicatorsContainer ( fixture ) ) . toBeDefined ( ) ;
715
+ expect ( carousel . total ) . toEqual ( 2 ) ;
716
+ expect ( HelperTestFunctions . getIndicatorsContainer ( fixture ) ) . toBeDefined ( ) ;
667
717
expect ( HelperTestFunctions . getIndicatorsContainer ( fixture , CarouselIndicatorsOrientation . top ) ) . toBeDefined ( ) ;
668
718
expect ( HelperTestFunctions . getNextButton ( fixture ) . hidden ) . toBeFalsy ( ) ;
669
719
expect ( HelperTestFunctions . getPreviousButton ( fixture ) . hidden ) . toBeFalsy ( ) ;
@@ -824,10 +874,10 @@ class CarouselDynamicSlidesComponent {
824
874
825
875
addNewSlide ( ) {
826
876
this . slides . push (
827
- { text : 'Slide 1' , active : false } ,
828
- { text : 'Slide 2' , active : false } ,
829
- { text : 'Slide 3' , active : true } ,
830
- { text : 'Slide 4' , active : false }
877
+ { text : 'Slide 1' , active : false } ,
878
+ { text : 'Slide 2' , active : false } ,
879
+ { text : 'Slide 3' , active : true } ,
880
+ { text : 'Slide 4' , active : false }
831
881
) ;
832
882
}
833
883
@@ -837,8 +887,8 @@ class CarouselDynamicSlidesComponent {
837
887
838
888
public addSlides ( ) {
839
889
this . slides . push (
840
- { text : 'Slide 1' } ,
841
- { text : 'Slide 2' }
890
+ { text : 'Slide 1' } ,
891
+ { text : 'Slide 2' }
842
892
) ;
843
893
}
844
894
}
0 commit comments