Skip to content

Commit eaa9a01

Browse files
authored
chore(progress-circle): remove TestComponentBuilder (#1010)
1 parent dc8eb24 commit eaa9a01

File tree

1 file changed

+71
-102
lines changed

1 file changed

+71
-102
lines changed
Lines changed: 71 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,101 @@
1-
import {inject, TestComponentBuilder, TestBed, async} from '@angular/core/testing';
2-
import {Component, DebugElement} from '@angular/core';
1+
import {TestBed, async} from '@angular/core/testing';
2+
import {Component} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {MdProgressCircleModule} from './progress-circle';
55

66

77
describe('MdProgressCircular', () => {
8-
let builder: TestComponentBuilder;
98

109
beforeEach(async(() => {
1110
TestBed.configureTestingModule({
1211
imports: [MdProgressCircleModule],
13-
declarations: [TestApp],
12+
declarations: [
13+
BasicProgressSpinner,
14+
IndeterminateProgressSpinner,
15+
ProgressSpinnerWithValueAndBoundMode,
16+
IndeterminateProgressSpinnerWithNgIf,
17+
],
1418
});
1519

1620
TestBed.compileComponents();
1721
}));
1822

19-
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
20-
builder = tcb;
21-
}));
23+
it('should apply a mode of "determinate" if no mode is provided.', () => {
24+
let fixture = TestBed.createComponent(BasicProgressSpinner);
25+
fixture.detectChanges();
2226

23-
it('should apply a mode of "determinate" if no mode is provided.', (done: () => void) => {
24-
builder
25-
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
26-
.createAsync(TestApp)
27-
.then((fixture) => {
28-
fixture.detectChanges();
29-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
30-
expect(progressElement.componentInstance.mode).toBe('determinate');
31-
done();
32-
});
27+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
28+
expect(progressElement.componentInstance.mode).toBe('determinate');
3329
});
3430

35-
it('should not modify the mode if a valid mode is provided.', (done: () => void) => {
36-
builder
37-
.overrideTemplate(TestApp, '<md-progress-circle mode="indeterminate"></md-progress-circle>')
38-
.createAsync(TestApp)
39-
.then((fixture) => {
40-
fixture.detectChanges();
41-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
42-
expect(progressElement.componentInstance.mode).toBe('indeterminate');
43-
done();
44-
});
31+
it('should not modify the mode if a valid mode is provided.', () => {
32+
let fixture = TestBed.createComponent(IndeterminateProgressSpinner);
33+
fixture.detectChanges();
34+
35+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
36+
expect(progressElement.componentInstance.mode).toBe('indeterminate');
4537
});
4638

47-
it('should define a default value of undefined for the value attribute', (done: () => void) => {
48-
builder
49-
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
50-
.createAsync(TestApp)
51-
.then((fixture) => {
52-
fixture.detectChanges();
53-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
54-
expect(progressElement.componentInstance.value).toBeUndefined();
55-
done();
56-
});
39+
it('should define a default value of undefined for the value attribute', () => {
40+
let fixture = TestBed.createComponent(BasicProgressSpinner);
41+
fixture.detectChanges();
42+
43+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
44+
expect(progressElement.componentInstance.value).toBeUndefined();
5745
});
5846

59-
it('should set the value to undefined when the mode is set to indeterminate',
60-
(done: () => void) => {
61-
builder
62-
.overrideTemplate(TestApp, `<md-progress-circle value="50"
63-
[mode]="mode"></md-progress-circle>`)
64-
.createAsync(TestApp)
65-
.then((fixture) => {
66-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
67-
fixture.debugElement.componentInstance.mode = 'determinate';
68-
fixture.detectChanges();
69-
expect(progressElement.componentInstance.value).toBe(50);
70-
fixture.debugElement.componentInstance.mode = 'indeterminate';
71-
fixture.detectChanges();
72-
expect(progressElement.componentInstance.value).toBe(undefined);
73-
done();
74-
});
47+
it('should set the value to undefined when the mode is set to indeterminate', () => {
48+
let fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
49+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
50+
fixture.debugElement.componentInstance.mode = 'determinate';
51+
fixture.detectChanges();
52+
53+
expect(progressElement.componentInstance.value).toBe(50);
54+
fixture.debugElement.componentInstance.mode = 'indeterminate';
55+
fixture.detectChanges();
56+
expect(progressElement.componentInstance.value).toBe(undefined);
7557
});
7658

77-
it('should clamp the value of the progress between 0 and 100', (done: () => void) => {
78-
builder
79-
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
80-
.createAsync(TestApp)
81-
.then((fixture) => {
82-
fixture.detectChanges();
83-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
84-
let progressComponent = progressElement.componentInstance;
85-
86-
progressComponent.value = 50;
87-
expect(progressComponent.value).toBe(50);
88-
89-
progressComponent.value = 999;
90-
expect(progressComponent.value).toBe(100);
91-
92-
progressComponent.value = -10;
93-
expect(progressComponent.value).toBe(0);
94-
done();
95-
});
59+
it('should clamp the value of the progress between 0 and 100', () => {
60+
let fixture = TestBed.createComponent(BasicProgressSpinner);
61+
fixture.detectChanges();
62+
63+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
64+
let progressComponent = progressElement.componentInstance;
65+
66+
progressComponent.value = 50;
67+
expect(progressComponent.value).toBe(50);
68+
69+
progressComponent.value = 999;
70+
expect(progressComponent.value).toBe(100);
71+
72+
progressComponent.value = -10;
73+
expect(progressComponent.value).toBe(0);
9674
});
9775

98-
it('should clean up the indeterminate animation when the element is destroyed',
99-
(done: () => void) => {
100-
let template = `<md-progress-circle
101-
mode="indeterminate"
102-
*ngIf="!isHidden"></md-progress-circle>`;
103-
104-
builder
105-
.overrideTemplate(TestApp, template)
106-
.createAsync(TestApp)
107-
.then((fixture) => {
108-
fixture.detectChanges();
109-
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
110-
expect(progressElement.componentInstance.interdeterminateInterval).toBeTruthy();
111-
112-
fixture.debugElement.componentInstance.isHidden = true;
113-
fixture.detectChanges();
114-
expect(progressElement.componentInstance.interdeterminateInterval).toBeFalsy();
115-
done();
116-
});
117-
});
76+
it('should clean up the indeterminate animation when the element is destroyed', () => {
77+
let fixture = TestBed.createComponent(IndeterminateProgressSpinnerWithNgIf);
78+
fixture.detectChanges();
79+
80+
let progressElement = fixture.debugElement.query(By.css('md-progress-circle'));
81+
expect(progressElement.componentInstance.interdeterminateInterval).toBeTruthy();
82+
83+
fixture.debugElement.componentInstance.isHidden = true;
84+
fixture.detectChanges();
85+
expect(progressElement.componentInstance.interdeterminateInterval).toBeFalsy();
86+
});
11887
});
11988

12089

121-
/** Gets a child DebugElement by tag name. */
122-
function getChildDebugElement(parent: DebugElement, selector: string): DebugElement {
123-
return parent.query(By.css(selector));
124-
}
90+
@Component({template: '<md-progress-circle></md-progress-circle>'})
91+
class BasicProgressSpinner { }
92+
93+
@Component({template: '<md-progress-circle mode="indeterminate"></md-progress-circle>'})
94+
class IndeterminateProgressSpinner { }
12595

96+
@Component({template: '<md-progress-circle value="50" [mode]="mode"></md-progress-circle>'})
97+
class ProgressSpinnerWithValueAndBoundMode { }
12698

127-
/** Test component that contains an MdButton. */
128-
@Component({
129-
template: '',
130-
})
131-
class TestApp {
132-
}
99+
@Component({template: `
100+
<md-progress-circle mode="indeterminate" *ngIf="!isHidden"></md-progress-circle>`})
101+
class IndeterminateProgressSpinnerWithNgIf { }

0 commit comments

Comments
 (0)