@@ -3,6 +3,7 @@ import { IgxIconService } from './icon.service';
33import { DOCUMENT } from '@angular/common' ;
44
55import { configureTestSuite } from '../test-utils/configure-suite' ;
6+ import { first } from 'rxjs/operators' ;
67
78describe ( 'Icon Service' , ( ) => {
89 configureTestSuite ( ) ;
@@ -21,38 +22,38 @@ describe('Icon Service', () => {
2122 } ) ;
2223
2324 it ( 'should set the default icon set' , ( ) => {
24- const iconService = TestBed . get ( IgxIconService ) ;
25+ const iconService = TestBed . inject ( IgxIconService ) ;
2526
2627 expect ( ( ) => {
2728 iconService . defaultFontSet = MY_FONT ;
2829 } ) . not . toThrow ( ) ;
2930 } ) ;
3031
3132 it ( 'should get the default icon set' , ( ) => {
32- const iconService = TestBed . get ( IgxIconService ) ;
33+ const iconService = TestBed . inject ( IgxIconService ) ;
3334 iconService . defaultFontSet = MY_FONT ;
3435
3536 expect ( iconService . defaultFontSet ) . toBe ( MY_FONT ) ;
3637 } ) ;
3738
3839 it ( 'should associate alias name with icon set name' , ( ) => {
39- const iconService = TestBed . get ( IgxIconService ) ;
40+ const iconService = TestBed . inject ( IgxIconService ) ;
4041
4142 expect ( ( ) => {
4243 iconService . registerFontSetAlias ( ALIAS , MY_FONT ) ;
4344 } ) . not . toThrow ( ) ;
4445 } ) ;
4546
4647 it ( 'should get icon set name from alias name' , ( ) => {
47- const iconService = TestBed . get ( IgxIconService ) ;
48+ const iconService = TestBed . inject ( IgxIconService ) ;
4849 iconService . registerFontSetAlias ( ALIAS , MY_FONT ) ;
4950
5051 expect ( iconService . fontSetClassName ( ALIAS ) ) . toBe ( MY_FONT ) ;
5152 } ) ;
5253
5354 it ( 'should add custom svg icon from url' , ( ) => {
54- const iconService = TestBed . get ( IgxIconService ) as IgxIconService ;
55- const document = TestBed . get ( DOCUMENT ) ;
55+ const iconService = TestBed . inject ( IgxIconService ) as IgxIconService ;
56+ const document = TestBed . inject ( DOCUMENT ) ;
5657
5758 const iconName = 'test' ;
5859 const fontSet = 'svg-icons' ;
@@ -71,8 +72,8 @@ describe('Icon Service', () => {
7172 } ) ;
7273
7374 it ( 'should add custom svg icon from text' , ( ) => {
74- const iconService = TestBed . get ( IgxIconService ) as IgxIconService ;
75- const document = TestBed . get ( DOCUMENT ) ;
75+ const iconService = TestBed . inject ( IgxIconService ) as IgxIconService ;
76+ const document = TestBed . inject ( DOCUMENT ) ;
7677
7778 const iconName = 'test' ;
7879 const fontSet = 'svg-icons' ;
@@ -86,4 +87,28 @@ describe('Icon Service', () => {
8687 const svgElement = document . querySelector ( `svg[id='${ iconKey } ']` ) ;
8788 expect ( svgElement ) . toBeDefined ( ) ;
8889 } ) ;
90+
91+ it ( 'should emit loading event for a custom svg icon from url' , done => {
92+ const iconService = TestBed . inject ( IgxIconService ) as IgxIconService ;
93+
94+ iconService . iconLoaded . pipe ( first ( ) ) . subscribe ( event => {
95+ expect ( event . name ) . toMatch ( 'test' ) ;
96+ expect ( event . fontSet ) . toMatch ( 'svg-icons' ) ;
97+ done ( ) ;
98+ } ) ;
99+
100+ const iconName = 'test' ;
101+ const fontSet = 'svg-icons' ;
102+
103+ spyOn ( XMLHttpRequest . prototype , 'open' ) . and . callThrough ( ) ;
104+ spyOn ( XMLHttpRequest . prototype , 'send' ) . and . callFake ( ( ) => {
105+ ( iconService as any ) . _iconLoaded . next ( {
106+ name : iconName ,
107+ value : svgText ,
108+ fontSet : fontSet
109+ } ) ;
110+ } ) ;
111+
112+ iconService . addSvgIcon ( iconName , 'test.svg' , fontSet ) ;
113+ } ) ;
89114} ) ;
0 commit comments