@@ -2,7 +2,6 @@ import {TestBed, async} from '@angular/core/testing';
2
2
import { Component } from '@angular/core' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { MatProgressSpinnerModule } from './index' ;
5
- import { PROGRESS_SPINNER_STROKE_WIDTH } from './progress-spinner' ;
6
5
7
6
8
7
describe ( 'MatProgressSpinner' , ( ) => {
@@ -16,13 +15,10 @@ describe('MatProgressSpinner', () => {
16
15
ProgressSpinnerWithValueAndBoundMode ,
17
16
ProgressSpinnerWithColor ,
18
17
ProgressSpinnerCustomStrokeWidth ,
19
- IndeterminateProgressSpinnerWithNgIf ,
20
- SpinnerWithNgIf ,
21
- SpinnerWithColor
18
+ ProgressSpinnerCustomDiameter ,
19
+ SpinnerWithColor ,
22
20
] ,
23
- } ) ;
24
-
25
- TestBed . compileComponents ( ) ;
21
+ } ) . compileComponents ( ) ;
26
22
} ) ) ;
27
23
28
24
it ( 'should apply a mode of "determinate" if no mode is provided.' , ( ) => {
@@ -84,51 +80,57 @@ describe('MatProgressSpinner', () => {
84
80
expect ( progressComponent . value ) . toBe ( 0 ) ;
85
81
} ) ;
86
82
87
- it ( 'should clean up the indeterminate animation when the element is destroyed' , ( ) => {
88
- let fixture = TestBed . createComponent ( IndeterminateProgressSpinnerWithNgIf ) ;
89
- fixture . detectChanges ( ) ;
90
-
91
- let progressElement = fixture . debugElement . query ( By . css ( 'mat-progress-spinner' ) ) ;
92
- expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeTruthy ( ) ;
93
-
94
- fixture . componentInstance . isHidden = true ;
95
- fixture . detectChanges ( ) ;
96
- expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeFalsy ( ) ;
97
- } ) ;
83
+ it ( 'should allow a custom diameter' , ( ) => {
84
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomDiameter ) ;
85
+ const spinner = fixture . debugElement . query ( By . css ( 'mat-progress-spinner' ) ) . nativeElement ;
86
+ const svgElement = fixture . nativeElement . querySelector ( 'svg' ) ;
98
87
99
- it ( 'should clean up the animation when a spinner is destroyed' , ( ) => {
100
- let fixture = TestBed . createComponent ( SpinnerWithNgIf ) ;
88
+ fixture . componentInstance . diameter = 32 ;
101
89
fixture . detectChanges ( ) ;
102
90
103
- let progressElement = fixture . debugElement . query ( By . css ( 'mat-spinner' ) ) ;
91
+ expect ( parseInt ( spinner . style . width ) )
92
+ . toBe ( 32 , 'Expected the custom diameter to be applied to the host element width.' ) ;
93
+ expect ( parseInt ( spinner . style . height ) )
94
+ . toBe ( 32 , 'Expected the custom diameter to be applied to the host element height.' ) ;
95
+ expect ( parseInt ( svgElement . style . width ) )
96
+ . toBe ( 32 , 'Expected the custom diameter to be applied to the svg element width.' ) ;
97
+ expect ( parseInt ( svgElement . style . height ) )
98
+ . toBe ( 32 , 'Expected the custom diameter to be applied to the svg element height.' ) ;
99
+ expect ( svgElement . getAttribute ( 'viewBox' ) )
100
+ . toBe ( '0 0 32 32' , 'Expected the custom diameter to be applied to the svg viewBox.' ) ;
101
+ } ) ;
104
102
105
- expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeTruthy ( ) ;
103
+ it ( 'should allow a custom stroke width' , ( ) => {
104
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
105
+ const circleElement = fixture . nativeElement . querySelector ( 'circle' ) ;
106
106
107
- fixture . componentInstance . isHidden = true ;
107
+ fixture . componentInstance . strokeWidth = 40 ;
108
108
fixture . detectChanges ( ) ;
109
109
110
- expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeFalsy ( ) ;
110
+ expect ( parseInt ( circleElement . style . strokeWidth ) )
111
+ . toBe ( 40 , 'Expected the custom stroke width to be applied to the circle element.' ) ;
111
112
} ) ;
112
113
113
- it ( 'should set a default stroke width' , ( ) => {
114
- let fixture = TestBed . createComponent ( BasicProgressSpinner ) ;
115
- let pathElement = fixture . nativeElement . querySelector ( 'path ' ) ;
114
+ it ( 'should expand the host element if the stroke width is greater than the default ' , ( ) => {
115
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
116
+ const element = fixture . debugElement . nativeElement . querySelector ( '.mat-progress-spinner ' ) ;
116
117
118
+ fixture . componentInstance . strokeWidth = 40 ;
117
119
fixture . detectChanges ( ) ;
118
120
119
- expect ( parseInt ( pathElement . style . strokeWidth ) )
120
- . toBe ( PROGRESS_SPINNER_STROKE_WIDTH , 'Expected the default stroke-width to be applied. ') ;
121
+ expect ( element . style . width ) . toBe ( '130px' ) ;
122
+ expect ( element . style . height ) . toBe ( '130px ') ;
121
123
} ) ;
122
124
123
- it ( 'should allow a custom stroke width' , ( ) => {
124
- let fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
125
- let pathElement = fixture . nativeElement . querySelector ( 'path ' ) ;
125
+ it ( 'should not collapse the host element if the stroke width is less than the default ' , ( ) => {
126
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
127
+ const element = fixture . debugElement . nativeElement . querySelector ( '.mat-progress-spinner ' ) ;
126
128
127
- fixture . componentInstance . strokeWidth = 40 ;
129
+ fixture . componentInstance . strokeWidth = 5 ;
128
130
fixture . detectChanges ( ) ;
129
131
130
- expect ( parseInt ( pathElement . style . strokeWidth ) )
131
- . toBe ( 40 , 'Expected the custom stroke width to be applied to the path element. ') ;
132
+ expect ( element . style . width ) . toBe ( '100px' ) ;
133
+ expect ( element . style . height ) . toBe ( '100px ') ;
132
134
} ) ;
133
135
134
136
it ( 'should set the color class on the mat-spinner' , ( ) => {
@@ -161,23 +163,6 @@ describe('MatProgressSpinner', () => {
161
163
expect ( progressElement . nativeElement . classList ) . not . toContain ( 'mat-primary' ) ;
162
164
} ) ;
163
165
164
- it ( 'should re-render the circle when switching from indeterminate to determinate mode' , ( ) => {
165
- let fixture = TestBed . createComponent ( ProgressSpinnerWithValueAndBoundMode ) ;
166
- let progressElement = fixture . debugElement . query ( By . css ( 'mat-progress-spinner' ) ) . nativeElement ;
167
-
168
- fixture . componentInstance . mode = 'indeterminate' ;
169
- fixture . detectChanges ( ) ;
170
-
171
- let path = progressElement . querySelector ( 'path' ) ;
172
- let oldDimesions = path . getAttribute ( 'd' ) ;
173
-
174
- fixture . componentInstance . mode = 'determinate' ;
175
- fixture . detectChanges ( ) ;
176
-
177
- expect ( path . getAttribute ( 'd' ) ) . not
178
- . toBe ( oldDimesions , 'Expected circle dimensions to have changed.' ) ;
179
- } ) ;
180
-
181
166
it ( 'should remove the underlying SVG element from the tab order explicitly' , ( ) => {
182
167
const fixture = TestBed . createComponent ( BasicProgressSpinner ) ;
183
168
@@ -197,19 +182,17 @@ class ProgressSpinnerCustomStrokeWidth {
197
182
strokeWidth : number ;
198
183
}
199
184
185
+ @Component ( { template : '<mat-progress-spinner [diameter]="diameter"></mat-progress-spinner>' } )
186
+ class ProgressSpinnerCustomDiameter {
187
+ diameter : number ;
188
+ }
189
+
200
190
@Component ( { template : '<mat-progress-spinner mode="indeterminate"></mat-progress-spinner>' } )
201
191
class IndeterminateProgressSpinner { }
202
192
203
193
@Component ( { template : '<mat-progress-spinner value="50" [mode]="mode"></mat-progress-spinner>' } )
204
194
class ProgressSpinnerWithValueAndBoundMode { mode = 'indeterminate' ; }
205
195
206
- @Component ( { template : `
207
- <mat-progress-spinner mode="indeterminate" *ngIf="!isHidden"></mat-progress-spinner>` } )
208
- class IndeterminateProgressSpinnerWithNgIf { isHidden = false ; }
209
-
210
- @Component ( { template : `<mat-spinner *ngIf="!isHidden"></mat-spinner>` } )
211
- class SpinnerWithNgIf { isHidden = false ; }
212
-
213
196
@Component ( { template : `<mat-spinner [color]="color"></mat-spinner>` } )
214
197
class SpinnerWithColor { color : string = 'primary' ; }
215
198
0 commit comments