44 TestBed ,
55 ComponentFixture ,
66 fakeAsync ,
7- tick
7+ tick ,
8+ flush
89} from '@angular/core/testing' ;
910import { By } from '@angular/platform-browser' ;
1011import {
@@ -19,6 +20,8 @@ import { configureTestSuite } from '../test-utils/configure-suite';
1920import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2021import { IgxSlideComponent } from './slide.component' ;
2122
23+ declare var Simulator : any ;
24+
2225describe ( 'Carousel' , ( ) => {
2326 configureTestSuite ( ) ;
2427 let fixture ;
@@ -427,7 +430,7 @@ describe('Carousel', () => {
427430 expect ( carousel . onSlideChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
428431 } ) ;
429432
430- it ( 'should stop/play on mouse enter/leave and on tab key ' , ( ) => {
433+ it ( 'should stop/play on mouse enter/leave ' , ( ) => {
431434 carousel . interval = 1000 ;
432435 carousel . play ( ) ;
433436 fixture . detectChanges ( ) ;
@@ -450,17 +453,64 @@ describe('Carousel', () => {
450453 expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 1 ) ;
451454 expect ( carousel . onCarouselPaused . emit ) . toHaveBeenCalledTimes ( 1 ) ;
452455
453- UIInteractions . triggerKeyDownEvtUponElem ( 'Tab' , carousel . nativeElement , true ) ;
456+ // When the carousel is stopped mouseleave does not start playing
457+ carousel . stop ( ) ;
454458 fixture . detectChanges ( ) ;
455459
456460 expect ( carousel . isPlaying ) . toBeFalsy ( ) ;
461+ expect ( carousel . onCarouselPlaying . emit ) . toHaveBeenCalledTimes ( 1 ) ;
457462 expect ( carousel . onCarouselPaused . emit ) . toHaveBeenCalledTimes ( 2 ) ;
458463
459- UIInteractions . triggerKeyDownEvtUponElem ( 'Tab' , carousel . nativeElement , true ) ;
464+ UIInteractions . hoverElement ( carousel . nativeElement , true ) ;
460465 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+
461483 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 ( ) ;
464514 } ) ;
465515 } ) ;
466516
@@ -601,19 +651,19 @@ describe('Carousel', () => {
601651 HelperTestFunctions . verifyActiveSlide ( carousel , 0 ) ;
602652 } ) ) ;
603653
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 ( ( ) => {
605655 tick ( ) ;
606656 spyOn ( carousel . onSlideAdded , 'emit' ) ;
607657
608658 // add a slide
609- slides . push ( { text : 'Slide 5' } ) ;
659+ slides . push ( { text : 'Slide 5' } ) ;
610660 fixture . detectChanges ( ) ;
611661
612662 HelperTestFunctions . verifyActiveSlide ( carousel , 2 ) ;
613663 expect ( carousel . total ) . toEqual ( 5 ) ;
614664
615665 // add an active slide
616- slides . push ( { text : 'Slide 6' , active : true } ) ;
666+ slides . push ( { text : 'Slide 6' , active : true } ) ;
617667 fixture . detectChanges ( ) ;
618668 tick ( 100 ) ;
619669
@@ -623,7 +673,7 @@ describe('Carousel', () => {
623673 expect ( carousel . onSlideAdded . emit ) . toHaveBeenCalledTimes ( 2 ) ;
624674 } ) ) ;
625675
626- it ( 'should remove slides in the carousel' , fakeAsync ( ( ) => {
676+ it ( 'should remove slides in the carousel' , fakeAsync ( ( ) => {
627677 tick ( ) ;
628678 spyOn ( carousel . onSlideRemoved , 'emit' ) ;
629679
@@ -646,7 +696,7 @@ describe('Carousel', () => {
646696 expect ( carousel . onSlideRemoved . emit ) . toHaveBeenCalledTimes ( 2 ) ;
647697 } ) ) ;
648698
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 ( ( ) => {
650700 fixture . componentInstance . removeAllSlides ( ) ;
651701 fixture . detectChanges ( ) ;
652702 tick ( 200 ) ;
@@ -657,13 +707,13 @@ describe('Carousel', () => {
657707 expect ( HelperTestFunctions . getNextButton ( fixture ) . hidden ) . toBeTruthy ( ) ;
658708 expect ( HelperTestFunctions . getPreviousButton ( fixture ) . hidden ) . toBeTruthy ( ) ;
659709
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 ) ;
664714
665- expect ( carousel . total ) . toEqual ( 2 ) ;
666- expect ( HelperTestFunctions . getIndicatorsContainer ( fixture ) ) . toBeDefined ( ) ;
715+ expect ( carousel . total ) . toEqual ( 2 ) ;
716+ expect ( HelperTestFunctions . getIndicatorsContainer ( fixture ) ) . toBeDefined ( ) ;
667717 expect ( HelperTestFunctions . getIndicatorsContainer ( fixture , CarouselIndicatorsOrientation . top ) ) . toBeDefined ( ) ;
668718 expect ( HelperTestFunctions . getNextButton ( fixture ) . hidden ) . toBeFalsy ( ) ;
669719 expect ( HelperTestFunctions . getPreviousButton ( fixture ) . hidden ) . toBeFalsy ( ) ;
@@ -824,10 +874,10 @@ class CarouselDynamicSlidesComponent {
824874
825875 addNewSlide ( ) {
826876 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 }
831881 ) ;
832882 }
833883
@@ -837,8 +887,8 @@ class CarouselDynamicSlidesComponent {
837887
838888 public addSlides ( ) {
839889 this . slides . push (
840- { text : 'Slide 1' } ,
841- { text : 'Slide 2' }
890+ { text : 'Slide 1' } ,
891+ { text : 'Slide 2' }
842892 ) ;
843893 }
844894}
0 commit comments