@@ -5,135 +5,132 @@ import {By} from '@angular/platform-browser';
55import { MdButton , MdAnchor } from './button' ;
66
77
8+ describe ( 'MdButton' , ( ) => {
9+ let builder : TestComponentBuilder ;
10+
11+ beforeEach ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
12+ builder = tcb ;
13+ } ) ) ;
14+
15+ // General button tests
16+ it ( 'should apply class based on color attribute' , ( done : ( ) => void ) => {
17+ return builder . createAsync ( TestApp ) . then ( fixture => {
18+ let testComponent = fixture . debugElement . componentInstance ;
19+ let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
20+ let aDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
21+
22+ testComponent . buttonColor = 'primary' ;
23+ fixture . detectChanges ( ) ;
24+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
25+ expect ( aDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
26+
27+ testComponent . buttonColor = 'accent' ;
28+ fixture . detectChanges ( ) ;
29+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
30+ expect ( aDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
31+ done ( ) ;
32+ } ) ;
33+ } ) ;
34+
35+ it ( 'should should not clear previous defined classes' , ( done : ( ) => void ) => {
36+ return builder . createAsync ( TestApp ) . then ( fixture => {
37+ let testComponent = fixture . debugElement . componentInstance ;
38+ let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
39+
40+ buttonDebugElement . nativeElement . classList . add ( 'custom-class' ) ;
41+
42+ testComponent . buttonColor = 'primary' ;
43+ fixture . detectChanges ( ) ;
844
9- export function main ( ) {
10- describe ( 'MdButton' , ( ) => {
11- let builder : TestComponentBuilder ;
45+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
46+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
1247
13- beforeEach ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
14- builder = tcb ;
15- } ) ) ;
48+ testComponent . buttonColor = 'accent' ;
49+ fixture . detectChanges ( ) ;
1650
17- // General button tests
18- it ( 'should apply class based on color attribute' , ( done : ( ) => void ) => {
51+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( false ) ;
52+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
53+ expect ( buttonDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
54+
55+ done ( ) ;
56+ } ) ;
57+ } ) ;
58+
59+ // Regular button tests
60+ describe ( 'button[md-button]' , ( ) => {
61+ it ( 'should handle a click on the button' , ( done : ( ) => void ) => {
1962 return builder . createAsync ( TestApp ) . then ( fixture => {
2063 let testComponent = fixture . debugElement . componentInstance ;
2164 let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
22- let aDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
23-
24- testComponent . buttonColor = 'primary' ;
25- fixture . detectChanges ( ) ;
26- expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
27- expect ( aDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
2865
29- testComponent . buttonColor = 'accent' ;
30- fixture . detectChanges ( ) ;
31- expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
32- expect ( aDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
66+ buttonDebugElement . nativeElement . click ( ) ;
67+ expect ( testComponent . clickCount ) . toBe ( 1 ) ;
3368 done ( ) ;
3469 } ) ;
3570 } ) ;
3671
37- it ( 'should should not clear previous defined classes ' , ( done : ( ) => void ) => {
72+ it ( 'should not increment if disabled ' , ( done : ( ) => void ) => {
3873 return builder . createAsync ( TestApp ) . then ( fixture => {
3974 let testComponent = fixture . debugElement . componentInstance ;
4075 let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
4176
42- buttonDebugElement . nativeElement . classList . add ( 'custom-class' ) ;
43-
44- testComponent . buttonColor = 'primary' ;
45- fixture . detectChanges ( ) ;
46-
47- expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( true ) ;
48- expect ( buttonDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
49-
50- testComponent . buttonColor = 'accent' ;
77+ testComponent . isDisabled = true ;
5178 fixture . detectChanges ( ) ;
5279
53- expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-primary' ) ) . toBe ( false ) ;
54- expect ( buttonDebugElement . nativeElement . classList . contains ( 'md-accent' ) ) . toBe ( true ) ;
55- expect ( buttonDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
80+ buttonDebugElement . nativeElement . click ( ) ;
5681
82+ expect ( testComponent . clickCount ) . toBe ( 0 ) ;
5783 done ( ) ;
5884 } ) ;
5985 } ) ;
6086
61- // Regular button tests
62- describe ( 'button[md-button]' , ( ) => {
63- it ( 'should handle a click on the button' , ( done : ( ) => void ) => {
64- return builder . createAsync ( TestApp ) . then ( fixture => {
65- let testComponent = fixture . debugElement . componentInstance ;
66- let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
67-
68- buttonDebugElement . nativeElement . click ( ) ;
69- expect ( testComponent . clickCount ) . toBe ( 1 ) ;
70- done ( ) ;
71- } ) ;
72- } ) ;
73-
74- it ( 'should not increment if disabled' , ( done : ( ) => void ) => {
75- return builder . createAsync ( TestApp ) . then ( fixture => {
76- let testComponent = fixture . debugElement . componentInstance ;
77- let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
87+ } ) ;
7888
79- testComponent . isDisabled = true ;
80- fixture . detectChanges ( ) ;
89+ // Anchor button tests
90+ describe ( 'a[md-button]' , ( ) => {
91+ it ( 'should not redirect if disabled' , ( done : ( ) => void ) => {
92+ return builder . createAsync ( TestApp ) . then ( fixture => {
93+ let testComponent = fixture . debugElement . componentInstance ;
94+ let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
8195
82- buttonDebugElement . nativeElement . click ( ) ;
96+ testComponent . isDisabled = true ;
97+ fixture . detectChanges ( ) ;
8398
84- expect ( testComponent . clickCount ) . toBe ( 0 ) ;
85- done ( ) ;
86- } ) ;
99+ buttonDebugElement . nativeElement . click ( ) ;
100+ // will error if page reloads
101+ done ( ) ;
87102 } ) ;
88-
89103 } ) ;
90104
91- // Anchor button tests
92- describe ( 'a[md-button]' , ( ) => {
93- it ( 'should not redirect if disabled' , ( done : ( ) => void ) => {
94- return builder . createAsync ( TestApp ) . then ( fixture => {
95- let testComponent = fixture . debugElement . componentInstance ;
96- let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
97-
98- testComponent . isDisabled = true ;
99- fixture . detectChanges ( ) ;
105+ it ( 'should remove tabindex if disabled' , ( done : ( ) => void ) => {
106+ return builder . createAsync ( TestApp ) . then ( fixture => {
107+ let testComponent = fixture . debugElement . componentInstance ;
108+ let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
109+ expect ( buttonDebugElement . nativeElement . getAttribute ( 'tabIndex' ) ) . toBe ( null ) ;
100110
101- buttonDebugElement . nativeElement . click ( ) ;
102- // will error if page reloads
103- done ( ) ;
104- } ) ;
111+ testComponent . isDisabled = true ;
112+ fixture . detectChanges ( ) ;
113+ expect ( buttonDebugElement . nativeElement . getAttribute ( 'tabIndex' ) ) . toBe ( '-1' ) ;
114+ done ( ) ;
105115 } ) ;
116+ } ) ;
106117
107- it ( 'should remove tabindex if disabled' , ( done : ( ) => void ) => {
108- return builder . createAsync ( TestApp ) . then ( fixture => {
109- let testComponent = fixture . debugElement . componentInstance ;
110- let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
111- expect ( buttonDebugElement . nativeElement . getAttribute ( 'tabIndex' ) ) . toBe ( null ) ;
112-
113- testComponent . isDisabled = true ;
114- fixture . detectChanges ( ) ;
115- expect ( buttonDebugElement . nativeElement . getAttribute ( 'tabIndex' ) ) . toBe ( '-1' ) ;
116- done ( ) ;
117- } ) ;
118- } ) ;
118+ it ( 'should add aria-disabled attribute if disabled' , ( done : ( ) => void ) => {
119+ return builder . createAsync ( TestApp ) . then ( fixture => {
120+ let testComponent = fixture . debugElement . componentInstance ;
121+ let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
122+ fixture . detectChanges ( ) ;
123+ expect ( buttonDebugElement . nativeElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
119124
120- it ( 'should add aria-disabled attribute if disabled' , ( done : ( ) => void ) => {
121- return builder . createAsync ( TestApp ) . then ( fixture => {
122- let testComponent = fixture . debugElement . componentInstance ;
123- let buttonDebugElement = fixture . debugElement . query ( By . css ( 'a' ) ) ;
124- fixture . detectChanges ( ) ;
125- expect ( buttonDebugElement . nativeElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
126-
127- testComponent . isDisabled = true ;
128- fixture . detectChanges ( ) ;
129- expect ( buttonDebugElement . nativeElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
130- done ( ) ;
131- } ) ;
125+ testComponent . isDisabled = true ;
126+ fixture . detectChanges ( ) ;
127+ expect ( buttonDebugElement . nativeElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
128+ done ( ) ;
132129 } ) ;
133-
134130 } ) ;
131+
135132 } ) ;
136- }
133+ } ) ;
137134
138135/** Test component that contains an MdButton. */
139136@Component ( {
0 commit comments