Skip to content

Commit a4b8880

Browse files
committed
Fixed tests
1 parent 8b048a0 commit a4b8880

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

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

421422
expect(innerRadios[1].nativeElement.checked).toBe(true);
423+
expect(radioInstances[1].checked).toBe(true);
422424
}));
423425

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

551-
fruitRadioInstances[0].ariaLabel = 'Pineapple';
553+
testComponent.ariaLabel = 'Pineapple';
552554
fixture.detectChanges();
553555

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

568-
fruitRadioInstances[0].ariaLabelledby = 'uvw';
570+
testComponent.ariaLabelledby = 'uvw';
569571
fixture.detectChanges();
570572

571573
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
@@ -615,12 +617,15 @@ class RadiosInsideRadioGroup {
615617
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
616618
617619
<span id="xyz">Baby Banana</span>
618-
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
620+
<md-radio-button name="fruit" value="banana" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby">
619621
</md-radio-button>
620622
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
621623
`
622624
})
623-
class StandaloneRadioButtons { }
625+
class StandaloneRadioButtons {
626+
ariaLabel: string = 'Banana';
627+
ariaLabelledby: string = 'xyz';
628+
}
624629

625630

626631
@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. */
@@ -327,6 +344,7 @@ export class MdRadioButton implements OnInit {
327344
constructor(@Optional() radioGroup: MdRadioGroup,
328345
private _elementRef: ElementRef,
329346
private _renderer: Renderer,
347+
private _changeDetector: ChangeDetectorRef,
330348
public radioDispatcher: UniqueSelectionDispatcher) {
331349
// Assertions. Ideally these should be stripped out by the compiler.
332350
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -368,6 +386,7 @@ export class MdRadioButton implements OnInit {
368386
// Notify all radio buttons with the same name to un-check.
369387
this.radioDispatcher.notify(this.id, this.name);
370388
}
389+
this._changeDetector.markForCheck();
371390
}
372391
}
373392

@@ -431,6 +450,10 @@ export class MdRadioButton implements OnInit {
431450
this._disabled = (value != null && value !== false) ? true : null;
432451
}
433452

453+
groupValueChanged() {
454+
this._changeDetector.markForCheck();
455+
}
456+
434457
ngOnInit() {
435458
if (this.radioGroup) {
436459
// If the radio is inside a radio group, determine if it should be checked

0 commit comments

Comments
 (0)