@@ -423,6 +423,80 @@ describe('carousel custom strategies', () => {
423423 } ) ) ;
424424} ) ;
425425
426+ describe ( 'carousel arrows' , ( ) => {
427+ let fixture : ComponentFixture < NzTestCarouselArrowsComponent > ;
428+ let testComponent : NzTestCarouselArrowsComponent ;
429+ let carouselWrapper : DebugElement ;
430+ let carouselContents : DebugElement [ ] ;
431+
432+ beforeEach ( ( ) => {
433+ fixture = TestBed . createComponent ( NzTestCarouselArrowsComponent ) ;
434+ fixture . detectChanges ( ) ;
435+ testComponent = fixture . debugElement . componentInstance ;
436+ carouselWrapper = fixture . debugElement . query ( By . directive ( NzCarouselComponent ) ) ;
437+ carouselContents = fixture . debugElement . queryAll ( By . directive ( NzCarouselContentDirective ) ) ;
438+ } ) ;
439+
440+ it ( 'should render arrows when nzArrows is true' , ( ) => {
441+ const prev = carouselWrapper . nativeElement . querySelector ( '.slick-prev' ) ;
442+ const next = carouselWrapper . nativeElement . querySelector ( '.slick-next' ) ;
443+ expect ( prev ) . not . toBeNull ( ) ;
444+ expect ( next ) . not . toBeNull ( ) ;
445+ } ) ;
446+
447+ it ( 'should navigate via arrows' , fakeAsync ( ( ) => {
448+ expect ( carouselContents [ 0 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
449+ carouselWrapper . nativeElement . querySelector ( '.slick-next' ) . click ( ) ;
450+ tickMilliseconds ( fixture , 700 ) ;
451+ expect ( carouselContents [ 1 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
452+ carouselWrapper . nativeElement . querySelector ( '.slick-prev' ) . click ( ) ;
453+ tickMilliseconds ( fixture , 700 ) ;
454+ expect ( carouselContents [ 0 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
455+ } ) ) ;
456+
457+ it ( 'should disable arrows at edges when loop is false' , fakeAsync ( ( ) => {
458+ testComponent . loop = false ;
459+ fixture . detectChanges ( ) ;
460+ const prev = carouselWrapper . nativeElement . querySelector ( '.slick-prev' ) ;
461+ const next = carouselWrapper . nativeElement . querySelector ( '.slick-next' ) ;
462+ expect ( prev . classList ) . toContain ( 'slick-disabled' ) ;
463+ expect ( next . classList ) . not . toContain ( 'slick-disabled' ) ;
464+
465+ // Go to last slide
466+ for ( let i = 0 ; i < 3 ; i ++ ) {
467+ next . click ( ) ;
468+ tickMilliseconds ( fixture , 700 ) ;
469+ }
470+ expect ( carouselContents [ 3 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
471+ expect ( next . classList ) . toContain ( 'slick-disabled' ) ;
472+
473+ // Clicking next should not move beyond last
474+ next . click ( ) ;
475+ tickMilliseconds ( fixture , 700 ) ;
476+ expect ( carouselContents [ 3 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
477+ } ) ) ;
478+ } ) ;
479+
480+ describe ( 'carousel no swipe' , ( ) => {
481+ let fixture : ComponentFixture < NzTestCarouselNoSwipeComponent > ;
482+ let testComponent : NzTestCarouselNoSwipeComponent ;
483+ let carouselContents : DebugElement [ ] ;
484+
485+ beforeEach ( ( ) => {
486+ fixture = TestBed . createComponent ( NzTestCarouselNoSwipeComponent ) ;
487+ fixture . detectChanges ( ) ;
488+ testComponent = fixture . debugElement . componentInstance ;
489+ carouselContents = fixture . debugElement . queryAll ( By . directive ( NzCarouselContentDirective ) ) ;
490+ } ) ;
491+
492+ it ( 'should not change slide on swipe when nzEnableSwipe is false' , fakeAsync ( ( ) => {
493+ expect ( carouselContents [ 0 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
494+ swipe ( testComponent . nzCarouselComponent , 500 ) ;
495+ tickMilliseconds ( fixture , 700 ) ;
496+ expect ( carouselContents [ 0 ] . nativeElement . classList ) . toContain ( 'slick-active' ) ;
497+ } ) ) ;
498+ } ) ;
499+
426500function tickMilliseconds < T > ( fixture : ComponentFixture < T > , seconds : number = 1 ) : void {
427501 fixture . detectChanges ( ) ;
428502 tick ( seconds ) ;
@@ -508,6 +582,43 @@ export class NzTestCarouselActiveIndexComponent {
508582 }
509583}
510584
585+ @Component ( {
586+ selector : 'nz-test-carousel-arrows' ,
587+ imports : [ NzCarouselModule ] ,
588+ template : `
589+ <nz-carousel [nzArrows]="true" [nzLoop]="loop">
590+ @for (index of array; track index) {
591+ <div nz-carousel-content>
592+ <h3>{{ index }}</h3>
593+ </div>
594+ }
595+ </nz-carousel>
596+ `
597+ } )
598+ export class NzTestCarouselArrowsComponent {
599+ @ViewChild ( NzCarouselComponent , { static : true } ) nzCarouselComponent ! : NzCarouselComponent ;
600+ array = [ 1 , 2 , 3 , 4 ] ;
601+ loop = true ;
602+ }
603+
604+ @Component ( {
605+ selector : 'nz-test-carousel-no-swipe' ,
606+ imports : [ NzCarouselModule ] ,
607+ template : `
608+ <nz-carousel [nzEnableSwipe]="false">
609+ @for (index of array; track index) {
610+ <div nz-carousel-content>
611+ <h3>{{ index }}</h3>
612+ </div>
613+ }
614+ </nz-carousel>
615+ `
616+ } )
617+ export class NzTestCarouselNoSwipeComponent {
618+ @ViewChild ( NzCarouselComponent , { static : true } ) nzCarouselComponent ! : NzCarouselComponent ;
619+ array = [ 1 , 2 , 3 , 4 ] ;
620+ }
621+
511622class MockDirectionality {
512623 value = 'ltr' ;
513624 change = new Subject ( ) ;
0 commit comments