@@ -48,6 +48,28 @@ const getStepperPositions = (): string[] => {
48
48
return positions ;
49
49
} ;
50
50
51
+ const testAnimationBehvior = (
52
+ val : any ,
53
+ fix : ComponentFixture < IgxStepperSampleTestComponent > ,
54
+ isHorAnimTypeInvalidTest : boolean
55
+ ) : void => {
56
+ const stepper = fix . componentInstance . stepper ;
57
+ stepper . steps [ 0 ] . active = true ;
58
+ fix . detectChanges ( ) ;
59
+ const previousActiveStep = stepper . steps [ 0 ] ;
60
+ const activeChangeSpy = spyOn ( previousActiveStep . activeChange , 'emit' ) ;
61
+ activeChangeSpy . calls . reset ( ) ;
62
+ stepper . next ( ) ;
63
+ fix . detectChanges ( ) ;
64
+ tick ( 1000 ) ;
65
+ if ( ! isHorAnimTypeInvalidTest ) {
66
+ expect ( previousActiveStep . activeChange . emit ) . withContext ( val ) . toHaveBeenCalledOnceWith ( false ) ;
67
+ } else {
68
+ expect ( previousActiveStep . activeChange . emit ) . withContext ( val ) . not . toHaveBeenCalled ( ) ;
69
+ }
70
+ activeChangeSpy . calls . reset ( ) ;
71
+ } ;
72
+
51
73
describe ( 'Rendering Tests' , ( ) => {
52
74
configureTestSuite ( ) ;
53
75
let fix : ComponentFixture < IgxStepperSampleTestComponent > ;
@@ -205,7 +227,7 @@ describe('Rendering Tests', () => {
205
227
206
228
const testValues = [ null , undefined , [ ] , { } , 'sampleString' ] ;
207
229
208
- for ( const val of testValues ) {
230
+ for ( const val of testValues ) {
209
231
stepper . navigateTo ( val as any ) ;
210
232
fix . detectChanges ( ) ;
211
233
expect ( changingSpy ) . not . toHaveBeenCalled ( ) ;
@@ -421,7 +443,7 @@ describe('Rendering Tests', () => {
421
443
fix . detectChanges ( ) ;
422
444
423
445
let positions = getStepperPositions ( ) ;
424
- positions . forEach ( ( pos : string ) => {
446
+ positions . forEach ( ( pos : IgxStepperTitlePosition ) => {
425
447
stepper . horizontalTitlePosition = pos ;
426
448
fix . detectChanges ( ) ;
427
449
@@ -434,7 +456,7 @@ describe('Rendering Tests', () => {
434
456
fix . detectChanges ( ) ;
435
457
436
458
positions = getStepperPositions ( ) ;
437
- positions . forEach ( ( pos : string ) => {
459
+ positions . forEach ( ( pos : IgxStepperTitlePosition ) => {
438
460
stepper . verticalTitlePosition = pos ;
439
461
fix . detectChanges ( ) ;
440
462
@@ -514,59 +536,57 @@ describe('Rendering Tests', () => {
514
536
expect ( stepper . nativeElement . children [ 1 ] ) . toHaveClass ( STEPPER_HEADER ) ;
515
537
} ) ;
516
538
517
- it ( 'should allow modifying animationSettings that are used for transitioning between steps ' , ( ) => {
518
- stepper . orientation = IgxStepperOrientation . Horizontal ;
519
- fix . detectChanges ( ) ;
520
-
521
- expect ( stepper . animationDuration ) . toBe ( fix . componentInstance . animationDuration ) ;
522
- fix . componentInstance . animationDuration = 1000 ;
523
- fix . detectChanges ( ) ;
524
-
525
- expect ( stepper . animationDuration ) . toBe ( 1000 ) ;
526
-
527
- fix . componentInstance . animationDuration = null ;
528
- fix . detectChanges ( ) ;
539
+ it ( 'should allow modifying animationSettings that are used for transitioning between steps ' , fakeAsync ( ( ) => {
540
+ const numericTestValues = [ 100 , 1000 ] ;
529
541
530
- expect ( stepper . animationDuration ) . toBe ( ( stepper as any ) . _defaultAnimationDuration ) ;
542
+ for ( const val of numericTestValues ) {
543
+ fix . componentInstance . animationDuration = val as any ;
544
+ testAnimationBehvior ( val , fix , false ) ;
545
+ }
531
546
532
- fix . componentInstance . animationDuration = undefined ;
533
- fix . detectChanges ( ) ;
547
+ const dummyTestValues = [ - 1 , 'sampleString' , [ ] , { } ] ;
534
548
535
- expect ( stepper . animationDuration ) . toBe ( ( stepper as any ) . _defaultAnimationDuration ) ;
549
+ for ( const val of dummyTestValues ) {
550
+ expect ( ( ) => {
551
+ fix . componentInstance . animationDuration = val as any ;
552
+ testAnimationBehvior ( val , fix , false ) ;
553
+ } ) . toThrow ( ) ;
554
+ }
536
555
537
- expect ( stepper . horizontalAnimationType ) . toBe ( fix . componentInstance . horizontalAnimationType ) ;
538
- expect ( stepper . horizontalAnimationType ) . toBe ( 'slide' ) ;
556
+ const fallbackToDefaultValues = [ 0 , null ] ;
557
+ for ( const val of fallbackToDefaultValues ) {
558
+ fix . componentInstance . animationDuration = val as any ;
559
+ fix . detectChanges ( ) ;
560
+ expect ( stepper . animationDuration ) . withContext ( 'Set 0/null animation duration and verify default value' )
561
+ . toBe ( ( stepper as any ) . _defaultAnimationDuration ) ;
562
+ testAnimationBehvior ( val , fix , false ) ;
563
+ }
539
564
540
- fix . componentInstance . horizontalAnimationType = 'fade' ;
565
+ fix . componentInstance . animationDuration = 300 ;
566
+ stepper . orientation = IgxStepperOrientation . Horizontal ;
541
567
fix . detectChanges ( ) ;
542
568
543
- expect ( stepper . horizontalAnimationType ) . toBe ( fix . componentInstance . horizontalAnimationType ) ;
544
- expect ( stepper . horizontalAnimationType ) . toBe ( 'fade' ) ;
545
-
546
- fix . componentInstance . horizontalAnimationType = 'none' ;
547
- fix . detectChanges ( ) ;
569
+ const horAnimTypeValidValues = [ 'slide' , 'fade' , 'none' ] ;
570
+ for ( const val of horAnimTypeValidValues ) {
571
+ fix . componentInstance . horizontalAnimationType = val as any ;
572
+ testAnimationBehvior ( val , fix , false ) ;
573
+ }
548
574
549
- expect ( stepper . horizontalAnimationType ) . toBe ( fix . componentInstance . horizontalAnimationType ) ;
550
- expect ( stepper . horizontalAnimationType ) . toBe ( 'none' ) ;
575
+ const horAnimTypeTestValues = [ 'sampleString' , null , undefined , 0 , [ ] , { } ] ;
576
+ for ( const val of horAnimTypeTestValues ) {
577
+ fix . componentInstance . horizontalAnimationType = val as any ;
578
+ testAnimationBehvior ( val , fix , true ) ;
579
+ }
551
580
552
581
stepper . orientation = IgxStepperOrientation . Vertical ;
553
582
fix . detectChanges ( ) ;
554
583
555
- expect ( stepper . verticalAnimationType ) . toBe ( fix . componentInstance . verticalAnimationType ) ;
556
- fix . componentInstance . verticalAnimationType = 'grow' ;
557
-
558
- fix . componentInstance . verticalAnimationType = 'fade' ;
559
- fix . detectChanges ( ) ;
560
-
561
- expect ( stepper . verticalAnimationType ) . toBe ( fix . componentInstance . verticalAnimationType ) ;
562
- expect ( stepper . verticalAnimationType ) . toBe ( 'fade' ) ;
563
-
564
- fix . componentInstance . verticalAnimationType = 'none' ;
565
- fix . detectChanges ( ) ;
566
-
567
- expect ( stepper . verticalAnimationType ) . toBe ( fix . componentInstance . verticalAnimationType ) ;
568
- expect ( stepper . verticalAnimationType ) . toBe ( 'none' ) ;
569
- } ) ;
584
+ const vertAnimTypeTestValues = [ 'fade' , 'grow' , 'none' , 'sampleString' , null , undefined , 0 , [ ] , { } ] ;
585
+ for ( const val of vertAnimTypeTestValues ) {
586
+ fix . componentInstance . verticalAnimationType = val as any ;
587
+ testAnimationBehvior ( val , fix , false ) ;
588
+ }
589
+ } ) ) ;
570
590
571
591
it ( 'should render dynamically added step and properly set the linear disabled steps with its addition' , fakeAsync ( ( ) => {
572
592
const stepsLength = stepper . steps . length ;
@@ -670,14 +690,7 @@ describe('Rendering Tests', () => {
670
690
it ( 'should properly collapse the previously active step in horizontal orientation and animation type \'fade\'' , fakeAsync ( ( ) => {
671
691
stepper . orientation = IgxStepperOrientation . Horizontal ;
672
692
stepper . horizontalAnimationType = 'fade' ;
673
- stepper . steps [ 0 ] . active = true ;
674
- fix . detectChanges ( ) ;
675
-
676
- const previousActiveStep = stepper . steps [ 0 ] ;
677
- spyOn ( previousActiveStep . activeChange , 'emit' ) ;
678
-
679
- stepper . next ( ) ;
680
- expect ( previousActiveStep . activeChange . emit ) . toHaveBeenCalledOnceWith ( false ) ;
693
+ testAnimationBehvior ( 'fade' , fix , false ) ;
681
694
} ) ) ;
682
695
} ) ;
683
696
@@ -1011,7 +1024,7 @@ describe('Stepper service unit tests', () => {
1011
1024
1012
1025
const testValues = [ null , undefined , [ ] , { } , 'sampleString' ] ;
1013
1026
1014
- for ( const val of testValues ) {
1027
+ for ( const val of testValues ) {
1015
1028
expect ( ( ) => {
1016
1029
stepperService . expand ( val as any ) ;
1017
1030
} ) . toThrow ( ) ;
@@ -1048,7 +1061,7 @@ describe('Stepper service unit tests', () => {
1048
1061
1049
1062
const testValues = [ null , undefined , [ ] , { } , 'sampleString' ] ;
1050
1063
1051
- for ( const val of testValues ) {
1064
+ for ( const val of testValues ) {
1052
1065
expect ( ( ) => {
1053
1066
stepperService . expandThroughApi ( val as any ) ;
1054
1067
} ) . toThrow ( ) ;
@@ -1101,7 +1114,7 @@ describe('Stepper service unit tests', () => {
1101
1114
1102
1115
const testValues = [ null , undefined , [ ] , { } , 'sampleString' ] ;
1103
1116
1104
- for ( const val of testValues ) {
1117
+ for ( const val of testValues ) {
1105
1118
expect ( ( ) => {
1106
1119
stepperService . collapse ( val as any ) ;
1107
1120
} ) . toThrow ( ) ;
@@ -1297,5 +1310,3 @@ export class IgxStepperSampleTestComponent {
1297
1310
public displayHiddenStep = false ;
1298
1311
1299
1312
}
1300
-
1301
-
0 commit comments