Skip to content

Commit 8ada70f

Browse files
Updated radio spec to test both intially bound and unbound values.
1 parent 4cefea0 commit 8ada70f

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/components/radio/radio.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function main() {
259259
}).then(done);
260260
});
261261

262-
it('should bind value to model', (done: () => void) => {
262+
it('should bind value to model without initial value', (done: () => void) => {
263263
builder
264264
.overrideTemplate(TestApp, `
265265
<md-radio-group [(ngModel)]="choice">
@@ -272,6 +272,37 @@ export function main() {
272272
let buttons = fixture.debugElement.queryAll(By.css('md-radio-button'));
273273
let group = fixture.debugElement.query(By.css('md-radio-group'));
274274

275+
fixture.detectChanges();
276+
expect(buttons[0].componentInstance.checked).toBe(false);
277+
expect(buttons[1].componentInstance.checked).toBe(false);
278+
expect(fixture.componentInstance.choice).toBe(undefined);
279+
280+
group.componentInstance.selected = buttons[0].componentInstance;
281+
fixture.detectChanges();
282+
expect(isSinglySelected(buttons[0], buttons)).toBe(true);
283+
expect(fixture.componentInstance.choice).toBe(0);
284+
285+
group.componentInstance.selected = buttons[1].componentInstance;
286+
fixture.detectChanges();
287+
expect(isSinglySelected(buttons[1], buttons)).toBe(true);
288+
expect(fixture.componentInstance.choice).toBe(1);
289+
});
290+
}).then(done);
291+
});
292+
293+
it('should bind value to model with initial value', (done: () => void) => {
294+
builder
295+
.overrideTemplate(TestAppWithInitialValue, `
296+
<md-radio-group [(ngModel)]="choice">
297+
<md-radio-button [value]="0"></md-radio-button>
298+
<md-radio-button [value]="1"></md-radio-button>
299+
</md-radio-group>`)
300+
.createAsync(TestAppWithInitialValue)
301+
.then((fixture) => {
302+
fakeAsync(function() {
303+
let buttons = fixture.debugElement.queryAll(By.css('md-radio-button'));
304+
let group = fixture.debugElement.query(By.css('md-radio-group'));
305+
275306
fixture.detectChanges();
276307
expect(isSinglySelected(buttons[1], buttons)).toBe(true);
277308
expect(fixture.componentInstance.choice).toBe(1);
@@ -288,6 +319,7 @@ export function main() {
288319
});
289320
}).then(done);
290321
});
322+
291323
});
292324
}
293325

@@ -320,5 +352,15 @@ function createEvent(name: string): Event {
320352
template: ''
321353
})
322354
class TestApp {
355+
choice: number;
356+
}
357+
358+
/** Test component. */
359+
@Component({
360+
directives: [MdRadioButton, MdRadioGroup],
361+
providers: [MdRadioDispatcher],
362+
template: ''
363+
})
364+
class TestAppWithInitialValue {
323365
choice: number = 1;
324366
}

0 commit comments

Comments
 (0)