@@ -27,7 +27,9 @@ describe('MatHorizontalStepper', () => {
27
27
declarations : [
28
28
SimpleMatHorizontalStepperApp ,
29
29
SimplePreselectedMatHorizontalStepperApp ,
30
- LinearMatHorizontalStepperApp
30
+ LinearMatHorizontalStepperApp ,
31
+ SimpleStepperWithoutStepControl ,
32
+ SimpleStepperWithStepControlAndCompletedBinding
31
33
] ,
32
34
providers : [
33
35
{ provide : Directionality , useFactory : ( ) => ( { value : dir } ) }
@@ -199,6 +201,54 @@ describe('MatHorizontalStepper', () => {
199
201
let stepHeaders = debugElement . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
200
202
assertSelectionChangeOnHeaderClick ( preselectedFixture , stepHeaders ) ;
201
203
} ) ;
204
+
205
+ it ( 'should not move to the next step if the current one is not completed ' +
206
+ 'and there is no `stepControl`' , ( ) => {
207
+ fixture . destroy ( ) ;
208
+
209
+ const noStepControlFixture = TestBed . createComponent ( SimpleStepperWithoutStepControl ) ;
210
+
211
+ noStepControlFixture . detectChanges ( ) ;
212
+
213
+ const stepper : MatHorizontalStepper = noStepControlFixture . debugElement
214
+ . query ( By . directive ( MatHorizontalStepper ) ) . componentInstance ;
215
+
216
+ const headers = noStepControlFixture . debugElement
217
+ . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
218
+
219
+ expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
220
+
221
+ headers [ 1 ] . nativeElement . click ( ) ;
222
+ noStepControlFixture . detectChanges ( ) ;
223
+
224
+ expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
225
+ } ) ;
226
+
227
+ it ( 'should have the `stepControl` take precedence when both `completed` and ' +
228
+ '`stepControl` are set' , ( ) => {
229
+ fixture . destroy ( ) ;
230
+
231
+ const controlAndBindingFixture =
232
+ TestBed . createComponent ( SimpleStepperWithStepControlAndCompletedBinding ) ;
233
+
234
+ controlAndBindingFixture . detectChanges ( ) ;
235
+
236
+ expect ( controlAndBindingFixture . componentInstance . steps [ 0 ] . control . valid ) . toBe ( true ) ;
237
+ expect ( controlAndBindingFixture . componentInstance . steps [ 0 ] . completed ) . toBe ( false ) ;
238
+
239
+ const stepper : MatHorizontalStepper = controlAndBindingFixture . debugElement
240
+ . query ( By . directive ( MatHorizontalStepper ) ) . componentInstance ;
241
+
242
+ const headers = controlAndBindingFixture . debugElement
243
+ . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
244
+
245
+ expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
246
+
247
+ headers [ 1 ] . nativeElement . click ( ) ;
248
+ controlAndBindingFixture . detectChanges ( ) ;
249
+
250
+ expect ( stepper . selectedIndex ) . toBe ( 1 ) ;
251
+ } ) ;
202
252
} ) ;
203
253
} ) ;
204
254
@@ -988,3 +1038,40 @@ class LinearMatVerticalStepperApp {
988
1038
class SimplePreselectedMatHorizontalStepperApp {
989
1039
index = 0 ;
990
1040
}
1041
+
1042
+ @Component ( {
1043
+ template : `
1044
+ <mat-horizontal-stepper linear>
1045
+ <mat-step
1046
+ *ngFor="let step of steps"
1047
+ [label]="step.label"
1048
+ [completed]="step.completed"></mat-step>
1049
+ </mat-horizontal-stepper>
1050
+ `
1051
+ } )
1052
+ class SimpleStepperWithoutStepControl {
1053
+ steps = [
1054
+ { label : 'One' , completed : false } ,
1055
+ { label : 'Two' , completed : false } ,
1056
+ { label : 'Three' , completed : false }
1057
+ ] ;
1058
+ }
1059
+
1060
+ @Component ( {
1061
+ template : `
1062
+ <mat-horizontal-stepper linear>
1063
+ <mat-step
1064
+ *ngFor="let step of steps"
1065
+ [label]="step.label"
1066
+ [stepControl]="step.control"
1067
+ [completed]="step.completed"></mat-step>
1068
+ </mat-horizontal-stepper>
1069
+ `
1070
+ } )
1071
+ class SimpleStepperWithStepControlAndCompletedBinding {
1072
+ steps = [
1073
+ { label : 'One' , completed : false , control : new FormControl ( ) } ,
1074
+ { label : 'Two' , completed : false , control : new FormControl ( ) } ,
1075
+ { label : 'Three' , completed : false , control : new FormControl ( ) }
1076
+ ] ;
1077
+ }
0 commit comments