@@ -75,6 +75,16 @@ describe('MdHorizontalStepper', () => {
75
75
let stepHeaders = fixture . debugElement . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
76
76
checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
77
77
} ) ;
78
+
79
+ it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
80
+ checkEditableStep ( stepperComponent , fixture ) ;
81
+ } ) ;
82
+
83
+ it ( 'should show icon instead of index and active label on completed steps' , ( ) => {
84
+ let stepperComponentEl = fixture . debugElement
85
+ . query ( By . css ( 'md-horizontal-stepper' ) ) . nativeElement ;
86
+ checkStepIcon ( stepperComponent , stepperComponentEl , fixture ) ;
87
+ } ) ;
78
88
} ) ;
79
89
80
90
describe ( 'linear horizontal stepper' , ( ) => {
@@ -105,6 +115,10 @@ describe('MdHorizontalStepper', () => {
105
115
. queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) [ 1 ] . nativeElement ;
106
116
checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
107
117
} ) ;
118
+
119
+ it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
120
+ checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
121
+ } ) ;
108
122
} ) ;
109
123
} ) ;
110
124
@@ -173,6 +187,16 @@ describe('MdVerticalStepper', () => {
173
187
let stepHeaders = fixture . debugElement . queryAll ( By . css ( '.mat-vertical-stepper-header' ) ) ;
174
188
checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
175
189
} ) ;
190
+
191
+ it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
192
+ checkEditableStep ( stepperComponent , fixture ) ;
193
+ } ) ;
194
+
195
+ it ( 'should show icon instead of index on completed steps' , ( ) => {
196
+ let stepperComponentEl = fixture . debugElement
197
+ . query ( By . css ( 'md-vertical-stepper' ) ) . nativeElement ;
198
+ checkStepIcon ( stepperComponent , stepperComponentEl , fixture ) ;
199
+ } ) ;
176
200
} ) ;
177
201
178
202
describe ( 'linear vertical stepper' , ( ) => {
@@ -204,6 +228,10 @@ describe('MdVerticalStepper', () => {
204
228
205
229
checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
206
230
} ) ;
231
+
232
+ it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
233
+ checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
234
+ } ) ;
207
235
} ) ;
208
236
} ) ;
209
237
@@ -412,6 +440,57 @@ function checkLinearStepperValidity(stepHeaderEl: HTMLElement,
412
440
expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
413
441
}
414
442
443
+ function checkEditableStep ( stepperComponent : MdStepper ,
444
+ fixture : ComponentFixture < any > ) {
445
+ stepperComponent . selectedIndex = 1 ;
446
+ stepperComponent . _steps . toArray ( ) [ 0 ] . editable = false ;
447
+ let previousButtonNativeEl = fixture . debugElement
448
+ . queryAll ( By . directive ( MdStepperPrevious ) ) [ 1 ] . nativeElement ;
449
+ previousButtonNativeEl . click ( ) ;
450
+ fixture . detectChanges ( ) ;
451
+
452
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
453
+
454
+ stepperComponent . _steps . toArray ( ) [ 0 ] . editable = true ;
455
+ previousButtonNativeEl . click ( ) ;
456
+ fixture . detectChanges ( ) ;
457
+
458
+ expect ( stepperComponent . selectedIndex ) . toBe ( 0 ) ;
459
+ }
460
+
461
+ function checkOptionalStep ( stepperComponent : MdStepper ,
462
+ testComponent : LinearMdHorizontalStepperApp | LinearMdVerticalStepperApp ,
463
+ fixture : ComponentFixture < any > ) {
464
+ expect ( testComponent . oneGroup . get ( 'oneCtrl' ) ! . value ) . toBe ( '' ) ;
465
+ expect ( testComponent . oneGroup . get ( 'oneCtrl' ) ! . valid ) . toBe ( false ) ;
466
+ expect ( testComponent . oneGroup . valid ) . toBe ( false ) ;
467
+ expect ( stepperComponent . selectedIndex ) . toBe ( 0 ) ;
468
+
469
+ stepperComponent . _steps . toArray ( ) [ 0 ] . optional = true ;
470
+ let nextButtonNativeEl = fixture . debugElement
471
+ . queryAll ( By . directive ( MdStepperNext ) ) [ 0 ] . nativeElement ;
472
+ nextButtonNativeEl . click ( ) ;
473
+ fixture . detectChanges ( ) ;
474
+
475
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
476
+ }
477
+
478
+ function checkStepIcon ( stepperComponent : MdStepper ,
479
+ stepperComponentEl : HTMLElement ,
480
+ fixture : ComponentFixture < any > ) {
481
+ expect ( stepperComponent . _steps . toArray ( ) [ 0 ] . completed ) . toBe ( false ) ;
482
+ expect ( stepperComponentEl . querySelectorAll ( '.mat-stepper-index-interacted' ) . length ) . toBe ( 0 ) ;
483
+ expect ( stepperComponentEl . querySelectorAll ( '.mat-stepper-label-active' ) . length ) . toBe ( 1 ) ;
484
+ let nextButtonNativeEl = fixture . debugElement
485
+ . queryAll ( By . directive ( MdStepperNext ) ) [ 0 ] . nativeElement ;
486
+ nextButtonNativeEl . click ( ) ;
487
+ fixture . detectChanges ( ) ;
488
+
489
+ expect ( stepperComponent . _steps . toArray ( ) [ 0 ] . completed ) . toBe ( true ) ;
490
+ expect ( stepperComponentEl . querySelectorAll ( '.mat-stepper-index-interacted' ) . length ) . toBe ( 1 ) ;
491
+ expect ( stepperComponentEl . querySelectorAll ( '.mat-stepper-label-active' ) . length ) . toBe ( 2 ) ;
492
+ }
493
+
415
494
@Component ( {
416
495
template : `
417
496
<md-horizontal-stepper>
0 commit comments