9
9
SPACE ,
10
10
UP_ARROW ,
11
11
} from '@angular/cdk/keycodes' ;
12
- import { StepperOrientation , STEP_STATE } from '@angular/cdk/stepper' ;
12
+ import { StepperOrientation } from '@angular/cdk/stepper' ;
13
13
import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
14
14
import { Component , DebugElement , EventEmitter , OnInit } from '@angular/core' ;
15
15
import { async , ComponentFixture , fakeAsync , flush , inject , TestBed } from '@angular/core/testing' ;
@@ -278,62 +278,28 @@ describe('MatStepper', () => {
278
278
expect ( stepperComponent . selectedIndex ) . toBe ( 0 ) ;
279
279
} ) ;
280
280
281
- describe ( 'with custom state' , ( ) => {
282
- it ( 'should set the custom icon when the step is completed and on selected step' , ( ) => {
283
- let stepperComponent = fixture . debugElement
284
- . query ( By . directive ( MatStepper ) ) . componentInstance ;
285
- const firstStep = stepperComponent . _steps . toArray ( ) [ 0 ] ;
286
-
287
- expect ( stepperComponent . _getIndicatorType ( 0 , 'warning' ) ) . toBe ( STEP_STATE . EDIT ) ;
288
-
289
- stepperComponent . selectedIndex = 0 ;
290
- firstStep . completed = true ;
291
- fixture . detectChanges ( ) ;
292
-
293
- expect ( stepperComponent . _getIndicatorType ( 0 , 'warning' ) ) . toBe ( 'warning' ) ;
294
- } ) ;
295
- } ) ;
296
-
297
- it ( 'should set error icon if step has error' , ( ) => {
281
+ it ( 'should set create icon if step is editable and completed' , ( ) => {
298
282
let stepperComponent = fixture . debugElement . query ( By . directive ( MatStepper ) ) . componentInstance ;
299
283
let nextButtonNativeEl = fixture . debugElement
300
284
. queryAll ( By . directive ( MatStepperNext ) ) [ 0 ] . nativeElement ;
301
- const firstStep = stepperComponent . _steps . toArray ( ) [ 0 ] ;
302
-
303
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . EDIT ) ;
304
-
305
- firstStep . hasError = true ;
285
+ expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( 'number' ) ;
286
+ stepperComponent . _steps . toArray ( ) [ 0 ] . editable = true ;
306
287
nextButtonNativeEl . click ( ) ;
307
288
fixture . detectChanges ( ) ;
308
289
309
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . ERROR ) ;
290
+ expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( 'edit' ) ;
310
291
} ) ;
311
292
312
- it ( 'should set done icon if step is completed' , ( ) => {
293
+ it ( 'should set done icon if step is not editable and is completed' , ( ) => {
313
294
let stepperComponent = fixture . debugElement . query ( By . directive ( MatStepper ) ) . componentInstance ;
314
295
let nextButtonNativeEl = fixture . debugElement
315
296
. queryAll ( By . directive ( MatStepperNext ) ) [ 0 ] . nativeElement ;
316
- const firstStep = stepperComponent . _steps . toArray ( ) [ 0 ] ;
317
-
318
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . EDIT ) ;
319
-
320
- firstStep . completed = true ;
297
+ expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( 'number' ) ;
298
+ stepperComponent . _steps . toArray ( ) [ 0 ] . editable = false ;
321
299
nextButtonNativeEl . click ( ) ;
322
300
fixture . detectChanges ( ) ;
323
301
324
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . DONE ) ;
325
- } ) ;
326
-
327
- it ( 'should set number icon if step is completed and on selected step' , ( ) => {
328
- let stepperComponent = fixture . debugElement . query ( By . directive ( MatStepper ) ) . componentInstance ;
329
- const firstStep = stepperComponent . _steps . toArray ( ) [ 0 ] ;
330
-
331
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . EDIT ) ;
332
-
333
- firstStep . completed = true ;
334
- fixture . detectChanges ( ) ;
335
-
336
- expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( STEP_STATE . NUMBER ) ;
302
+ expect ( stepperComponent . _getIndicatorType ( 0 ) ) . toBe ( 'done' ) ;
337
303
} ) ;
338
304
339
305
it ( 'should re-render when the i18n labels change' , inject ( [ MatStepperIntl ] ,
@@ -418,23 +384,12 @@ describe('MatStepper', () => {
418
384
fixture . detectChanges ( ) ;
419
385
} ) ;
420
386
421
- it ( 'should override any icon' , ( ) => {
422
- const stepperDebugElement = fixture . debugElement . query ( By . directive ( MatStepper ) ) ;
423
- const stepperComponent : MatStepper = stepperDebugElement . componentInstance ;
424
-
425
- stepperComponent . _steps . toArray ( ) [ 3 ] . completed = true ;
426
- fixture . detectChanges ( ) ;
427
-
428
- const headers = stepperDebugElement . nativeElement . querySelectorAll ( 'mat-step-header' ) ;
429
-
430
- expect ( headers [ 3 ] . textContent ) . toContain ( 'Custom warning' ) ;
431
- } ) ;
432
-
433
387
it ( 'should allow for the `edit` icon to be overridden' , ( ) => {
434
388
const stepperDebugElement = fixture . debugElement . query ( By . directive ( MatStepper ) ) ;
435
389
const stepperComponent : MatStepper = stepperDebugElement . componentInstance ;
436
390
437
391
stepperComponent . _steps . toArray ( ) [ 0 ] . editable = true ;
392
+ stepperComponent . next ( ) ;
438
393
fixture . detectChanges ( ) ;
439
394
440
395
const header = stepperDebugElement . nativeElement . querySelector ( 'mat-step-header' ) ;
@@ -731,13 +686,12 @@ describe('MatStepper', () => {
731
686
732
687
const stepper : MatHorizontalStepper = noStepControlFixture . debugElement
733
688
. query ( By . directive ( MatHorizontalStepper ) ) . componentInstance ;
734
- const firstStep = stepper . _steps . toArray ( ) [ 0 ] ;
689
+
735
690
const headers = noStepControlFixture . debugElement
736
691
. queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
737
692
738
693
expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
739
694
740
- firstStep . completed = false ;
741
695
headers [ 1 ] . nativeElement . click ( ) ;
742
696
noStepControlFixture . detectChanges ( ) ;
743
697
@@ -754,16 +708,16 @@ describe('MatStepper', () => {
754
708
controlAndBindingFixture . detectChanges ( ) ;
755
709
756
710
expect ( controlAndBindingFixture . componentInstance . steps [ 0 ] . control . valid ) . toBe ( true ) ;
711
+ expect ( controlAndBindingFixture . componentInstance . steps [ 0 ] . completed ) . toBe ( false ) ;
757
712
758
713
const stepper : MatHorizontalStepper = controlAndBindingFixture . debugElement
759
714
. query ( By . directive ( MatHorizontalStepper ) ) . componentInstance ;
760
- const firstStep = stepper . _steps . toArray ( ) [ 0 ] ;
715
+
761
716
const headers = controlAndBindingFixture . debugElement
762
717
. queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
763
718
764
719
expect ( stepper . selectedIndex ) . toBe ( 0 ) ;
765
720
766
- firstStep . completed = false ;
767
721
headers [ 1 ] . nativeElement . click ( ) ;
768
722
controlAndBindingFixture . detectChanges ( ) ;
769
723
@@ -1169,16 +1123,16 @@ class SimplePreselectedMatHorizontalStepperApp {
1169
1123
<mat-horizontal-stepper linear>
1170
1124
<mat-step
1171
1125
*ngFor="let step of steps"
1172
- [label]="step.label">
1173
- </mat-step>
1126
+ [label]="step.label"
1127
+ [completed]="step.completed"> </mat-step>
1174
1128
</mat-horizontal-stepper>
1175
1129
`
1176
1130
} )
1177
1131
class SimpleStepperWithoutStepControl {
1178
1132
steps = [
1179
- { label : 'One' } ,
1180
- { label : 'Two' } ,
1181
- { label : 'Three' }
1133
+ { label : 'One' , completed : false } ,
1134
+ { label : 'Two' , completed : false } ,
1135
+ { label : 'Three' , completed : false }
1182
1136
] ;
1183
1137
}
1184
1138
@@ -1188,16 +1142,16 @@ class SimpleStepperWithoutStepControl {
1188
1142
<mat-step
1189
1143
*ngFor="let step of steps"
1190
1144
[label]="step.label"
1191
- [stepControl]="step.control">
1192
- </mat-step>
1145
+ [stepControl]="step.control"
1146
+ [completed]="step.completed"> </mat-step>
1193
1147
</mat-horizontal-stepper>
1194
1148
`
1195
1149
} )
1196
1150
class SimpleStepperWithStepControlAndCompletedBinding {
1197
1151
steps = [
1198
- { label : 'One' , control : new FormControl ( ) } ,
1199
- { label : 'Two' , control : new FormControl ( ) } ,
1200
- { label : 'Three' , control : new FormControl ( ) }
1152
+ { label : 'One' , completed : false , control : new FormControl ( ) } ,
1153
+ { label : 'Two' , completed : false , control : new FormControl ( ) } ,
1154
+ { label : 'Three' , completed : false , control : new FormControl ( ) }
1201
1155
] ;
1202
1156
}
1203
1157
@@ -1209,12 +1163,10 @@ class SimpleStepperWithStepControlAndCompletedBinding {
1209
1163
<ng-template matStepperIcon="number" let-index="index">
1210
1164
{{getRomanNumeral(index + 1)}}
1211
1165
</ng-template>
1212
- <ng-template matStepperIcon="warning">Custom warning</ng-template>
1213
1166
1214
1167
<mat-step>Content 1</mat-step>
1215
1168
<mat-step>Content 2</mat-step>
1216
1169
<mat-step>Content 3</mat-step>
1217
- <mat-step state="warning">Content 4</mat-step>
1218
1170
</mat-horizontal-stepper>
1219
1171
`
1220
1172
} )
0 commit comments