Skip to content

Commit 7026609

Browse files
committed
Fixed tests
1 parent 44ef4c0 commit 7026609

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/lib/radio/radio.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ describe('MdRadio', () => {
417417

418418
it('should write to the radio button based on ngModel', fakeAsync(() => {
419419
testComponent.modelValue = 'chocolate';
420+
420421
fixture.detectChanges();
421422
tick();
422423
fixture.detectChanges();
423424

424425
expect(innerRadios[1].nativeElement.checked).toBe(true);
426+
expect(radioInstances[1].checked).toBe(true);
425427
}));
426428

427429
it('should update the ngModel value when selecting a radio button', () => {
@@ -551,7 +553,7 @@ describe('MdRadio', () => {
551553
it('should change aria-label attribute if property is changed at runtime', () => {
552554
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Banana');
553555

554-
fruitRadioInstances[0].ariaLabel = 'Pineapple';
556+
testComponent.ariaLabel = 'Pineapple';
555557
fixture.detectChanges();
556558

557559
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Pineapple');
@@ -568,7 +570,7 @@ describe('MdRadio', () => {
568570
it('should change aria-labelledby attribute if property is changed at runtime', () => {
569571
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('xyz');
570572

571-
fruitRadioInstances[0].ariaLabelledby = 'uvw';
573+
testComponent.ariaLabelledby = 'uvw';
572574
fixture.detectChanges();
573575

574576
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
@@ -618,12 +620,15 @@ class RadiosInsideRadioGroup {
618620
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
619621
620622
<span id="xyz">Baby Banana</span>
621-
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
623+
<md-radio-button name="fruit" value="banana" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby">
622624
</md-radio-button>
623625
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
624626
`
625627
})
626-
class StandaloneRadioButtons { }
628+
class StandaloneRadioButtons {
629+
ariaLabel: string = 'Banana';
630+
ariaLabelledby: string = 'xyz';
631+
}
627632

628633

629634
@Component({

src/lib/radio/radio.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
8888
/** Whether the `value` has been set to its initial value. */
8989
private _isInitialized: boolean = false;
9090

91+
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
92+
private _labelPosition: 'before' | 'after' = 'after';
93+
9194
/** The method to be called in order to update ngModel */
9295
_controlValueAccessorChangeFn: (value: any) => void = (value) => {};
9396

@@ -131,8 +134,19 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
131134
this.labelPosition = (v == 'start') ? 'after' : 'before';
132135
}
133136

137+
134138
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
135-
@Input() labelPosition: 'before' | 'after' = 'after';
139+
@Input()
140+
get labelPosition() {
141+
return this._labelPosition;
142+
}
143+
144+
set labelPosition(v) {
145+
this._labelPosition = (v == 'before') ? 'before' : 'after';
146+
if (this._radios) {
147+
this._radios.forEach(radio => radio.groupValueChanged());
148+
}
149+
}
136150

137151
/** Value of the radio button. */
138152
@Input()
@@ -305,6 +319,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
305319
constructor(@Optional() radioGroup: MdRadioGroup,
306320
private _elementRef: ElementRef,
307321
private _renderer: Renderer,
322+
private _changeDetector: ChangeDetectorRef,
308323
public radioDispatcher: UniqueSelectionDispatcher) {
309324
// Assertions. Ideally these should be stripped out by the compiler.
310325
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -345,6 +360,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
345360
// Notify all radio buttons with the same name to un-check.
346361
this._radioDispatcher.notify(this.id, this.name);
347362
}
363+
this._changeDetector.markForCheck();
348364
}
349365
}
350366

@@ -464,6 +480,10 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
464480
this._focusOriginMonitor.focusVia(this._inputElement.nativeElement, this._renderer, 'keyboard');
465481
}
466482

483+
groupValueChanged() {
484+
this._changeDetector.markForCheck();
485+
}
486+
467487
ngOnInit() {
468488
if (this.radioGroup) {
469489
// If the radio is inside a radio group, determine if it should be checked

0 commit comments

Comments
 (0)