@@ -345,10 +345,14 @@ describe('MdRadio', () => {
345
345
let radioDebugElements : DebugElement [ ] ;
346
346
let seasonRadioInstances : MdRadioButton [ ] ;
347
347
let weatherRadioInstances : MdRadioButton [ ] ;
348
+ let fruitRadioInstances : MdRadioButton [ ] ;
349
+ let fruitRadioNativeInputs : HTMLElement [ ] ;
348
350
let testComponent : StandaloneRadioButtons ;
349
351
350
352
beforeEach ( async ( ( ) => {
351
353
builder . createAsync ( StandaloneRadioButtons ) . then ( f => {
354
+ let fruitRadioNativeElements : HTMLElement [ ] ;
355
+
352
356
fixture = f ;
353
357
fixture . detectChanges ( ) ;
354
358
@@ -361,6 +365,18 @@ describe('MdRadio', () => {
361
365
weatherRadioInstances = radioDebugElements
362
366
. filter ( debugEl => debugEl . componentInstance . name == 'weather' )
363
367
. map ( debugEl => debugEl . componentInstance ) ;
368
+ fruitRadioInstances = radioDebugElements
369
+ . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
370
+ . map ( debugEl => debugEl . componentInstance ) ;
371
+
372
+ fruitRadioNativeElements = radioDebugElements
373
+ . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
374
+ . map ( debugEl => debugEl . nativeElement ) ;
375
+
376
+ fruitRadioNativeInputs = [ ] ;
377
+ for ( let element of fruitRadioNativeElements ) {
378
+ fruitRadioNativeInputs . push ( < HTMLElement > element . querySelector ( 'input' ) ) ;
379
+ }
364
380
} ) ;
365
381
} ) ) ;
366
382
@@ -393,6 +409,40 @@ describe('MdRadio', () => {
393
409
expect ( weatherRadioInstances [ 1 ] . checked ) . toBe ( false ) ;
394
410
expect ( weatherRadioInstances [ 2 ] . checked ) . toBe ( true ) ;
395
411
} ) ;
412
+
413
+ it ( 'should add aria-label attribute to the underlying input element if defined' , ( ) => {
414
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-label' ) ) . toBe ( 'Banana' ) ;
415
+ } ) ;
416
+
417
+ it ( 'should not add aria-label attribute if not defined' , ( ) => {
418
+ expect ( fruitRadioNativeInputs [ 1 ] . hasAttribute ( 'aria-label' ) ) . toBeFalsy ( ) ;
419
+ } ) ;
420
+
421
+ it ( 'should change aria-label attribute if property is changed at runtime' , ( ) => {
422
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-label' ) ) . toBe ( 'Banana' ) ;
423
+
424
+ fruitRadioInstances [ 0 ] . ariaLabel = 'Pineapple' ;
425
+ fixture . detectChanges ( ) ;
426
+
427
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-label' ) ) . toBe ( 'Pineapple' ) ;
428
+ } ) ;
429
+
430
+ it ( 'should add aria-labelledby attribute to the underlying input element if defined' , ( ) => {
431
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'xyz' ) ;
432
+ } ) ;
433
+
434
+ it ( 'should not add aria-labelledby attribute if not defined' , ( ) => {
435
+ expect ( fruitRadioNativeInputs [ 1 ] . hasAttribute ( 'aria-labelledby' ) ) . toBeFalsy ( ) ;
436
+ } ) ;
437
+
438
+ it ( 'should change aria-labelledby attribute if property is changed at runtime' , ( ) => {
439
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'xyz' ) ;
440
+
441
+ fruitRadioInstances [ 0 ] . ariaLabelledby = 'uvw' ;
442
+ fixture . detectChanges ( ) ;
443
+
444
+ expect ( fruitRadioNativeInputs [ 0 ] . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'uvw' ) ;
445
+ } ) ;
396
446
} ) ;
397
447
} ) ;
398
448
@@ -423,6 +473,11 @@ class RadiosInsideRadioGroup {
423
473
<md-radio-button name="weather" value="warm">Spring</md-radio-button>
424
474
<md-radio-button name="weather" value="hot">Summer</md-radio-button>
425
475
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
476
+
477
+ <span id="xyz">Baby Banana<span>
478
+ <md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
479
+ </md-radio-button>
480
+ <md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
426
481
`
427
482
} )
428
483
class StandaloneRadioButtons { }
0 commit comments