Skip to content

Commit 844a213

Browse files
authored
chore(radio): remove TestComponentBuilder (#1011)
1 parent c885fa7 commit 844a213

File tree

1 file changed

+52
-109
lines changed

1 file changed

+52
-109
lines changed

src/components/radio/radio.spec.ts

Lines changed: 52 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
import {
2-
inject,
3-
async,
4-
fakeAsync,
5-
TestComponentBuilder,
6-
ComponentFixture,
7-
TestBed,
8-
} from '@angular/core/testing';
1+
import {async, fakeAsync, ComponentFixture, TestBed} from '@angular/core/testing';
92
import {NgControl, FormsModule} from '@angular/forms';
103
import {Component, DebugElement} from '@angular/core';
114
import {By} from '@angular/platform-browser';
125
import {MdRadioGroup, MdRadioButton, MdRadioChange, MdRadioModule} from './radio';
13-
import {
14-
MdUniqueSelectionDispatcher
15-
} from '@angular2-material/core/coordination/unique-selection-dispatcher';
166

177

188
describe('MdRadio', () => {
19-
let builder: TestComponentBuilder;
20-
let dispatcher: MdUniqueSelectionDispatcher;
219

2210
beforeEach(async(() => {
2311
TestBed.configureTestingModule({
@@ -32,12 +20,6 @@ describe('MdRadio', () => {
3220
TestBed.compileComponents();
3321
}));
3422

35-
let injectDeps = [TestComponentBuilder, MdUniqueSelectionDispatcher];
36-
beforeEach(inject(injectDeps, (tcb: TestComponentBuilder, d: MdUniqueSelectionDispatcher) => {
37-
builder = tcb;
38-
dispatcher = d;
39-
}));
40-
4123
describe('inside of a group', () => {
4224
let fixture: ComponentFixture<RadiosInsideRadioGroup>;
4325
let groupDebugElement: DebugElement;
@@ -50,23 +32,21 @@ describe('MdRadio', () => {
5032
let testComponent: RadiosInsideRadioGroup;
5133

5234
beforeEach(async(() => {
53-
builder.createAsync(RadiosInsideRadioGroup).then(f => {
54-
fixture = f;
55-
fixture.detectChanges();
35+
fixture = TestBed.createComponent(RadiosInsideRadioGroup);
36+
fixture.detectChanges();
5637

57-
testComponent = fixture.debugElement.componentInstance;
38+
testComponent = fixture.debugElement.componentInstance;
5839

59-
groupDebugElement = fixture.debugElement.query(By.directive(MdRadioGroup));
60-
groupNativeElement = groupDebugElement.nativeElement;
61-
groupInstance = groupDebugElement.injector.get(MdRadioGroup);
40+
groupDebugElement = fixture.debugElement.query(By.directive(MdRadioGroup));
41+
groupNativeElement = groupDebugElement.nativeElement;
42+
groupInstance = groupDebugElement.injector.get(MdRadioGroup);
6243

63-
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
64-
radioNativeElements = radioDebugElements.map(debugEl => debugEl.nativeElement);
65-
radioInstances = radioDebugElements.map(debugEl => debugEl.componentInstance);
44+
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
45+
radioNativeElements = radioDebugElements.map(debugEl => debugEl.nativeElement);
46+
radioInstances = radioDebugElements.map(debugEl => debugEl.componentInstance);
6647

67-
radioLabelElements = radioDebugElements
68-
.map(debugEl => debugEl.query(By.css('label')).nativeElement);
69-
});
48+
radioLabelElements = radioDebugElements
49+
.map(debugEl => debugEl.query(By.css('label')).nativeElement);
7050
}));
7151

7252
it('should set individual radio names based on the group name', () => {
@@ -250,26 +230,24 @@ describe('MdRadio', () => {
250230
let testComponent: RadioGroupWithNgModel;
251231
let groupNgControl: NgControl;
252232

253-
beforeEach(async(() => {
254-
builder.createAsync(RadioGroupWithNgModel).then(f => {
255-
fixture = f;
256-
fixture.detectChanges();
233+
beforeEach(() => {
234+
fixture = TestBed.createComponent(RadioGroupWithNgModel);
235+
fixture.detectChanges();
257236

258-
testComponent = fixture.debugElement.componentInstance;
237+
testComponent = fixture.debugElement.componentInstance;
259238

260-
groupDebugElement = fixture.debugElement.query(By.directive(MdRadioGroup));
261-
groupNativeElement = groupDebugElement.nativeElement;
262-
groupInstance = groupDebugElement.injector.get(MdRadioGroup);
263-
groupNgControl = groupDebugElement.injector.get(NgControl);
239+
groupDebugElement = fixture.debugElement.query(By.directive(MdRadioGroup));
240+
groupNativeElement = groupDebugElement.nativeElement;
241+
groupInstance = groupDebugElement.injector.get(MdRadioGroup);
242+
groupNgControl = groupDebugElement.injector.get(NgControl);
264243

265-
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
266-
radioNativeElements = radioDebugElements.map(debugEl => debugEl.nativeElement);
267-
radioInstances = radioDebugElements.map(debugEl => debugEl.componentInstance);
244+
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
245+
radioNativeElements = radioDebugElements.map(debugEl => debugEl.nativeElement);
246+
radioInstances = radioDebugElements.map(debugEl => debugEl.componentInstance);
268247

269-
radioLabelElements = radioDebugElements
270-
.map(debugEl => debugEl.query(By.css('label')).nativeElement);
271-
});
272-
}));
248+
radioLabelElements = radioDebugElements
249+
.map(debugEl => debugEl.query(By.css('label')).nativeElement);
250+
});
273251

274252
it('should set individual radio names based on the group name', () => {
275253
expect(groupInstance.name).toBeTruthy();
@@ -327,37 +305,6 @@ describe('MdRadio', () => {
327305

328306
expect(testComponent.modelValue).toBe('chocolate');
329307
}));
330-
});
331-
332-
describe('group with ngModel and change event', () => {
333-
let fixture: ComponentFixture<RadioGroupWithNgModel>;
334-
let groupDebugElement: DebugElement;
335-
let groupNativeElement: HTMLElement;
336-
let radioDebugElements: DebugElement[];
337-
let radioNativeElements: HTMLElement[];
338-
let groupInstance: MdRadioGroup;
339-
let radioInstances: MdRadioButton[];
340-
let testComponent: RadioGroupWithNgModel;
341-
let groupNgControl: NgControl;
342-
343-
beforeEach(async(() => {
344-
builder.createAsync(RadioGroupWithNgModel).then(f => {
345-
fixture = f;
346-
347-
testComponent = fixture.componentInstance;
348-
349-
groupDebugElement = fixture.debugElement.query(By.directive(MdRadioGroup));
350-
groupNativeElement = groupDebugElement.nativeElement;
351-
groupInstance = groupDebugElement.injector.get(MdRadioGroup);
352-
groupNgControl = groupDebugElement.injector.get(NgControl);
353-
354-
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
355-
radioNativeElements = radioDebugElements.map(debugEl => debugEl.nativeElement);
356-
radioInstances = radioDebugElements.map(debugEl => debugEl.componentInstance);
357-
358-
fixture.detectChanges();
359-
});
360-
}));
361308

362309
it('should update the model before firing change event', fakeAsync(() => {
363310
expect(testComponent.modelValue).toBeUndefined();
@@ -386,36 +333,32 @@ describe('MdRadio', () => {
386333
let fruitRadioNativeInputs: HTMLElement[];
387334
let testComponent: StandaloneRadioButtons;
388335

389-
beforeEach(async(() => {
390-
builder.createAsync(StandaloneRadioButtons).then(f => {
391-
let fruitRadioNativeElements: HTMLElement[];
392-
393-
fixture = f;
394-
fixture.detectChanges();
395-
396-
testComponent = fixture.debugElement.componentInstance;
397-
398-
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
399-
seasonRadioInstances = radioDebugElements
400-
.filter(debugEl => debugEl.componentInstance.name == 'season')
401-
.map(debugEl => debugEl.componentInstance);
402-
weatherRadioInstances = radioDebugElements
403-
.filter(debugEl => debugEl.componentInstance.name == 'weather')
404-
.map(debugEl => debugEl.componentInstance);
405-
fruitRadioInstances = radioDebugElements
406-
.filter(debugEl => debugEl.componentInstance.name == 'fruit')
407-
.map(debugEl => debugEl.componentInstance);
408-
409-
fruitRadioNativeElements = radioDebugElements
410-
.filter(debugEl => debugEl.componentInstance.name == 'fruit')
411-
.map(debugEl => debugEl.nativeElement);
412-
413-
fruitRadioNativeInputs = [];
414-
for (let element of fruitRadioNativeElements) {
415-
fruitRadioNativeInputs.push(<HTMLElement> element.querySelector('input'));
416-
}
417-
});
418-
}));
336+
beforeEach(() => {
337+
fixture = TestBed.createComponent(StandaloneRadioButtons);
338+
fixture.detectChanges();
339+
340+
testComponent = fixture.debugElement.componentInstance;
341+
342+
radioDebugElements = fixture.debugElement.queryAll(By.directive(MdRadioButton));
343+
seasonRadioInstances = radioDebugElements
344+
.filter(debugEl => debugEl.componentInstance.name == 'season')
345+
.map(debugEl => debugEl.componentInstance);
346+
weatherRadioInstances = radioDebugElements
347+
.filter(debugEl => debugEl.componentInstance.name == 'weather')
348+
.map(debugEl => debugEl.componentInstance);
349+
fruitRadioInstances = radioDebugElements
350+
.filter(debugEl => debugEl.componentInstance.name == 'fruit')
351+
.map(debugEl => debugEl.componentInstance);
352+
353+
let fruitRadioNativeElements = radioDebugElements
354+
.filter(debugEl => debugEl.componentInstance.name == 'fruit')
355+
.map(debugEl => debugEl.nativeElement);
356+
357+
fruitRadioNativeInputs = [];
358+
for (let element of fruitRadioNativeElements) {
359+
fruitRadioNativeInputs.push(<HTMLElement> element.querySelector('input'));
360+
}
361+
});
419362

420363
it('should uniquely select radios by a name', () => {
421364
seasonRadioInstances[0].checked = true;

0 commit comments

Comments
 (0)