@@ -259,7 +259,7 @@ export function main() {
259
259
} ) . then ( done ) ;
260
260
} ) ;
261
261
262
- it ( 'should bind value to model' , ( done : ( ) => void ) => {
262
+ it ( 'should bind value to model without initial value ' , ( done : ( ) => void ) => {
263
263
builder
264
264
. overrideTemplate ( TestApp , `
265
265
<md-radio-group [(ngModel)]="choice">
@@ -272,6 +272,37 @@ export function main() {
272
272
let buttons = fixture . debugElement . queryAll ( By . css ( 'md-radio-button' ) ) ;
273
273
let group = fixture . debugElement . query ( By . css ( 'md-radio-group' ) ) ;
274
274
275
+ fixture . detectChanges ( ) ;
276
+ expect ( buttons [ 0 ] . componentInstance . checked ) . toBe ( false ) ;
277
+ expect ( buttons [ 1 ] . componentInstance . checked ) . toBe ( false ) ;
278
+ expect ( fixture . componentInstance . choice ) . toBe ( undefined ) ;
279
+
280
+ group . componentInstance . selected = buttons [ 0 ] . componentInstance ;
281
+ fixture . detectChanges ( ) ;
282
+ expect ( isSinglySelected ( buttons [ 0 ] , buttons ) ) . toBe ( true ) ;
283
+ expect ( fixture . componentInstance . choice ) . toBe ( 0 ) ;
284
+
285
+ group . componentInstance . selected = buttons [ 1 ] . componentInstance ;
286
+ fixture . detectChanges ( ) ;
287
+ expect ( isSinglySelected ( buttons [ 1 ] , buttons ) ) . toBe ( true ) ;
288
+ expect ( fixture . componentInstance . choice ) . toBe ( 1 ) ;
289
+ } ) ;
290
+ } ) . then ( done ) ;
291
+ } ) ;
292
+
293
+ it ( 'should bind value to model with initial value' , ( done : ( ) => void ) => {
294
+ builder
295
+ . overrideTemplate ( TestAppWithInitialValue , `
296
+ <md-radio-group [(ngModel)]="choice">
297
+ <md-radio-button [value]="0"></md-radio-button>
298
+ <md-radio-button [value]="1"></md-radio-button>
299
+ </md-radio-group>` )
300
+ . createAsync ( TestAppWithInitialValue )
301
+ . then ( ( fixture ) => {
302
+ fakeAsync ( function ( ) {
303
+ let buttons = fixture . debugElement . queryAll ( By . css ( 'md-radio-button' ) ) ;
304
+ let group = fixture . debugElement . query ( By . css ( 'md-radio-group' ) ) ;
305
+
275
306
fixture . detectChanges ( ) ;
276
307
expect ( isSinglySelected ( buttons [ 1 ] , buttons ) ) . toBe ( true ) ;
277
308
expect ( fixture . componentInstance . choice ) . toBe ( 1 ) ;
@@ -288,6 +319,7 @@ export function main() {
288
319
} ) ;
289
320
} ) . then ( done ) ;
290
321
} ) ;
322
+
291
323
} ) ;
292
324
}
293
325
@@ -320,5 +352,15 @@ function createEvent(name: string): Event {
320
352
template : ''
321
353
} )
322
354
class TestApp {
355
+ choice : number ;
356
+ }
357
+
358
+ /** Test component. */
359
+ @Component ( {
360
+ directives : [ MdRadioButton , MdRadioGroup ] ,
361
+ providers : [ MdRadioDispatcher ] ,
362
+ template : ''
363
+ } )
364
+ class TestAppWithInitialValue {
323
365
choice : number = 1 ;
324
366
}
0 commit comments