@@ -16,6 +16,7 @@ describe('MatProgressSpinner', () => {
16
16
declarations : [
17
17
BasicProgressSpinner ,
18
18
IndeterminateProgressSpinner ,
19
+ IndeterminateSpinnerCustomDiameter ,
19
20
ProgressSpinnerWithValueAndBoundMode ,
20
21
ProgressSpinnerWithColor ,
21
22
ProgressSpinnerCustomStrokeWidth ,
@@ -185,6 +186,48 @@ describe('MatProgressSpinner', () => {
185
186
expect ( document . head . querySelectorAll ( 'style[mat-spinner-animation="64"]' ) . length ) . toBe ( 1 ) ;
186
187
} ) ) ;
187
188
189
+ it ( 'should allow floating point values for custom diameter' , ( ) => {
190
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomDiameter ) ;
191
+
192
+ fixture . componentInstance . diameter = 32.5 ;
193
+ fixture . detectChanges ( ) ;
194
+
195
+ const spinner = fixture . debugElement . query ( By . css ( 'mat-progress-spinner' ) ) ! . nativeElement ;
196
+ const svgElement = fixture . nativeElement . querySelector ( 'svg' ) ;
197
+
198
+ expect ( parseFloat ( spinner . style . width ) )
199
+ . toBe ( 32.5 , 'Expected the custom diameter to be applied to the host element width.' ) ;
200
+ expect ( parseFloat ( spinner . style . height ) )
201
+ . toBe ( 32.5 , 'Expected the custom diameter to be applied to the host element height.' ) ;
202
+ expect ( parseFloat ( svgElement . style . width ) )
203
+ . toBe ( 32.5 , 'Expected the custom diameter to be applied to the svg element width.' ) ;
204
+ expect ( parseFloat ( svgElement . style . height ) )
205
+ . toBe ( 32.5 , 'Expected the custom diameter to be applied to the svg element height.' ) ;
206
+ expect ( svgElement . getAttribute ( 'viewBox' ) )
207
+ . toBe ( '0 0 25.75 25.75' , 'Expected the custom diameter to be applied to the svg viewBox.' ) ;
208
+ } ) ;
209
+
210
+ it ( 'should handle creating animation style tags based on a floating point diameter' ,
211
+ inject ( [ Platform ] , ( platform : Platform ) => {
212
+ // On Edge and IE we use a fallback animation because the
213
+ // browser doesn't support animating SVG correctly.
214
+ if ( platform . EDGE || platform . TRIDENT ) {
215
+ return ;
216
+ }
217
+
218
+ const fixture = TestBed . createComponent ( IndeterminateSpinnerCustomDiameter ) ;
219
+
220
+ fixture . componentInstance . diameter = 32.5 ;
221
+ fixture . detectChanges ( ) ;
222
+
223
+ const circleElement = fixture . nativeElement . querySelector ( 'circle' ) ;
224
+
225
+ expect ( circleElement . style . animationName ) . toBe ( 'mat-progress-spinner-stroke-rotate-32_5' ,
226
+ 'Expected the spinner circle element to have an animation name based on the custom diameter' ) ;
227
+ expect ( document . head . querySelectorAll ( 'style[mat-spinner-animation="32_5"]' ) . length ) . toBe ( 1 ,
228
+ 'Expected a style tag with the indeterminate animation to be attached to the document head' ) ;
229
+ } ) ) ;
230
+
188
231
it ( 'should allow a custom stroke width' , ( ) => {
189
232
const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
190
233
@@ -200,6 +243,21 @@ describe('MatProgressSpinner', () => {
200
243
. toBe ( '0 0 130 130' , 'Expected the viewBox to be adjusted based on the stroke width.' ) ;
201
244
} ) ;
202
245
246
+ it ( 'should allow floating point values for custom stroke width' , ( ) => {
247
+ const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
248
+
249
+ fixture . componentInstance . strokeWidth = 40.5 ;
250
+ fixture . detectChanges ( ) ;
251
+
252
+ const circleElement = fixture . nativeElement . querySelector ( 'circle' ) ;
253
+ const svgElement = fixture . nativeElement . querySelector ( 'svg' ) ;
254
+
255
+ expect ( parseFloat ( circleElement . style . strokeWidth ) ) . toBe ( 40.5 , 'Expected the custom stroke ' +
256
+ 'width to be applied to the circle element as a percentage of the element size.' ) ;
257
+ expect ( svgElement . getAttribute ( 'viewBox' ) )
258
+ . toBe ( '0 0 130.5 130.5' , 'Expected the viewBox to be adjusted based on the stroke width.' ) ;
259
+ } ) ;
260
+
203
261
it ( 'should expand the host element if the stroke width is greater than the default' , ( ) => {
204
262
const fixture = TestBed . createComponent ( ProgressSpinnerCustomStrokeWidth ) ;
205
263
const element = fixture . debugElement . nativeElement . querySelector ( '.mat-progress-spinner' ) ;
@@ -444,6 +502,15 @@ class ProgressSpinnerCustomDiameter {
444
502
@Component ( { template : '<mat-progress-spinner mode="indeterminate"></mat-progress-spinner>' } )
445
503
class IndeterminateProgressSpinner { }
446
504
505
+ @Component ( {
506
+ template : `
507
+ <mat-progress-spinner mode="indeterminate" [diameter]="diameter"></mat-progress-spinner>
508
+ ` ,
509
+ } )
510
+ class IndeterminateSpinnerCustomDiameter {
511
+ diameter : number ;
512
+ }
513
+
447
514
@Component ( {
448
515
template : '<mat-progress-spinner [value]="value" [mode]="mode"></mat-progress-spinner>'
449
516
} )
0 commit comments