@@ -62,7 +62,7 @@ describe('MdRadio', () => {
62
62
63
63
it ( 'should set individual radio names based on the group name' , ( ) => {
64
64
expect ( groupInstance . name ) . toBeTruthy ( ) ;
65
- for ( let radio of radioInstances ) {
65
+ for ( const radio of radioInstances ) {
66
66
expect ( radio . name ) . toBe ( groupInstance . name ) ;
67
67
}
68
68
} ) ;
@@ -92,14 +92,14 @@ describe('MdRadio', () => {
92
92
testComponent . labelPos = 'before' ;
93
93
fixture . detectChanges ( ) ;
94
94
95
- for ( let radio of radioInstances ) {
95
+ for ( const radio of radioInstances ) {
96
96
expect ( radio . labelPosition ) . toBe ( 'before' ) ;
97
97
}
98
98
99
99
testComponent . labelPos = 'after' ;
100
100
fixture . detectChanges ( ) ;
101
101
102
- for ( let radio of radioInstances ) {
102
+ for ( const radio of radioInstances ) {
103
103
expect ( radio . labelPosition ) . toBe ( 'after' ) ;
104
104
}
105
105
} ) ;
@@ -108,11 +108,20 @@ describe('MdRadio', () => {
108
108
testComponent . isGroupDisabled = true ;
109
109
fixture . detectChanges ( ) ;
110
110
111
- for ( let radio of radioInstances ) {
111
+ for ( const radio of radioInstances ) {
112
112
expect ( radio . disabled ) . toBe ( true ) ;
113
113
}
114
114
} ) ;
115
115
116
+ it ( 'should set required to each radio button when the group is required' , ( ) => {
117
+ testComponent . isGroupRequired = true ;
118
+ fixture . detectChanges ( ) ;
119
+
120
+ for ( const radio of radioInstances ) {
121
+ expect ( radio . required ) . toBe ( true ) ;
122
+ }
123
+ } ) ;
124
+
116
125
it ( 'should update the group value when one of the radios changes' , ( ) => {
117
126
expect ( groupInstance . value ) . toBeFalsy ( ) ;
118
127
@@ -155,7 +164,7 @@ describe('MdRadio', () => {
155
164
it ( 'should emit a change event from radio buttons' , ( ) => {
156
165
expect ( radioInstances [ 0 ] . checked ) . toBe ( false ) ;
157
166
158
- let spies = radioInstances
167
+ const spies = radioInstances
159
168
. map ( ( radio , index ) => jasmine . createSpy ( `onChangeSpy ${ index } for ${ radio . name } ` ) ) ;
160
169
161
170
spies . forEach ( ( spy , index ) => radioInstances [ index ] . change . subscribe ( spy ) ) ;
@@ -178,7 +187,7 @@ describe('MdRadio', () => {
178
187
programmatically` , ( ) => {
179
188
expect ( groupInstance . value ) . toBeFalsy ( ) ;
180
189
181
- let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
190
+ const changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
182
191
groupInstance . change . subscribe ( changeSpy ) ;
183
192
184
193
radioLabelElements [ 0 ] . click ( ) ;
@@ -265,7 +274,7 @@ describe('MdRadio', () => {
265
274
testComponent . disableRipple = true ;
266
275
fixture . detectChanges ( ) ;
267
276
268
- for ( let radioLabel of radioLabelElements ) {
277
+ for ( const radioLabel of radioLabelElements ) {
269
278
dispatchFakeEvent ( radioLabel , 'mousedown' ) ;
270
279
dispatchFakeEvent ( radioLabel , 'mouseup' ) ;
271
280
@@ -275,7 +284,7 @@ describe('MdRadio', () => {
275
284
testComponent . disableRipple = false ;
276
285
fixture . detectChanges ( ) ;
277
286
278
- for ( let radioLabel of radioLabelElements ) {
287
+ for ( const radioLabel of radioLabelElements ) {
279
288
dispatchFakeEvent ( radioLabel , 'mousedown' ) ;
280
289
dispatchFakeEvent ( radioLabel , 'mouseup' ) ;
281
290
@@ -285,7 +294,7 @@ describe('MdRadio', () => {
285
294
286
295
it ( `should update the group's selected radio to null when unchecking that radio
287
296
programmatically` , ( ) => {
288
- let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
297
+ const changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
289
298
groupInstance . change . subscribe ( changeSpy ) ;
290
299
radioInstances [ 0 ] . checked = true ;
291
300
@@ -305,7 +314,7 @@ describe('MdRadio', () => {
305
314
} ) ;
306
315
307
316
it ( 'should not fire a change event from the group when a radio checked state changes' , ( ) => {
308
- let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
317
+ const changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
309
318
groupInstance . change . subscribe ( changeSpy ) ;
310
319
radioInstances [ 0 ] . checked = true ;
311
320
@@ -324,7 +333,7 @@ describe('MdRadio', () => {
324
333
} ) ;
325
334
326
335
it ( `should update checked status if changed value to radio group's value` , ( ) => {
327
- let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
336
+ const changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
328
337
groupInstance . change . subscribe ( changeSpy ) ;
329
338
groupInstance . value = 'apple' ;
330
339
@@ -403,25 +412,25 @@ describe('MdRadio', () => {
403
412
404
413
it ( 'should set individual radio names based on the group name' , ( ) => {
405
414
expect ( groupInstance . name ) . toBeTruthy ( ) ;
406
- for ( let radio of radioInstances ) {
415
+ for ( const radio of radioInstances ) {
407
416
expect ( radio . name ) . toBe ( groupInstance . name ) ;
408
417
}
409
418
410
419
groupInstance . name = 'new name' ;
411
420
412
- for ( let radio of radioInstances ) {
421
+ for ( const radio of radioInstances ) {
413
422
expect ( radio . name ) . toBe ( groupInstance . name ) ;
414
423
}
415
424
} ) ;
416
425
417
426
it ( 'should check the corresponding radio button on group value change' , ( ) => {
418
427
expect ( groupInstance . value ) . toBeFalsy ( ) ;
419
- for ( let radio of radioInstances ) {
428
+ for ( const radio of radioInstances ) {
420
429
expect ( radio . checked ) . toBeFalsy ( ) ;
421
430
}
422
431
423
432
groupInstance . value = 'vanilla' ;
424
- for ( let radio of radioInstances ) {
433
+ for ( const radio of radioInstances ) {
425
434
expect ( radio . checked ) . toBe ( groupInstance . value === radio . value ) ;
426
435
}
427
436
expect ( groupInstance . selected ! . value ) . toBe ( groupInstance . value ) ;
@@ -539,12 +548,12 @@ describe('MdRadio', () => {
539
548
. filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
540
549
. map ( debugEl => debugEl . componentInstance ) ;
541
550
542
- let fruitRadioNativeElements = radioDebugElements
551
+ const fruitRadioNativeElements = radioDebugElements
543
552
. filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
544
553
. map ( debugEl => debugEl . nativeElement ) ;
545
554
546
555
fruitRadioNativeInputs = [ ] ;
547
- for ( let element of fruitRadioNativeElements ) {
556
+ for ( const element of fruitRadioNativeElements ) {
548
557
fruitRadioNativeInputs . push ( < HTMLElement > element . querySelector ( 'input' ) ) ;
549
558
}
550
559
} ) ;
@@ -579,6 +588,14 @@ describe('MdRadio', () => {
579
588
expect ( weatherRadioInstances [ 2 ] . checked ) . toBe ( true ) ;
580
589
} ) ;
581
590
591
+ it ( 'should add required attribute to the underlying input element if defined' , ( ) => {
592
+ const radioInstance = seasonRadioInstances [ 0 ] ;
593
+ radioInstance . required = true ;
594
+ fixture . detectChanges ( ) ;
595
+
596
+ expect ( radioInstance . required ) . toBe ( true ) ;
597
+ } ) ;
598
+
582
599
it ( 'should add aria-label attribute to the underlying input element if defined' , ( ) => {
583
600
expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-label' ) ) . toBe ( 'Banana' ) ;
584
601
} ) ;
@@ -630,6 +647,7 @@ describe('MdRadio', () => {
630
647
template : `
631
648
<md-radio-group [disabled]="isGroupDisabled"
632
649
[labelPosition]="labelPos"
650
+ [required]="isGroupRequired"
633
651
[value]="groupValue"
634
652
name="test-name">
635
653
<md-radio-button value="fire" [disableRipple]="disableRipple" [disabled]="isFirstDisabled"
@@ -647,8 +665,9 @@ describe('MdRadio', () => {
647
665
} )
648
666
class RadiosInsideRadioGroup {
649
667
labelPos : 'before' | 'after' ;
650
- isGroupDisabled : boolean = false ;
651
668
isFirstDisabled : boolean = false ;
669
+ isGroupDisabled : boolean = false ;
670
+ isGroupRequired : boolean = false ;
652
671
groupValue : string | null = null ;
653
672
disableRipple : boolean = false ;
654
673
color : string | null ;
0 commit comments