Skip to content

Commit f82e27c

Browse files
committed
Fixed tests
1 parent 9c18e4f commit f82e27c

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
@@ -403,11 +403,13 @@ describe('MdRadio', () => {
403403

404404
it('should write to the radio button based on ngModel', fakeAsync(() => {
405405
testComponent.modelValue = 'chocolate';
406+
406407
fixture.detectChanges();
407408
tick();
408409
fixture.detectChanges();
409410

410411
expect(innerRadios[1].nativeElement.checked).toBe(true);
412+
expect(radioInstances[1].checked).toBe(true);
411413
}));
412414

413415
it('should update the ngModel value when selecting a radio button', () => {
@@ -537,7 +539,7 @@ describe('MdRadio', () => {
537539
it('should change aria-label attribute if property is changed at runtime', () => {
538540
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Banana');
539541

540-
fruitRadioInstances[0].ariaLabel = 'Pineapple';
542+
testComponent.ariaLabel = 'Pineapple';
541543
fixture.detectChanges();
542544

543545
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Pineapple');
@@ -554,7 +556,7 @@ describe('MdRadio', () => {
554556
it('should change aria-labelledby attribute if property is changed at runtime', () => {
555557
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('xyz');
556558

557-
fruitRadioInstances[0].ariaLabelledby = 'uvw';
559+
testComponent.ariaLabelledby = 'uvw';
558560
fixture.detectChanges();
559561

560562
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
@@ -604,12 +606,15 @@ class RadiosInsideRadioGroup {
604606
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
605607
606608
<span id="xyz">Baby Banana</span>
607-
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
609+
<md-radio-button name="fruit" value="banana" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby">
608610
</md-radio-button>
609611
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
610612
`
611613
})
612-
class StandaloneRadioButtons { }
614+
class StandaloneRadioButtons {
615+
ariaLabel: string = 'Banana';
616+
ariaLabelledby: string = 'xyz';
617+
}
613618

614619

615620
@Component({

src/lib/radio/radio.ts

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

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

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

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

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

141158
/** Value of the radio button. */
@@ -309,6 +326,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
309326
constructor(@Optional() radioGroup: MdRadioGroup,
310327
private _elementRef: ElementRef,
311328
private _renderer: Renderer,
329+
private _changeDetector: ChangeDetectorRef,
312330
public radioDispatcher: UniqueSelectionDispatcher) {
313331
// Assertions. Ideally these should be stripped out by the compiler.
314332
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -349,6 +367,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
349367
// Notify all radio buttons with the same name to un-check.
350368
this._radioDispatcher.notify(this.id, this.name);
351369
}
370+
this._changeDetector.markForCheck();
352371
}
353372
}
354373

@@ -473,6 +492,10 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
473492
this._focusOriginMonitor.focusVia(this._inputElement.nativeElement, this._renderer, 'keyboard');
474493
}
475494

495+
groupValueChanged() {
496+
this._changeDetector.markForCheck();
497+
}
498+
476499
ngOnInit() {
477500
if (this.radioGroup) {
478501
// If the radio is inside a radio group, determine if it should be checked

0 commit comments

Comments
 (0)