@@ -2,7 +2,7 @@ import { Component, DebugElement } from '@angular/core';
22import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
33import { By } from '@angular/platform-browser' ;
44
5- import { MdcButton , MdcIcon , MdcIconModule , MdcButtonModule } from '@angular-mdc/web' ;
5+ import { MdcButton , MdcButtonLabel , MdcIcon , MdcIconModule , MdcButtonModule } from '@angular-mdc/web' ;
66
77describe ( 'MdcButton' , ( ) => {
88 let fixture : ComponentFixture < any > ;
@@ -13,7 +13,10 @@ describe('MdcButton', () => {
1313 declarations : [
1414 SimpleButton ,
1515 HrefButton ,
16- SimpleButtonWithIcon
16+ SimpleButtonWithIcon ,
17+ SimpleButtonWithTrailingIcon ,
18+ SimpleButtonWithTrailingIconLabelElement ,
19+ SimpleButtonWithTrailingIconLabelAttr
1720 ]
1821 } ) ;
1922 TestBed . compileComponents ( ) ;
@@ -102,6 +105,11 @@ describe('MdcButton', () => {
102105 fixture . detectChanges ( ) ;
103106 expect ( buttonNativeElement . disabled ) . toBeTruthy ( 'Expected button to be disabled' ) ;
104107 } ) ;
108+
109+ it ( '#should NOT have mdc-button-label by default' , ( ) => {
110+ expect ( fixture . debugElement . query ( By . directive ( MdcButtonLabel ) ) )
111+ . toBe ( null , 'Expected buttons not to have mdc-button-label by default' ) ;
112+ } ) ;
105113 } ) ;
106114
107115 // Anchor button tests
@@ -173,6 +181,38 @@ describe('MdcButton', () => {
173181 expect ( buttonDebugElement . nativeElement . classList . contains ( 'mdc-button__icon' ) ) . toBe ( true ) ;
174182 } ) ;
175183 } ) ;
184+
185+ // Trailing icon button tests
186+ describe ( 'mdc-button with trailing icon' , ( ) => {
187+ let buttonLabelDebugElement : DebugElement ;
188+
189+ it ( '#should have class mdc-button__label when using MdcButtonLabel attr' , ( ) => {
190+ fixture = TestBed . createComponent ( SimpleButtonWithTrailingIcon ) ;
191+ fixture . detectChanges ( ) ;
192+
193+ buttonLabelDebugElement = fixture . debugElement . query ( By . directive ( MdcButtonLabel ) ) ;
194+
195+ expect ( buttonLabelDebugElement . nativeElement . classList . contains ( 'mdc-button__label' ) ) . toBe ( true ) ;
196+ } ) ;
197+
198+ it ( '#should have class mdc-button__label when using MdcButtonLabel element' , ( ) => {
199+ fixture = TestBed . createComponent ( SimpleButtonWithTrailingIconLabelElement ) ;
200+ fixture . detectChanges ( ) ;
201+
202+ buttonLabelDebugElement = fixture . debugElement . query ( By . directive ( MdcButtonLabel ) ) ;
203+
204+ expect ( buttonLabelDebugElement . nativeElement . classList . contains ( 'mdc-button__label' ) ) . toBe ( true ) ;
205+ } ) ;
206+
207+ it ( '#should have class mdc-button__label when using MdcButton label attribute' , ( ) => {
208+ fixture = TestBed . createComponent ( SimpleButtonWithTrailingIconLabelAttr ) ;
209+ fixture . detectChanges ( ) ;
210+
211+ buttonLabelDebugElement = fixture . debugElement . query ( By . directive ( MdcButtonLabel ) ) ;
212+
213+ expect ( buttonLabelDebugElement . nativeElement . classList . contains ( 'mdc-button__label' ) ) . toBe ( true ) ;
214+ } ) ;
215+ } ) ;
176216} ) ;
177217
178218/** Simple component for testing. */
@@ -225,3 +265,32 @@ class HrefButton {
225265 ` ,
226266} )
227267class SimpleButtonWithIcon { }
268+
269+ @Component ( {
270+ template : `
271+ <button mdc-button>
272+ <span mdcButtonLabel>Search</span>
273+ <mdc-icon>search</mdc-icon>
274+ </button>
275+ ` ,
276+ } )
277+ class SimpleButtonWithTrailingIcon { }
278+
279+ @Component ( {
280+ template : `
281+ <button mdc-button>
282+ <mdc-button-label>Search</mdc-button-label>
283+ <mdc-icon>search</mdc-icon>
284+ </button>
285+ ` ,
286+ } )
287+ class SimpleButtonWithTrailingIconLabelElement { }
288+
289+ @Component ( {
290+ template : `
291+ <button mdc-button label="Search">
292+ <mdc-icon>search</mdc-icon>
293+ </button>
294+ ` ,
295+ } )
296+ class SimpleButtonWithTrailingIconLabelAttr { }
0 commit comments