Skip to content

Commit c99a727

Browse files
committed
Fixed tests
1 parent d452816 commit c99a727

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/lib/radio/radio.spec.ts

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

414414
it('should write to the radio button based on ngModel', fakeAsync(() => {
415415
testComponent.modelValue = 'chocolate';
416+
416417
fixture.detectChanges();
417418
tick();
418419
fixture.detectChanges();
419420

420421
expect(innerRadios[1].nativeElement.checked).toBe(true);
422+
expect(radioInstances[1].checked).toBe(true);
421423
}));
422424

423425
it('should update the ngModel value when selecting a radio button', () => {
@@ -547,7 +549,7 @@ describe('MdRadio', () => {
547549
it('should change aria-label attribute if property is changed at runtime', () => {
548550
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Banana');
549551

550-
fruitRadioInstances[0].ariaLabel = 'Pineapple';
552+
testComponent.ariaLabel = 'Pineapple';
551553
fixture.detectChanges();
552554

553555
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Pineapple');
@@ -564,7 +566,7 @@ describe('MdRadio', () => {
564566
it('should change aria-labelledby attribute if property is changed at runtime', () => {
565567
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('xyz');
566568

567-
fruitRadioInstances[0].ariaLabelledby = 'uvw';
569+
testComponent.ariaLabelledby = 'uvw';
568570
fixture.detectChanges();
569571

570572
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
@@ -614,12 +616,15 @@ class RadiosInsideRadioGroup {
614616
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
615617
616618
<span id="xyz">Baby Banana</span>
617-
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
619+
<md-radio-button name="fruit" value="banana" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby">
618620
</md-radio-button>
619621
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
620622
`
621623
})
622-
class StandaloneRadioButtons { }
624+
class StandaloneRadioButtons {
625+
ariaLabel: string = 'Banana';
626+
ariaLabelledby: string = 'xyz';
627+
}
623628

624629

625630
@Component({

src/lib/radio/radio.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
8282
/** Whether the `value` has been set to its initial value. */
8383
private _isInitialized: boolean = false;
8484

85+
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
86+
private _labelPosition: 'before' | 'after' = 'after';
87+
8588
/** The method to be called in order to update ngModel */
8689
_controlValueAccessorChangeFn: (value: any) => void = (value) => {};
8790

@@ -126,15 +129,29 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
126129
this.labelPosition = (v == 'start') ? 'after' : 'before';
127130
}
128131

132+
129133
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
130-
@Input() labelPosition: 'before' | 'after' = 'after';
134+
@Input()
135+
get labelPosition() {
136+
return this._labelPosition;
137+
}
138+
139+
set labelPosition(v) {
140+
this._labelPosition = (v == 'before') ? 'before' : 'after';
141+
if (this._radios) {
142+
this._radios.forEach(radio => radio.groupValueChanged());
143+
}
144+
}
131145

132146
/** Whether the radio button is disabled. */
133147
@Input()
134148
get disabled(): boolean { return this._disabled; }
135149
set disabled(value) {
136150
// The presence of *any* disabled value makes the component disabled, *except* for false.
137151
this._disabled = (value != null && value !== false) ? true : null;
152+
if (this._radios) {
153+
this._radios.forEach(radio => radio.groupValueChanged());
154+
}
138155
}
139156

140157
/** Value of the radio button. */
@@ -323,6 +340,7 @@ export class MdRadioButton implements OnInit {
323340
constructor(@Optional() radioGroup: MdRadioGroup,
324341
private _elementRef: ElementRef,
325342
private _renderer: Renderer,
343+
private _changeDetector: ChangeDetectorRef,
326344
public radioDispatcher: UniqueSelectionDispatcher) {
327345
// Assertions. Ideally these should be stripped out by the compiler.
328346
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -364,6 +382,7 @@ export class MdRadioButton implements OnInit {
364382
// Notify all radio buttons with the same name to un-check.
365383
this.radioDispatcher.notify(this.id, this.name);
366384
}
385+
this._changeDetector.markForCheck();
367386
}
368387
}
369388

@@ -427,6 +446,10 @@ export class MdRadioButton implements OnInit {
427446
this._disabled = (value != null && value !== false) ? true : null;
428447
}
429448

449+
groupValueChanged() {
450+
this._changeDetector.markForCheck();
451+
}
452+
430453
ngOnInit() {
431454
if (this.radioGroup) {
432455
// If the radio is inside a radio group, determine if it should be checked

0 commit comments

Comments
 (0)