1
- import { Directionality , Direction } from '@angular/cdk/bidi' ;
1
+ import { Direction , Directionality } from '@angular/cdk/bidi' ;
2
2
import {
3
+ DOWN_ARROW ,
4
+ END ,
3
5
ENTER ,
6
+ HOME ,
4
7
LEFT_ARROW ,
5
8
RIGHT_ARROW ,
6
- UP_ARROW ,
7
- DOWN_ARROW ,
8
9
SPACE ,
9
- HOME ,
10
- END ,
10
+ UP_ARROW ,
11
11
} from '@angular/cdk/keycodes' ;
12
+ import { StepperOrientation } from '@angular/cdk/stepper' ;
12
13
import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
13
14
import { Component , DebugElement } from '@angular/core' ;
14
- import { async , ComponentFixture , TestBed , inject } from '@angular/core/testing' ;
15
- import { AbstractControl , AsyncValidatorFn , FormControl , FormGroup , ReactiveFormsModule ,
16
- ValidationErrors , Validators } from '@angular/forms' ;
15
+ import { async , ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
16
+ import {
17
+ AbstractControl ,
18
+ AsyncValidatorFn ,
19
+ FormControl ,
20
+ FormGroup ,
21
+ ReactiveFormsModule ,
22
+ ValidationErrors ,
23
+ Validators
24
+ } from '@angular/forms' ;
17
25
import { By } from '@angular/platform-browser' ;
18
26
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
19
- import { StepperOrientation } from '@angular/cdk/stepper ' ;
27
+ import { Observable } from 'rxjs/Observable ' ;
20
28
import { map } from 'rxjs/operators/map' ;
21
29
import { take } from 'rxjs/operators/take' ;
22
- import { Observable } from 'rxjs/Observable' ;
23
30
import { Subject } from 'rxjs/Subject' ;
24
31
import { MatStepperModule } from './index' ;
25
32
import { MatHorizontalStepper , MatStep , MatStepper , MatVerticalStepper } from './stepper' ;
@@ -44,6 +51,7 @@ describe('MatStepper', () => {
44
51
SimpleStepperWithoutStepControl ,
45
52
SimpleStepperWithStepControlAndCompletedBinding ,
46
53
SimpleMatHorizontalStepperApp ,
54
+ LinearStepperWithValidOptionalStep ,
47
55
] ,
48
56
providers : [
49
57
{ provide : Directionality , useFactory : ( ) => ( { value : dir } ) }
@@ -491,6 +499,8 @@ describe('MatStepper', () => {
491
499
testComponent . oneGroup . get ( 'oneCtrl' ) ! . setValue ( 'input' ) ;
492
500
testComponent . twoGroup . get ( 'twoCtrl' ) ! . setValue ( 'input' ) ;
493
501
testComponent . validationTrigger . next ( ) ;
502
+ stepperComponent . selectedIndex = 1 ;
503
+ fixture . detectChanges ( ) ;
494
504
stepperComponent . selectedIndex = 2 ;
495
505
fixture . detectChanges ( ) ;
496
506
@@ -559,6 +569,8 @@ describe('MatStepper', () => {
559
569
testComponent . twoGroup . get ( 'twoCtrl' ) ! . setValue ( 'input' ) ;
560
570
testComponent . threeGroup . get ( 'threeCtrl' ) ! . setValue ( 'valid' ) ;
561
571
testComponent . validationTrigger . next ( ) ;
572
+ stepperComponent . selectedIndex = 1 ;
573
+ fixture . detectChanges ( ) ;
562
574
stepperComponent . selectedIndex = 2 ;
563
575
fixture . detectChanges ( ) ;
564
576
stepperComponent . selectedIndex = 3 ;
@@ -695,6 +707,43 @@ describe('MatStepper', () => {
695
707
assertArrowKeyInteractionInRtl ( fixture , stepHeaders ) ;
696
708
} ) ;
697
709
} ) ;
710
+
711
+ describe ( 'valid step in linear stepper' , ( ) => {
712
+ let fixture : ComponentFixture < LinearStepperWithValidOptionalStep > ;
713
+ let testComponent : LinearStepperWithValidOptionalStep ;
714
+ let stepper : MatStepper ;
715
+
716
+ beforeEach ( ( ) => {
717
+ fixture = TestBed . createComponent ( LinearStepperWithValidOptionalStep ) ;
718
+ fixture . detectChanges ( ) ;
719
+
720
+ testComponent = fixture . componentInstance ;
721
+ stepper = fixture . debugElement
722
+ . query ( By . css ( 'mat-horizontal-stepper' ) ) . componentInstance ;
723
+ } ) ;
724
+
725
+ it ( 'must be visited if not optional' , ( ) => {
726
+ stepper . selectedIndex = 2 ;
727
+ fixture . detectChanges ( ) ;
728
+ expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
729
+
730
+ stepper . selectedIndex = 1 ;
731
+ fixture . detectChanges ( ) ;
732
+ expect ( stepper . selectedIndex ) . toBe ( 1 ) ;
733
+
734
+ stepper . selectedIndex = 2 ;
735
+ fixture . detectChanges ( ) ;
736
+ expect ( stepper . selectedIndex ) . toBe ( 2 ) ;
737
+ } ) ;
738
+
739
+ it ( 'can be skipped entirely if optional' , ( ) => {
740
+ testComponent . step2Optional = true ;
741
+ fixture . detectChanges ( ) ;
742
+ stepper . selectedIndex = 2 ;
743
+ fixture . detectChanges ( ) ;
744
+ expect ( stepper . selectedIndex ) . toBe ( 2 ) ;
745
+ } ) ;
746
+ } ) ;
698
747
} ) ;
699
748
700
749
/** Asserts that keyboard interaction works correctly. */
@@ -986,3 +1035,17 @@ class SimpleStepperWithStepControlAndCompletedBinding {
986
1035
`
987
1036
} )
988
1037
class IconOverridesStepper { }
1038
+
1039
+ @Component ( {
1040
+ template : `
1041
+ <mat-horizontal-stepper linear>
1042
+ <mat-step label="Step 1" [stepControl]="controls[0]"></mat-step>
1043
+ <mat-step label="Step 2" [stepControl]="controls[1]" [optional]="step2Optional"></mat-step>
1044
+ <mat-step label="Step 3" [stepControl]="controls[2]"></mat-step>
1045
+ </mat-horizontal-stepper>
1046
+ `
1047
+ } )
1048
+ class LinearStepperWithValidOptionalStep {
1049
+ controls = [ 0 , 0 , 0 ] . map ( ( ) => new FormControl ( ) ) ;
1050
+ step2Optional = false ;
1051
+ }
0 commit comments