@@ -5,135 +5,132 @@ import {By} from '@angular/platform-browser';
5
5
import { MdButton , MdAnchor } from './button' ;
6
6
7
7
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 ( ) ;
8
44
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 ) ;
12
47
13
- beforeEach ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
14
- builder = tcb ;
15
- } ) ) ;
48
+ testComponent . buttonColor = 'accent' ;
49
+ fixture . detectChanges ( ) ;
16
50
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 ) => {
19
62
return builder . createAsync ( TestApp ) . then ( fixture => {
20
63
let testComponent = fixture . debugElement . componentInstance ;
21
64
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 ) ;
28
65
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 ) ;
33
68
done ( ) ;
34
69
} ) ;
35
70
} ) ;
36
71
37
- it ( 'should should not clear previous defined classes ' , ( done : ( ) => void ) => {
72
+ it ( 'should not increment if disabled ' , ( done : ( ) => void ) => {
38
73
return builder . createAsync ( TestApp ) . then ( fixture => {
39
74
let testComponent = fixture . debugElement . componentInstance ;
40
75
let buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ;
41
76
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 ;
51
78
fixture . detectChanges ( ) ;
52
79
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 ( ) ;
56
81
82
+ expect ( testComponent . clickCount ) . toBe ( 0 ) ;
57
83
done ( ) ;
58
84
} ) ;
59
85
} ) ;
60
86
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
+ } ) ;
78
88
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' ) ) ;
81
95
82
- buttonDebugElement . nativeElement . click ( ) ;
96
+ testComponent . isDisabled = true ;
97
+ fixture . detectChanges ( ) ;
83
98
84
- expect ( testComponent . clickCount ) . toBe ( 0 ) ;
85
- done ( ) ;
86
- } ) ;
99
+ buttonDebugElement . nativeElement . click ( ) ;
100
+ // will error if page reloads
101
+ done ( ) ;
87
102
} ) ;
88
-
89
103
} ) ;
90
104
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 ) ;
100
110
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 ( ) ;
105
115
} ) ;
116
+ } ) ;
106
117
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' ) ;
119
124
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 ( ) ;
132
129
} ) ;
133
-
134
130
} ) ;
131
+
135
132
} ) ;
136
- }
133
+ } ) ;
137
134
138
135
/** Test component that contains an MdButton. */
139
136
@Component ( {
0 commit comments