@@ -10,6 +10,7 @@ import {
1010 dispatchEvent ,
1111 fakeAsync ,
1212 tick ,
13+ flushMicrotasks ,
1314 expect ,
1415 it ,
1516 inject ,
@@ -31,7 +32,8 @@ import {
3132 NgFor ,
3233 NgForm ,
3334 Validators ,
34- Validator
35+ Validator ,
36+ RadioButtonState
3537} from 'angular2/common' ;
3638import { Provider , forwardRef , Input } from 'angular2/core' ;
3739import { By } from 'angular2/platform/browser' ;
@@ -328,6 +330,33 @@ export function main() {
328330 } ) ;
329331 } ) ) ;
330332
333+ it ( "should support <type=radio>" ,
334+ inject ( [ TestComponentBuilder , AsyncTestCompleter ] , ( tcb : TestComponentBuilder , async ) => {
335+ var t = `<form [ngFormModel]="form">
336+ <input type="radio" ngControl="foodChicken" name="food">
337+ <input type="radio" ngControl="foodFish" name="food">
338+ </form>` ;
339+
340+ tcb . overrideTemplate ( MyComp , t ) . createAsync ( MyComp ) . then ( ( fixture ) => {
341+ fixture . debugElement . componentInstance . form = new ControlGroup ( {
342+ "foodChicken" : new Control ( new RadioButtonState ( false , 'chicken' ) ) ,
343+ "foodFish" : new Control ( new RadioButtonState ( true , 'fish' ) )
344+ } ) ;
345+ fixture . detectChanges ( ) ;
346+
347+ var input = fixture . debugElement . query ( By . css ( "input" ) ) ;
348+ expect ( input . nativeElement . checked ) . toEqual ( false ) ;
349+
350+ dispatchEvent ( input . nativeElement , "change" ) ;
351+ fixture . detectChanges ( ) ;
352+
353+ let value = fixture . debugElement . componentInstance . form . value ;
354+ expect ( value [ 'foodChicken' ] . checked ) . toEqual ( true ) ;
355+ expect ( value [ 'foodFish' ] . checked ) . toEqual ( false ) ;
356+ async . done ( ) ;
357+ } ) ;
358+ } ) ) ;
359+
331360 it ( "should support <select>" ,
332361 inject ( [ TestComponentBuilder , AsyncTestCompleter ] , ( tcb : TestComponentBuilder , async ) => {
333362 var t = `<div [ngFormModel]="form">
@@ -812,9 +841,50 @@ export function main() {
812841
813842 expect ( fixture . debugElement . componentInstance . name ) . toEqual ( "updatedValue" ) ;
814843 } ) ) ) ;
815- } ) ;
816844
817845
846+ it ( "should support <type=radio>" ,
847+ inject ( [ TestComponentBuilder ] , fakeAsync ( ( tcb : TestComponentBuilder ) => {
848+ var t = `<form>
849+ <input type="radio" name="food" ngControl="chicken" [(ngModel)]="data['chicken1']">
850+ <input type="radio" name="food" ngControl="fish" [(ngModel)]="data['fish1']">
851+ </form>
852+
853+ <form>
854+ <input type="radio" name="food" ngControl="chicken" [(ngModel)]="data['chicken2']">
855+ <input type="radio" name="food" ngControl="fish" [(ngModel)]="data['fish2']">
856+ </form>` ;
857+
858+ var fixture : ComponentFixture ;
859+ tcb . overrideTemplate ( MyComp , t ) . createAsync ( MyComp ) . then ( ( f ) => { fixture = f ; } ) ;
860+ tick ( ) ;
861+
862+ fixture . debugElement . componentInstance . data = {
863+ 'chicken1' : new RadioButtonState ( false , 'chicken' ) ,
864+ 'fish1' : new RadioButtonState ( true , 'fish' ) ,
865+
866+ 'chicken2' : new RadioButtonState ( false , 'chicken' ) ,
867+ 'fish2' : new RadioButtonState ( true , 'fish' )
868+ } ;
869+ fixture . detectChanges ( ) ;
870+ tick ( ) ;
871+
872+ var input = fixture . debugElement . query ( By . css ( "input" ) ) ;
873+ expect ( input . nativeElement . checked ) . toEqual ( false ) ;
874+
875+ dispatchEvent ( input . nativeElement , "change" ) ;
876+ tick ( ) ;
877+
878+ let data = fixture . debugElement . componentInstance . data ;
879+
880+ expect ( data [ 'chicken1' ] ) . toEqual ( new RadioButtonState ( true , 'chicken' ) ) ;
881+ expect ( data [ 'fish1' ] ) . toEqual ( new RadioButtonState ( false , 'fish' ) ) ;
882+
883+ expect ( data [ 'chicken2' ] ) . toEqual ( new RadioButtonState ( false , 'chicken' ) ) ;
884+ expect ( data [ 'fish2' ] ) . toEqual ( new RadioButtonState ( true , 'fish' ) ) ;
885+ } ) ) ) ;
886+ } ) ;
887+
818888 describe ( "setting status classes" , ( ) => {
819889 it ( "should work with single fields" ,
820890 inject ( [ TestComponentBuilder , AsyncTestCompleter ] , ( tcb : TestComponentBuilder , async ) => {
0 commit comments