@@ -6,7 +6,7 @@ import {Input, Provider, forwardRef} from '@angular/core';
66import { fakeAsync , flushMicrotasks , tick } from '@angular/core/testing' ;
77import { afterEach , beforeEach , ddescribe , describe , expect , iit , inject , it , xdescribe , xit } from '@angular/core/testing/testing_internal' ;
88import { AsyncTestCompleter } from '@angular/core/testing/testing_internal' ;
9- import { ControlValueAccessor , FORM_DIRECTIVES , FORM_PROVIDERS , FormControl , FormGroup , NG_ASYNC_VALIDATORS , NG_VALIDATORS , NgControl , NgForm , NgModel , REACTIVE_FORM_DIRECTIVES , RadioButtonState , Validator , Validators , disableDeprecatedForms , provideForms } from '@angular/forms' ;
9+ import { ControlValueAccessor , FORM_DIRECTIVES , FORM_PROVIDERS , FormControl , FormGroup , NG_ASYNC_VALIDATORS , NG_VALIDATORS , NgControl , NgForm , NgModel , REACTIVE_FORM_DIRECTIVES , Validator , Validators , disableDeprecatedForms , provideForms } from '@angular/forms' ;
1010import { By } from '@angular/platform-browser/src/dom/debug/by' ;
1111import { getDOM } from '@angular/platform-browser/src/dom/dom_adapter' ;
1212import { dispatchEvent } from '@angular/platform-browser/testing' ;
@@ -503,29 +503,35 @@ export function main() {
503503 [ TestComponentBuilder , AsyncTestCompleter ] ,
504504 ( tcb : TestComponentBuilder , async : AsyncTestCompleter ) => {
505505 const t = `<form [formGroup]="form">
506- <input type="radio" formControlName="foodChicken" name="food ">
507- <input type="radio" formControlName="foodFish" name="food ">
506+ <input type="radio" formControlName="food" value="chicken ">
507+ <input type="radio" formControlName="food" value="fish ">
508508 </form>` ;
509509
510+ const ctrl = new FormControl ( 'fish' ) ;
510511 tcb . overrideTemplate ( MyComp8 , t )
511512 . overrideProviders ( MyComp8 , providerArr )
512513 . createAsync ( MyComp8 )
513514 . then ( ( fixture ) => {
514- fixture . debugElement . componentInstance . form = new FormGroup ( {
515- 'foodChicken' : new FormControl ( new RadioButtonState ( false , 'chicken' ) ) ,
516- 'foodFish' : new FormControl ( new RadioButtonState ( true , 'fish' ) )
517- } ) ;
515+ fixture . debugElement . componentInstance . form = new FormGroup ( { 'food' : ctrl } ) ;
518516 fixture . detectChanges ( ) ;
519517
520- var input = fixture . debugElement . query ( By . css ( 'input' ) ) ;
521- expect ( input . nativeElement . checked ) . toEqual ( false ) ;
518+ var inputs = fixture . debugElement . queryAll ( By . css ( 'input' ) ) ;
519+ expect ( inputs [ 0 ] . nativeElement . checked ) . toEqual ( false ) ;
520+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( true ) ;
522521
523- dispatchEvent ( input . nativeElement , 'change' ) ;
522+ dispatchEvent ( inputs [ 0 ] . nativeElement , 'change' ) ;
524523 fixture . detectChanges ( ) ;
525524
526525 let value = fixture . debugElement . componentInstance . form . value ;
527- expect ( value [ 'foodChicken' ] . checked ) . toEqual ( true ) ;
528- expect ( value [ 'foodFish' ] . checked ) . toEqual ( false ) ;
526+ expect ( value . food ) . toEqual ( 'chicken' ) ;
527+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( false ) ;
528+
529+ ctrl . updateValue ( 'fish' ) ;
530+ fixture . detectChanges ( ) ;
531+
532+ expect ( inputs [ 0 ] . nativeElement . checked ) . toEqual ( false ) ;
533+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( true ) ;
534+
529535 async . done ( ) ;
530536 } ) ;
531537 } ) ) ;
@@ -1393,77 +1399,70 @@ export function main() {
13931399 expect ( form . value ) . toEqual ( { two : 'some data' } ) ;
13941400 } ) ) ) ;
13951401
1396- // TODO(kara): Fix when re-doing radio buttons
1397- xit ( 'should support <type=radio>' ,
1398- fakeAsync ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
1399- const t = `<form>
1400- <input type="radio" name="food" [(ngModel)]="data['chicken']">
1401- <input type="radio" name="food" [(ngModel)]="data['fish']">
1402- <input type="radio" name="food" [(ngModel)]="data['beef']">
1403- <input type="radio" name="food" [(ngModel)]="data['pork']">
1402+ it ( 'should support <type=radio>' ,
1403+ fakeAsync ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
1404+ const t = `<form>
1405+ <input type="radio" name="food" [(ngModel)]="data.food" value="chicken">
1406+ <input type="radio" name="food" [(ngModel)]="data.food" value="fish">
14041407 </form>` ;
14051408
1406- const fixture = tcb . overrideTemplate ( MyComp8 , t ) . createFakeAsync ( MyComp8 ) ;
1407- tick ( ) ;
1409+ const fixture = tcb . overrideTemplate ( MyComp8 , t ) . createFakeAsync ( MyComp8 ) ;
1410+ tick ( ) ;
14081411
1409- fixture . debugElement . componentInstance . data = {
1410- 'chicken' : new RadioButtonState ( false , 'chicken' ) ,
1411- 'fish' : new RadioButtonState ( true , 'fish' ) ,
1412- 'beef' : new RadioButtonState ( false , 'beef' ) ,
1413- 'pork' : new RadioButtonState ( true , 'pork' )
1414- } ;
1415- fixture . detectChanges ( ) ;
1416- tick ( ) ;
1412+ fixture . debugElement . componentInstance . data = { food : 'fish' } ;
1413+ fixture . detectChanges ( ) ;
1414+ tick ( ) ;
14171415
1418- const input = fixture . debugElement . query ( By . css ( 'input' ) ) ;
1419- expect ( input . nativeElement . checked ) . toEqual ( false ) ;
1416+ const inputs = fixture . debugElement . queryAll ( By . css ( 'input' ) ) ;
1417+ expect ( inputs [ 0 ] . nativeElement . checked ) . toEqual ( false ) ;
1418+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( true ) ;
14201419
1421- dispatchEvent ( input . nativeElement , 'change' ) ;
1422- tick ( ) ;
1420+ dispatchEvent ( inputs [ 0 ] . nativeElement , 'change' ) ;
1421+ tick ( ) ;
14231422
1424- const data = fixture . debugElement . componentInstance . data ;
1423+ const data = fixture . debugElement . componentInstance . data ;
14251424
1426- expect ( data [ 'chicken' ] ) . toEqual ( new RadioButtonState ( true , 'chicken' ) ) ;
1427- expect ( data [ 'fish' ] ) . toEqual ( new RadioButtonState ( false , 'fish' ) ) ;
1428- expect ( data [ 'beef' ] ) . toEqual ( new RadioButtonState ( false , 'beef' ) ) ;
1429- expect ( data [ 'pork' ] ) . toEqual ( new RadioButtonState ( false , 'pork' ) ) ;
1430- } ) ) ) ;
1431- } ) ;
1425+ expect ( data . food ) . toEqual ( 'chicken' ) ;
1426+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( false ) ;
1427+ } ) ) ) ;
14321428
1433- xit ( 'should support multiple named <type=radio> groups' ,
1434- fakeAsync ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
1435- const t = `<form>
1436- <input type="radio" name="food" [(ngModel)]="data[' chicken'] ">
1437- <input type="radio" name="food" [(ngModel)]="data[' fish'] ">
1438- <input type="radio" name="drink" [(ngModel)]="data[' cola'] ">
1439- <input type="radio" name="drink" [(ngModel)]="data[' sprite'] ">
1429+ it ( 'should support multiple named <type=radio> groups' ,
1430+ fakeAsync ( inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
1431+ const t = `<form>
1432+ <input type="radio" name="food" [(ngModel)]="data.food" value=" chicken">
1433+ <input type="radio" name="food" [(ngModel)]="data.food" value=" fish">
1434+ <input type="radio" name="drink" [(ngModel)]="data.drink" value=" cola">
1435+ <input type="radio" name="drink" [(ngModel)]="data.drink" value=" sprite">
14401436 </form>` ;
14411437
1442- const fixture = tcb . overrideTemplate ( MyComp8 , t ) . createFakeAsync ( MyComp8 ) ;
1443- tick ( ) ;
1438+ const fixture = tcb . overrideTemplate ( MyComp8 , t ) . createFakeAsync ( MyComp8 ) ;
1439+ tick ( ) ;
1440+
1441+ fixture . debugElement . componentInstance . data = { food : 'fish' , drink : 'sprite' } ;
1442+ fixture . detectChanges ( ) ;
1443+ tick ( ) ;
14441444
1445- fixture . debugElement . componentInstance . data = {
1446- 'chicken' : new RadioButtonState ( false , 'chicken' ) ,
1447- 'fish' : new RadioButtonState ( true , 'fish' ) ,
1448- 'cola' : new RadioButtonState ( false , 'cola' ) ,
1449- 'sprite' : new RadioButtonState ( true , 'sprite' )
1450- } ;
1451- fixture . detectChanges ( ) ;
1452- tick ( ) ;
1445+ const inputs = fixture . debugElement . queryAll ( By . css ( 'input' ) ) ;
1446+ expect ( inputs [ 0 ] . nativeElement . checked ) . toEqual ( false ) ;
1447+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( true ) ;
1448+ expect ( inputs [ 2 ] . nativeElement . checked ) . toEqual ( false ) ;
1449+ expect ( inputs [ 3 ] . nativeElement . checked ) . toEqual ( true ) ;
1450+
1451+ dispatchEvent ( inputs [ 0 ] . nativeElement , 'change' ) ;
1452+ tick ( ) ;
14531453
1454- const input = fixture . debugElement . query ( By . css ( 'input' ) ) ;
1455- expect ( input . nativeElement . checked ) . toEqual ( false ) ;
1454+ const data = fixture . debugElement . componentInstance . data ;
14561455
1457- dispatchEvent ( input . nativeElement , 'change' ) ;
1458- tick ( ) ;
1456+ expect ( data . food ) . toEqual ( 'chicken' ) ;
1457+ expect ( data . drink ) . toEqual ( 'sprite' ) ;
1458+ expect ( inputs [ 1 ] . nativeElement . checked ) . toEqual ( false ) ;
1459+ expect ( inputs [ 2 ] . nativeElement . checked ) . toEqual ( false ) ;
1460+ expect ( inputs [ 3 ] . nativeElement . checked ) . toEqual ( true ) ;
14591461
1460- const data = fixture . debugElement . componentInstance . data ;
1462+ } ) ) ) ;
1463+
1464+ } ) ;
14611465
1462- expect ( data [ 'chicken' ] ) . toEqual ( new RadioButtonState ( true , 'chicken' ) ) ;
1463- expect ( data [ 'fish' ] ) . toEqual ( new RadioButtonState ( false , 'fish' ) ) ;
1464- expect ( data [ 'cola' ] ) . toEqual ( new RadioButtonState ( false , 'cola' ) ) ;
1465- expect ( data [ 'sprite' ] ) . toEqual ( new RadioButtonState ( true , 'sprite' ) ) ;
1466- } ) ) ) ;
14671466
14681467 describe ( 'setting status classes' , ( ) => {
14691468 it ( 'should work with single fields' ,
0 commit comments