@@ -25,67 +25,112 @@ describe('mdIcon directive', function() {
25
25
26
26
it ( 'should render correct HTML with md-font-icon value as class' , function ( ) {
27
27
el = make ( '<md-icon md-font-icon="android"></md-icon>' ) ;
28
- expect ( el . html ( ) ) . toEqual ( '<span class="md-font android" ng-class="fontIcon"></span>' ) ;
28
+
29
+ expect ( el . html ( ) ) . toEqual ( '' ) ;
30
+ expect ( clean ( el . attr ( 'class' ) ) ) . toEqual ( "md-font android" ) ;
31
+
29
32
} ) ;
30
33
31
34
it ( 'should transclude class specifiers' , function ( ) {
32
35
el = make ( '<md-icon md-font-icon="android" class="material-icons"></md-icon>' ) ;
33
- expect ( el . html ( ) ) . toEqual ( '<span class="md-font material-icons android" ng-class="fontIcon"></span>' ) ;
36
+
37
+ expect ( el . html ( ) ) . toEqual ( '' ) ;
38
+ expect ( el . hasClass ( 'md-font' ) ) . toBe ( true ) ;
39
+ expect ( el . hasClass ( 'android' ) ) . toBe ( true ) ;
40
+ expect ( el . hasClass ( 'material-icons' ) ) . toBe ( true ) ;
34
41
} ) ;
35
42
36
43
it ( 'should not render any inner content if the md-font-icon value is empty' , function ( ) {
37
44
el = make ( '<md-icon md-font-icon=""></md-icon>' ) ;
38
45
expect ( el . html ( ) ) . toEqual ( '' ) ;
39
46
} ) ;
40
47
48
+ it ( '' , function ( ) {
49
+ el = make ( '\
50
+ <md-icon \
51
+ md-font-icon="{{ font.name }}" \
52
+ aria-label="{{ font.name + font.size }}" \
53
+ class="step" > \
54
+ </md-icon> \
55
+ ' ) ;
56
+
57
+ $scope . $apply ( function ( ) {
58
+ $scope . font = {
59
+ name : 'icon-home' ,
60
+ color : "#777" ,
61
+ size : 48
62
+ } ;
63
+ } ) ;
64
+
65
+ expect ( el . attr ( 'md-font-icon' ) ) . toBe ( $scope . font . name ) ;
66
+ expect ( el . hasClass ( 'step' ) ) . toBe ( true ) ;
67
+ expect ( el . hasClass ( 'material-icons' ) ) . toBe ( true ) ;
68
+ expect ( el . attr ( 'aria-label' ) ) . toBe ( $scope . font . name + $scope . font . size ) ;
69
+ expect ( el . attr ( 'role' ) ) . toBe ( 'img' ) ;
70
+ } )
71
+
41
72
} ) ;
42
73
43
74
describe ( 'using font-icons with ligatures: md-font-set=""' , function ( ) {
44
75
45
76
it ( 'should render correct HTML with ligatures' , function ( ) {
46
77
el = make ( '<md-icon class="md-48">face</md-icon>' ) ;
47
- expect ( el . html ( ) ) . toEqual ( '<span class="material-icons md-48" ng-transclude=""><span class="ng-scope">face</span></span>' ) ;
78
+
79
+ expect ( el . text ( ) ) . toEqual ( 'face' ) ;
80
+ expect ( el . hasClass ( 'material-icons' ) ) . toBeTruthy ( ) ;
81
+ expect ( el . hasClass ( 'md-48' ) ) . toBeTruthy ( ) ;
48
82
} ) ;
49
83
50
84
it ( 'should render correctly using a md-font-set alias' , function ( ) {
51
85
$mdIconProvider . fontSet ( 'fa' , 'fontawesome' ) ;
52
86
53
87
el = make ( '<md-icon md-font-set="fa">email</md-icon>' ) ;
54
- expect ( el . html ( ) ) . toEqual ( '<span class="fontawesome" ng-transclude=""><span class="ng-scope">email</span></span>' ) ;
88
+
89
+ expect ( el . text ( ) ) . toEqual ( 'email' ) ;
90
+ expect ( clean ( el . attr ( 'class' ) ) ) . toEqual ( "fontawesome" ) ;
55
91
} ) ;
56
92
57
93
it ( 'should render correctly using md-font-set value as class' , function ( ) {
58
94
59
95
el = make ( '<md-icon md-font-set="fontawesome">email</md-icon>' ) ;
60
- expect ( el . html ( ) ) . toEqual ( '<span class="fontawesome" ng-transclude=""><span class="ng-scope">email</span></span>' ) ;
96
+
97
+ expect ( el . text ( ) ) . toEqual ( 'email' ) ;
98
+ expect ( clean ( el . attr ( 'class' ) ) ) . toEqual ( "fontawesome" ) ;
61
99
} ) ;
62
100
} ) ;
63
101
64
102
describe ( 'using font-icons with classnames' , function ( ) {
65
103
66
104
it ( 'should render with icon classname' , function ( ) {
67
105
el = make ( '<md-icon class="custom-cake"></md-icon>' ) ;
68
- expect ( el . html ( ) ) . toEqual ( '<span class="material-icons custom-cake" ng-transclude=""></span>' ) ;
106
+
107
+ expect ( el . text ( ) ) . toEqual ( '' ) ;
108
+ expect ( el . hasClass ( 'material-icons' ) ) . toBeTruthy ( ) ;
109
+ expect ( el . hasClass ( 'custom-cake' ) ) . toBeTruthy ( ) ;
69
110
} ) ;
70
111
71
112
it ( 'should support clearing default fontset' , function ( ) {
72
113
$mdIconProvider . defaultFontSet ( '' ) ;
73
114
74
115
el = make ( '<md-icon class="custom-cake"></md-icon>' ) ;
75
- expect ( el . html ( ) ) . toEqual ( '<span class= "custom-cake" ng-transclude=""></span>' ) ;
116
+ expect ( clean ( el . attr ( 'class' ) ) ) . toEqual ( "custom-cake" ) ;
76
117
77
118
el = make ( '<md-icon class="custom-cake">apple</md-icon>' ) ;
78
- expect ( el . html ( ) ) . toEqual ( '<span class="custom-cake" ng-transclude=""><span class="ng-scope">apple</span></span>' ) ;
119
+ expect ( el . text ( ) ) . toEqual ( 'apple' ) ;
120
+ expect ( clean ( el . attr ( 'class' ) ) ) . toEqual ( "custom-cake" ) ;
79
121
80
122
} ) ;
81
123
82
124
it ( 'should support clearing an invalid font alias' , function ( ) {
83
125
84
126
el = make ( '<md-icon md-font-set="none" class="custom-cake"></md-icon>' ) ;
85
- expect ( el . html ( ) ) . toEqual ( '<span class="none custom-cake" ng-transclude=""></span>' ) ;
127
+ expect ( el . hasClass ( 'none' ) ) . toBeTruthy ( ) ;
128
+ expect ( el . hasClass ( 'custom-cake' ) ) . toBeTruthy ( ) ;
86
129
87
130
el = make ( '<md-icon md-font-set="none" class="custom-cake">apple</md-icon>' ) ;
88
- expect ( el . html ( ) ) . toEqual ( '<span class="none custom-cake" ng-transclude=""><span class="ng-scope">apple</span></span>' ) ;
131
+ expect ( el . text ( ) ) . toEqual ( 'apple' ) ;
132
+ expect ( el . hasClass ( 'none' ) ) . toBeTruthy ( ) ;
133
+ expect ( el . hasClass ( 'custom-cake' ) ) . toBeTruthy ( ) ;
89
134
90
135
} ) ;
91
136
} ) ;
@@ -224,5 +269,16 @@ describe('mdIcon directive', function() {
224
269
return el ;
225
270
}
226
271
272
+ /**
273
+ * Utility to remove extra attributes to the specs are easy to compare
274
+ */
275
+ function clean ( style ) {
276
+ return style
277
+ . replace ( / n g - s c o p e | n g - i s o l a t e - s c o p e | m d - d e f a u l t - t h e m e / gi, '' )
278
+ . replace ( / \s \s + / g, ' ' )
279
+ . replace ( / \s + \" / g, '"' )
280
+ . trim ( ) ;
281
+ }
282
+
227
283
228
284
} ) ;
0 commit comments