@@ -2,7 +2,6 @@ import {TestBed, async} from '@angular/core/testing';
22import { Component } from '@angular/core' ;
33import { By } from '@angular/platform-browser' ;
44import { MatProgressSpinnerModule } from './index' ;
5- import { PROGRESS_SPINNER_STROKE_WIDTH } from './progress-spinner' ;
65
76
87describe ( 'MatProgressSpinner' , ( ) => {
@@ -16,13 +15,10 @@ describe('MatProgressSpinner', () => {
1615 ProgressSpinnerWithValueAndBoundMode ,
1716 ProgressSpinnerWithColor ,
1817 ProgressSpinnerCustomStrokeWidth ,
19- IndeterminateProgressSpinnerWithNgIf ,
20- SpinnerWithNgIf ,
21- SpinnerWithColor
18+ ProgressSpinnerCustomDiameter ,
19+ SpinnerWithColor ,
2220 ] ,
23- } ) ;
24-
25- TestBed . compileComponents ( ) ;
21+ } ) . compileComponents ( ) ;
2622 } ) ) ;
2723
2824 it ( 'should apply a mode of "determinate" if no mode is provided.' , ( ) => {
@@ -84,51 +80,57 @@ describe('MatProgressSpinner', () => {
8480 expect ( progressComponent . value ) . toBe ( 0 ) ;
8581 } ) ;
8682
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' ) ;
9887
99- it ( 'should clean up the animation when a spinner is destroyed' , ( ) => {
100- let fixture = TestBed . createComponent ( SpinnerWithNgIf ) ;
88+ fixture . componentInstance . diameter = 32 ;
10189 fixture . detectChanges ( ) ;
10290
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+ } ) ;
104102
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' ) ;
106106
107- fixture . componentInstance . isHidden = true ;
107+ fixture . componentInstance . strokeWidth = 40 ;
108108 fixture . detectChanges ( ) ;
109109
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.' ) ;
111112 } ) ;
112113
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 ' ) ;
116117
118+ fixture . componentInstance . strokeWidth = 40 ;
117119 fixture . detectChanges ( ) ;
118120
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 ') ;
121123 } ) ;
122124
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 ' ) ;
126128
127- fixture . componentInstance . strokeWidth = 40 ;
129+ fixture . componentInstance . strokeWidth = 5 ;
128130 fixture . detectChanges ( ) ;
129131
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 ') ;
132134 } ) ;
133135
134136 it ( 'should set the color class on the mat-spinner' , ( ) => {
@@ -161,23 +163,6 @@ describe('MatProgressSpinner', () => {
161163 expect ( progressElement . nativeElement . classList ) . not . toContain ( 'mat-primary' ) ;
162164 } ) ;
163165
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-
181166 it ( 'should remove the underlying SVG element from the tab order explicitly' , ( ) => {
182167 const fixture = TestBed . createComponent ( BasicProgressSpinner ) ;
183168
@@ -197,19 +182,17 @@ class ProgressSpinnerCustomStrokeWidth {
197182 strokeWidth : number ;
198183}
199184
185+ @Component ( { template : '<mat-progress-spinner [diameter]="diameter"></mat-progress-spinner>' } )
186+ class ProgressSpinnerCustomDiameter {
187+ diameter : number ;
188+ }
189+
200190@Component ( { template : '<mat-progress-spinner mode="indeterminate"></mat-progress-spinner>' } )
201191class IndeterminateProgressSpinner { }
202192
203193@Component ( { template : '<mat-progress-spinner value="50" [mode]="mode"></mat-progress-spinner>' } )
204194class ProgressSpinnerWithValueAndBoundMode { mode = 'indeterminate' ; }
205195
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-
213196@Component ( { template : `<mat-spinner [color]="color"></mat-spinner>` } )
214197class SpinnerWithColor { color : string = 'primary' ; }
215198
0 commit comments