@@ -22,8 +22,8 @@ export function main() {
22
22
builder = tcb ;
23
23
} ) ) ;
24
24
25
- it ( 'should have same name as radio group' , ( done : ( ) => void ) => {
26
- builder
25
+ it ( 'should have same name as radio group' , ( ) => {
26
+ return builder
27
27
. overrideTemplate ( TestApp , `
28
28
<md-radio-group name="my_group">
29
29
<md-radio-button></md-radio-button>
@@ -34,11 +34,11 @@ export function main() {
34
34
35
35
fixture . detectChanges ( ) ;
36
36
expect ( button . componentInstance . name ) . toBe ( 'my_group' ) ;
37
- } ) . then ( done ) ;
37
+ } ) ;
38
38
} ) ;
39
39
40
- it ( 'should not allow click selection if disabled' , ( done : ( ) => void ) => {
41
- builder
40
+ it ( 'should not allow click selection if disabled' , ( ) => {
41
+ return builder
42
42
. overrideTemplate ( TestApp , '<md-radio-button disabled></md-radio-button>' )
43
43
. createAsync ( TestApp )
44
44
. then ( fixture => {
@@ -49,11 +49,11 @@ export function main() {
49
49
50
50
button . nativeElement . click ( ) ;
51
51
expect ( button . componentInstance . checked ) . toBe ( false ) ;
52
- } ) . then ( done ) ;
52
+ } ) ;
53
53
} ) ;
54
54
55
- it ( 'should be disabled if radio group disabled' , ( done : ( ) => void ) => {
56
- builder
55
+ it ( 'should be disabled if radio group disabled' , ( ) => {
56
+ return builder
57
57
. overrideTemplate ( TestApp , `
58
58
<md-radio-group disabled>
59
59
<md-radio-button></md-radio-button>
@@ -64,11 +64,11 @@ export function main() {
64
64
65
65
fixture . detectChanges ( ) ;
66
66
expect ( button . componentInstance . disabled ) . toBe ( true ) ;
67
- } ) . then ( done ) ;
67
+ } ) ;
68
68
} ) ;
69
69
70
- it ( 'updates parent group value when selected and value changed' , ( done : ( ) => void ) => {
71
- builder
70
+ it ( 'updates parent group value when selected and value changed' , ( ) => {
71
+ return builder
72
72
. overrideTemplate ( TestApp , `
73
73
<md-radio-group>
74
74
<md-radio-button value="1"></md-radio-button>
@@ -86,11 +86,11 @@ export function main() {
86
86
button . componentInstance . value = '2' ;
87
87
fixture . detectChanges ( ) ;
88
88
expect ( radioGroupInstance . value ) . toBe ( '2' ) ;
89
- } ) . then ( done ) ;
89
+ } ) ;
90
90
} ) ;
91
91
92
- it ( 'should be checked after input change event' , ( done : ( ) => void ) => {
93
- builder
92
+ it ( 'should be checked after input change event' , ( ) => {
93
+ return builder
94
94
. overrideTemplate ( TestApp , '<md-radio-button></md-radio-button>' )
95
95
. createAsync ( TestApp )
96
96
. then ( fixture => {
@@ -103,11 +103,11 @@ export function main() {
103
103
let event = createEvent ( 'change' ) ;
104
104
input . nativeElement . dispatchEvent ( event ) ;
105
105
expect ( button . componentInstance . checked ) . toBe ( true ) ;
106
- } ) . then ( done ) ;
106
+ } ) ;
107
107
} ) ;
108
108
109
- it ( 'should emit event when checked' , ( done : ( ) => void ) => {
110
- builder
109
+ it ( 'should emit event when checked' , ( ) => {
110
+ return builder
111
111
. overrideTemplate ( TestApp , '<md-radio-button></md-radio-button>' )
112
112
. createAsync ( TestApp )
113
113
. then ( fixture => {
@@ -124,11 +124,11 @@ export function main() {
124
124
expect ( changeEvent ) . not . toBe ( null ) ;
125
125
expect ( changeEvent . source ) . toBe ( button . componentInstance ) ;
126
126
} ) ;
127
- } ) . then ( done ) ;
127
+ } ) ;
128
128
} ) ;
129
129
130
- it ( 'should be focusable' , ( done : ( ) => void ) => {
131
- builder
130
+ it ( 'should be focusable' , ( ) => {
131
+ return builder
132
132
. overrideTemplate ( TestApp , '<md-radio-button></md-radio-button>' )
133
133
. createAsync ( TestApp )
134
134
. then ( fixture => {
@@ -147,7 +147,7 @@ export function main() {
147
147
input . nativeElement . dispatchEvent ( event ) ;
148
148
fixture . detectChanges ( ) ;
149
149
expect ( button . nativeElement . classList . contains ( 'md-radio-focused' ) ) . toBe ( false ) ;
150
- } ) . then ( done ) ;
150
+ } ) ;
151
151
} ) ;
152
152
} ) ;
153
153
@@ -183,8 +183,8 @@ export function main() {
183
183
builder = tcb ;
184
184
} ) ) ;
185
185
186
- it ( 'can select by value' , ( done : ( ) => void ) => {
187
- builder
186
+ it ( 'can select by value' , ( ) => {
187
+ return builder
188
188
. overrideTemplate ( TestApp , `
189
189
<md-radio-group>
190
190
<md-radio-button value="1"></md-radio-button>
@@ -203,11 +203,11 @@ export function main() {
203
203
204
204
fixture . detectChanges ( ) ;
205
205
expect ( radioGroupInstance . selected ) . toBe ( buttons [ 1 ] . componentInstance ) ;
206
- } ) . then ( done ) ;
206
+ } ) ;
207
207
} ) ;
208
208
209
- it ( 'should select uniquely' , ( done : ( ) => void ) => {
210
- builder
209
+ it ( 'should select uniquely' , ( ) => {
210
+ return builder
211
211
. overrideTemplate ( TestApp , `
212
212
<md-radio-group>
213
213
<md-radio-button></md-radio-button>
@@ -229,11 +229,11 @@ export function main() {
229
229
radioGroupInstance . selected = buttons [ 1 ] . componentInstance ;
230
230
fixture . detectChanges ( ) ;
231
231
expect ( isSinglySelected ( buttons [ 1 ] , buttons ) ) . toBe ( true ) ;
232
- } ) . then ( done ) ;
232
+ } ) ;
233
233
} ) ;
234
234
235
- it ( 'should emit event when value changes' , ( done : ( ) => void ) => {
236
- builder
235
+ it ( 'should emit event when value changes' , ( ) => {
236
+ return builder
237
237
. overrideTemplate ( TestApp , `
238
238
<md-radio-group>
239
239
<md-radio-button></md-radio-button>
@@ -258,11 +258,11 @@ export function main() {
258
258
expect ( changeEvent ) . not . toBe ( null ) ;
259
259
expect ( changeEvent . source ) . toBe ( buttons [ 1 ] . componentInstance ) ;
260
260
} ) ;
261
- } ) . then ( done ) ;
261
+ } ) ;
262
262
} ) ;
263
263
264
- it ( 'should bind value to model without initial value' , ( done : ( ) => void ) => {
265
- builder
264
+ it ( 'should bind value to model without initial value' , ( ) => {
265
+ return builder
266
266
. overrideTemplate ( TestApp , `
267
267
<md-radio-group [(ngModel)]="choice">
268
268
<md-radio-button [value]="0"></md-radio-button>
@@ -290,11 +290,11 @@ export function main() {
290
290
expect ( isSinglySelected ( buttons [ 1 ] , buttons ) ) . toBe ( true ) ;
291
291
expect ( fixture . componentInstance . choice ) . toBe ( 1 ) ;
292
292
} ) ;
293
- } ) . then ( done ) ;
293
+ } ) ;
294
294
} ) ;
295
295
296
- it ( 'should bind value to model with initial value' , ( done : ( ) => void ) => {
297
- builder
296
+ it ( 'should bind value to model with initial value' , ( ) => {
297
+ return builder
298
298
. overrideTemplate ( TestAppWithInitialValue , `
299
299
<md-radio-group [(ngModel)]="choice">
300
300
<md-radio-button [value]="0"></md-radio-button>
@@ -321,7 +321,29 @@ export function main() {
321
321
expect ( isSinglySelected ( buttons [ 1 ] , buttons ) ) . toBe ( true ) ;
322
322
expect ( fixture . componentInstance . choice ) . toBe ( 1 ) ;
323
323
} ) ;
324
- } ) . then ( done ) ;
324
+ } ) ;
325
+ } ) ;
326
+
327
+ it ( 'should deselect all buttons when model is null or undefined' , ( ) => {
328
+ return builder
329
+ . overrideTemplate ( TestAppWithInitialValue , `
330
+ <md-radio-group [ngModel]="choice">
331
+ <md-radio-button [value]="0"></md-radio-button>
332
+ <md-radio-button [value]="1"></md-radio-button>
333
+ </md-radio-group>
334
+ ` )
335
+ . createAsync ( TestAppWithInitialValue )
336
+ . then ( fixture => {
337
+ let buttons = fixture . debugElement . queryAll ( By . css ( 'md-radio-button' ) ) ;
338
+
339
+ fixture . componentInstance . choice = 0 ;
340
+ fixture . detectChanges ( ) ;
341
+ expect ( isSinglySelected ( buttons [ 0 ] , buttons ) ) . toBe ( true ) ;
342
+
343
+ fixture . componentInstance . choice = null ;
344
+ fixture . detectChanges ( ) ;
345
+ expect ( allDeselected ( buttons ) ) . toBe ( true ) ;
346
+ } ) ;
325
347
} ) ;
326
348
327
349
} ) ;
@@ -336,6 +358,10 @@ function isSinglySelected(button: DebugElement, buttons: DebugElement[]): boolea
336
358
return component . checked && otherSelectedButtons . length == 0 ;
337
359
}
338
360
361
+ function allDeselected ( buttons : DebugElement [ ] ) : boolean {
362
+ return buttons . every ( debugEl => ! debugEl . componentInstance . checked ) ;
363
+ }
364
+
339
365
/** Browser-agnostic function for creating an event. */
340
366
function createEvent ( name : string ) : Event {
341
367
let ev : Event ;
0 commit comments