1
- import { inject , async , fakeAsync , tick , TestBed } from '@angular/core/testing' ;
2
- import { SafeResourceUrl , DomSanitizer } from '@angular/platform-browser' ;
3
- import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
4
- import { Component } from '@angular/core' ;
5
- import { MatIconModule } from './index' ;
6
- import { MatIconRegistry , getMatIconNoHttpProviderError } from './icon-registry' ;
7
- import { FAKE_SVGS } from './fake-svgs' ;
8
- import { wrappedErrorMessage } from '@angular/cdk/testing' ;
1
+ import { inject , async , fakeAsync , tick , TestBed } from '@angular/core/testing' ;
2
+ import { SafeResourceUrl , DomSanitizer } from '@angular/platform-browser' ;
3
+ import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
4
+ import { Component } from '@angular/core' ;
5
+ import { MatIconModule } from './index' ;
6
+ import { MatIconRegistry , getMatIconNoHttpProviderError } from './icon-registry' ;
7
+ import { FAKE_SVGS } from './fake-svgs' ;
8
+ import { wrappedErrorMessage } from '@angular/cdk/testing' ;
9
9
10
10
11
11
/** Returns the CSS classes assigned to an element as a sorted array. */
@@ -50,6 +50,7 @@ describe('MatIcon', () => {
50
50
IconFromSvgName ,
51
51
IconWithAriaHiddenFalse ,
52
52
IconWithBindingAndNgIf ,
53
+ InlineIcon ,
53
54
]
54
55
} ) ;
55
56
@@ -82,14 +83,26 @@ describe('MatIcon', () => {
82
83
const fixture = TestBed . createComponent ( IconWithLigature ) ;
83
84
const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
84
85
expect ( iconElement . getAttribute ( 'aria-hidden' ) )
85
- . toBe ( 'true' , 'Expected the mat-icon element has aria-hidden="true" by default' ) ;
86
+ . toBe ( 'true' , 'Expected the mat-icon element has aria-hidden="true" by default' ) ;
86
87
} ) ;
87
88
88
89
it ( 'should not override a user-provided aria-hidden attribute' , ( ) => {
89
90
const fixture = TestBed . createComponent ( IconWithAriaHiddenFalse ) ;
90
91
const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
91
92
expect ( iconElement . getAttribute ( 'aria-hidden' ) )
92
- . toBe ( 'false' , 'Expected the mat-icon element has the user-provided aria-hidden value' ) ;
93
+ . toBe ( 'false' , 'Expected the mat-icon element has the user-provided aria-hidden value' ) ;
94
+ } ) ;
95
+
96
+ it ( 'should apply inline styling' , ( ) => {
97
+ const fixture = TestBed . createComponent ( InlineIcon ) ;
98
+ const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
99
+ expect ( iconElement . classList . contains ( 'mat-icon-inline' ) )
100
+ . toBeFalsy ( 'Expected the mat-icon element to not include the inline styling class' ) ;
101
+
102
+ fixture . debugElement . componentInstance . inline = true ;
103
+ fixture . detectChanges ( ) ;
104
+ expect ( iconElement . classList . contains ( 'mat-icon-inline' ) )
105
+ . toBeTruthy ( 'Expected the mat-icon element to include the inline styling class' ) ;
93
106
} ) ;
94
107
95
108
describe ( 'Ligature icons' , ( ) => {
@@ -216,8 +229,8 @@ describe('MatIcon', () => {
216
229
iconRegistry . addSvgIconSetInNamespace ( 'farm' , trust ( 'farm-set-1.svg' ) ) ;
217
230
218
231
// Requests for icons must be subscribed to in order for requests to be made.
219
- iconRegistry . getNamedSvgIcon ( 'pig' , 'farm' ) . subscribe ( ( ) => { } ) ;
220
- iconRegistry . getNamedSvgIcon ( 'cow' , 'farm' ) . subscribe ( ( ) => { } ) ;
232
+ iconRegistry . getNamedSvgIcon ( 'pig' , 'farm' ) . subscribe ( ( ) => { } ) ;
233
+ iconRegistry . getNamedSvgIcon ( 'cow' , 'farm' ) . subscribe ( ( ) => { } ) ;
221
234
222
235
http . expectOne ( 'farm-set-1.svg' ) . flush ( FAKE_SVGS . farmSet1 ) ;
223
236
@@ -462,7 +475,7 @@ describe('MatIcon without HttpClientModule', () => {
462
475
sanitizer = ds ;
463
476
} ) ) ;
464
477
465
- it ( 'should throw an error when trying to load a remote icon' , async ( ) => {
478
+ it ( 'should throw an error when trying to load a remote icon' , async ( ) => {
466
479
const expectedError = wrappedErrorMessage ( getMatIconNoHttpProviderError ( ) ) ;
467
480
468
481
expect ( ( ) => {
@@ -477,33 +490,38 @@ describe('MatIcon without HttpClientModule', () => {
477
490
} ) ;
478
491
479
492
480
- @Component ( { template : `<mat-icon>{{iconName}}</mat-icon>` } )
493
+ @Component ( { template : `<mat-icon>{{iconName}}</mat-icon>` } )
481
494
class IconWithLigature {
482
495
iconName = '' ;
483
496
}
484
497
485
- @Component ( { template : `<mat-icon [color]="iconColor">{{iconName}}</mat-icon>` } )
498
+ @Component ( { template : `<mat-icon [color]="iconColor">{{iconName}}</mat-icon>` } )
486
499
class IconWithColor {
487
500
iconName = '' ;
488
501
iconColor = 'primary' ;
489
502
}
490
503
491
- @Component ( { template : `<mat-icon [fontSet]="fontSet" [fontIcon]="fontIcon"></mat-icon>` } )
504
+ @Component ( { template : `<mat-icon [fontSet]="fontSet" [fontIcon]="fontIcon"></mat-icon>` } )
492
505
class IconWithCustomFontCss {
493
506
fontSet = '' ;
494
507
fontIcon = '' ;
495
508
}
496
509
497
- @Component ( { template : `<mat-icon [svgIcon]="iconName"></mat-icon>` } )
510
+ @Component ( { template : `<mat-icon [svgIcon]="iconName"></mat-icon>` } )
498
511
class IconFromSvgName {
499
512
iconName : string | undefined = '' ;
500
513
}
501
514
502
- @Component ( { template : '<mat-icon aria-hidden="false">face</mat-icon>' } )
515
+ @Component ( { template : '<mat-icon aria-hidden="false">face</mat-icon>' } )
503
516
class IconWithAriaHiddenFalse { }
504
517
505
- @Component ( { template : `<mat-icon [svgIcon]="iconName" *ngIf="showIcon">{{iconName}}</mat-icon>` } )
518
+ @Component ( { template : `<mat-icon [svgIcon]="iconName" *ngIf="showIcon">{{iconName}}</mat-icon>` } )
506
519
class IconWithBindingAndNgIf {
507
520
iconName = 'fluffy' ;
508
521
showIcon = true ;
509
522
}
523
+
524
+ @Component ( { template : `<mat-icon [inline]="inline">{{iconName}}</mat-icon>` } )
525
+ class InlineIcon {
526
+ inline = false ;
527
+ }
0 commit comments