/
progress-bar.spec.ts
128 lines (97 loc) · 4.52 KB
/
progress-bar.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
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
import {Component} from '@angular/core';
import {By} from '@angular/platform-browser';
import {Location} from '@angular/common';
import {MatProgressBarModule} from './index';
describe('MatProgressBar', () => {
let fakePath = '/fake-path';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatProgressBarModule],
declarations: [
BasicProgressBar,
BufferProgressBar,
],
providers: [{
provide: Location,
useValue: {path: () => fakePath}
}]
});
TestBed.compileComponents();
}));
describe('basic progress-bar', () => {
let fixture: ComponentFixture<BasicProgressBar>;
beforeEach(() => {
fixture = TestBed.createComponent(BasicProgressBar);
fixture.detectChanges();
});
it('should apply a mode of "determinate" if no mode is provided.', () => {
let progressElement = fixture.debugElement.query(By.css('mat-progress-bar'));
expect(progressElement.componentInstance.mode).toBe('determinate');
});
it('should define default values for value and bufferValue attributes', () => {
let progressElement = fixture.debugElement.query(By.css('mat-progress-bar'));
expect(progressElement.componentInstance.value).toBe(0);
expect(progressElement.componentInstance.bufferValue).toBe(0);
});
it('should clamp value and bufferValue between 0 and 100', () => {
let progressElement = fixture.debugElement.query(By.css('mat-progress-bar'));
let progressComponent = progressElement.componentInstance;
progressComponent.value = 50;
expect(progressComponent.value).toBe(50);
progressComponent.value = 999;
expect(progressComponent.value).toBe(100);
progressComponent.value = -10;
expect(progressComponent.value).toBe(0);
progressComponent.bufferValue = -29;
expect(progressComponent.bufferValue).toBe(0);
progressComponent.bufferValue = 9;
expect(progressComponent.bufferValue).toBe(9);
progressComponent.bufferValue = 1320;
expect(progressComponent.bufferValue).toBe(100);
});
it('should return the transform attribute for bufferValue and mode', () => {
let progressElement = fixture.debugElement.query(By.css('mat-progress-bar'));
let progressComponent = progressElement.componentInstance;
expect(progressComponent._primaryTransform()).toEqual({transform: 'scaleX(0)'});
expect(progressComponent._bufferTransform()).toBe(undefined);
progressComponent.value = 40;
expect(progressComponent._primaryTransform()).toEqual({transform: 'scaleX(0.4)'});
expect(progressComponent._bufferTransform()).toBe(undefined);
progressComponent.value = 35;
progressComponent.bufferValue = 55;
expect(progressComponent._primaryTransform()).toEqual({transform: 'scaleX(0.35)'});
expect(progressComponent._bufferTransform()).toBe(undefined);
progressComponent.mode = 'buffer';
expect(progressComponent._primaryTransform()).toEqual({transform: 'scaleX(0.35)'});
expect(progressComponent._bufferTransform()).toEqual({transform: 'scaleX(0.55)'});
progressComponent.value = 60;
progressComponent.bufferValue = 60;
expect(progressComponent._primaryTransform()).toEqual({transform: 'scaleX(0.6)'});
expect(progressComponent._bufferTransform()).toEqual({transform: 'scaleX(0.6)'});
});
it('should prefix SVG references with the current path', () => {
const rect = fixture.debugElement.query(By.css('rect')).nativeElement;
expect(rect.getAttribute('fill')).toMatch(/^url\(\/fake-path#.*\)$/);
});
it('should not be able to tab into the underlying SVG element', () => {
const svg = fixture.debugElement.query(By.css('svg')).nativeElement;
expect(svg.getAttribute('focusable')).toBe('false');
});
});
describe('buffer progress-bar', () => {
let fixture: ComponentFixture<BufferProgressBar>;
beforeEach(() => {
fixture = TestBed.createComponent(BufferProgressBar);
fixture.detectChanges();
});
it('should not modify the mode if a valid mode is provided.', () => {
let progressElement = fixture.debugElement.query(By.css('mat-progress-bar'));
expect(progressElement.componentInstance.mode).toBe('buffer');
});
});
});
@Component({template: '<mat-progress-bar></mat-progress-bar>'})
class BasicProgressBar { }
@Component({template: '<mat-progress-bar mode="buffer"></mat-progress-bar>'})
class BufferProgressBar { }