@@ -352,7 +352,28 @@ export function main() {
352352 } ) ;
353353 } ) . then ( done ) ;
354354 } ) ;
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' ) ) ;
355366
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+ } ) ;
356377 } ) ;
357378}
358379
@@ -365,6 +386,13 @@ function isSinglySelected(button: DebugElement, buttons: DebugElement[]): boolea
365386 return component . checked && otherSelectedButtons . length == 0 ;
366387}
367388
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+
368396/** Browser-agnostic function for creating an event. */
369397function createEvent ( name : string ) : Event {
370398 let ev : Event ;
0 commit comments