-
Notifications
You must be signed in to change notification settings - Fork 40
/
progress-bar.component.spec.ts
135 lines (108 loc) Β· 4.67 KB
/
progress-bar.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { Component } from '@angular/core';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ThemePalette } from '@ptsecurity/mosaic/core';
import { McProgressBarModule } from './index';
// tslint:disable no-magic-numbers
const percentPairs = [
[40, 0.4],
[-50, 0],
[140, 1]
];
// tslint:enable no-magic-numbers
describe('McProgressBar', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [McProgressBarModule],
declarations: [TestApp]
});
TestBed.compileComponents();
}));
it('should apply class based on color attribute', () => {
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const progressBarDebugElement = fixture.debugElement.query(By.css('.first'));
Object.keys(ThemePalette).forEach((key) => {
if (ThemePalette[key]) {
testComponent.color = ThemePalette[key];
fixture.detectChanges();
expect(
progressBarDebugElement.nativeElement.classList.contains(`mc-${ThemePalette[key]}`)
).toBe(true);
}
});
});
it('should has default primary color', () => {
const fixture = TestBed.createComponent(TestApp);
const progressBarDebugElement = fixture.debugElement.query(By.css('.default'));
expect(progressBarDebugElement.nativeElement.classList.contains(`mc-${ThemePalette.Primary}`)).toBe(true);
});
it('should return percentage', () => {
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const progressBarDebugElement = fixture.debugElement.query(By.css('.first'));
percentPairs.forEach(([percent, expected]) => {
testComponent.value = percent;
fixture.detectChanges();
expect(progressBarDebugElement.componentInstance.percentage).toBe(expected);
});
});
it('should return 0 percentage by default', () => {
const fixture = TestBed.createComponent(TestApp);
const progressBarDebugElement = fixture.debugElement.query(By.css('.default'));
expect(progressBarDebugElement.componentInstance.percentage).toBe(0);
});
it('should show determinate line', () => {
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const progressBarDebugElement = fixture.debugElement.query(By.css('.first'));
testComponent.mode = 'determinate';
fixture.detectChanges();
expect(progressBarDebugElement.query(By.css('.mc-progress-bar__line--determinate'))).toBeDefined();
});
it('should show indeterminate line', () => {
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const progressBarDebugElement = fixture.debugElement.query(By.css('.first'));
testComponent.mode = 'indeterminate';
fixture.detectChanges();
expect(progressBarDebugElement.query(By.css('.mc-progress-bar__line--indeterminate'))).toBeDefined();
});
it('should show determinate line by default', () => {
const fixture = TestBed.createComponent(TestApp);
const progressBarDebugElement = fixture.debugElement.query(By.css('.default'));
expect(progressBarDebugElement.query(By.css('.mc-progress-bar__line--determinate'))).toBeDefined();
});
it('should set id attribute', () => {
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const progressBarDebugElement = fixture.debugElement.query(By.css('.first'));
testComponent.id = 'foo';
fixture.detectChanges();
expect(progressBarDebugElement.nativeElement.getAttribute('id')).toBe('foo');
});
it('should auto generate id', () => {
const fixture = TestBed.createComponent(TestApp);
const progressBarDebugElement = fixture.debugElement.query(By.css('.default'));
expect(progressBarDebugElement.nativeElement.getAttribute('id')).toBeDefined();
});
});
@Component({
selector: 'test-app',
template: `
<mc-progress-bar
class="first"
[id]="id"
[color]="color"
[value]="value"
[mode]="mode">
</mc-progress-bar>
<mc-progress-bar class="default"></mc-progress-bar>
`
})
class TestApp {
color: ThemePalette;
value: number = 0;
mode: string;
id: string;
}