@@ -352,7 +352,28 @@ export function main() {
352
352
} ) ;
353
353
} ) . then ( done ) ;
354
354
} ) ;
355
+ it ( 'should deselect all buttons when model is null or undefined' , ( done : ( ) => void ) => {
356
+ builder
357
+ . overrideTemplate ( TestAppWithInitialValue , `
358
+ <md-radio-group [(ngModel)]="choice">
359
+ <md-radio-button [value]="0"></md-radio-button>
360
+ <md-radio-button [value]="1"></md-radio-button>
361
+ </md-radio-group>` )
362
+ . createAsync ( TestAppWithInitialValue )
363
+ . then ( fixture => {
364
+ fakeAsync ( function ( ) {
365
+ let buttons = fixture . debugElement . queryAll ( By . css ( 'md-radio-button' ) ) ;
355
366
367
+ fixture . detectChanges ( ) ;
368
+ fixture . componentInstance . choice = 0 ;
369
+ expect ( isSinglySelected ( buttons [ 0 ] , buttons ) ) . toBe ( true ) ;
370
+
371
+ fixture . detectChanges ( ) ;
372
+ fixture . componentInstance . choice = null ;
373
+ expect ( allDeselected ( buttons ) ) . toBe ( true ) ;
374
+ } ) ;
375
+ } ) . then ( done ) ;
376
+ } ) ;
356
377
} ) ;
357
378
}
358
379
@@ -365,6 +386,13 @@ function isSinglySelected(button: DebugElement, buttons: DebugElement[]): boolea
365
386
return component . checked && otherSelectedButtons . length == 0 ;
366
387
}
367
388
389
+ /** Checks whether no button is selected from a group of buttons. */
390
+ function allDeselected ( buttons : DebugElement [ ] ) : boolean {
391
+ let selectedButtons =
392
+ buttons . filter ( ( e : DebugElement ) => e . componentInstance . checked ) ;
393
+ return selectedButtons . length == 0 ;
394
+ }
395
+
368
396
/** Browser-agnostic function for creating an event. */
369
397
function createEvent ( name : string ) : Event {
370
398
let ev : Event ;
0 commit comments