Skip to content

Commit 1287613

Browse files
Aleksandyrhanastasovzdrawku
authored
refactor(progressbar): improve animations (#10228)
* refactor(progressbar): improve animations * fix(progressbar): add linear bar animation * fix(progressbar): update progress dinamically when set max * test(progressbar): fixing tests * chore(progressbar): update changelog * fix(progressbar): validate when max is 0 * fix(progressbar): don't snap percent value when update max val * fix(progressbar): validate initial value Co-authored-by: Hristo <[email protected]> Co-authored-by: Zdravko Kolev <[email protected]>
1 parent 241667f commit 1287613

File tree

6 files changed

+231
-327
lines changed

6 files changed

+231
-327
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ All notable changes for each version of this project will be documented in this
7272
- Exposed a `groupStrategy` input that functions similarly to `sortStrategy`, allowing customization of the grouping behavior of the grid. Please, refer to the [Group By ](https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid/groupby) topic for more information.
7373
- `IgxDialog`
7474
- Added `focusTrap` input to set whether the Tab key focus is trapped within the dialog when opened. Defaults to `true`.
75+
- `IgxProgressBar`
76+
- Exposed new animationDuration input - sets the duration of the progress animation.
7577

7678
### General
7779

projects/igniteui-angular/src/lib/progressbar/circularbar.component.spec.ts

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ describe('IgCircularBar', () => {
2424
imports: [
2525
IgxProgressBarModule
2626
]
27-
})
28-
.compileComponents();
27+
}).compileComponents();
2928
}));
3029

3130
it('Initialize circularProgressbar with default values', () => {
@@ -55,22 +54,20 @@ describe('IgCircularBar', () => {
5554
expect(progress.value).toBe(expectedValue);
5655
});
5756

58-
it('If passed value is higher then max it should stay equal to maximum (default max size)', fakeAsync(() => {
57+
it('If passed value is higher then max it should stay equal to maximum (default max size)', () => {
5958
const progressBarValue = 120;
6059
const expectedMaxValue = 100;
6160
const fixture = TestBed.createComponent(InitCircularProgressBarComponent);
6261
fixture.detectChanges();
6362

6463
const progress = fixture.componentInstance.circularBar;
6564
progress.value = progressBarValue;
66-
67-
tick(2500);
6865
fixture.detectChanges();
6966

7067
expect(progress.value).toBe(expectedMaxValue);
71-
}));
68+
});
7269

73-
it('If passed value is higher then max it should stay equal to maximum (custom max size)', fakeAsync(() => {
70+
it('If passed value is higher then max it should stay equal to maximum (custom max size)', () => {
7471
const progressBarMaxValue = 150;
7572
const progressBarValue = 170;
7673
const fixture = TestBed.createComponent(InitCircularProgressBarComponent);
@@ -80,13 +77,11 @@ describe('IgCircularBar', () => {
8077
progress.max = progressBarMaxValue;
8178
progress.value = progressBarValue;
8279

83-
tick(3000);
8480
fixture.detectChanges();
85-
8681
expect(progress.value).toBe(progressBarMaxValue);
87-
}));
82+
});
8883

89-
it('should not update value if max is updated', fakeAsync(() => {
84+
it('should not update value if max is updated', () => {
9085
let progressBarMaxValue = 150;
9186
const progressBarValue = 120;
9287
const fixture = TestBed.createComponent(InitCircularProgressBarComponent);
@@ -97,7 +92,7 @@ describe('IgCircularBar', () => {
9792
progress.max = progressBarMaxValue;
9893
progress.value = progressBarValue;
9994

100-
tick(tickTime);
95+
10196
fixture.detectChanges();
10297

10398
expect(progress.value).toBe(progressBarValue);
@@ -106,37 +101,11 @@ describe('IgCircularBar', () => {
106101
progressBarMaxValue = 200;
107102
progress.max = progressBarMaxValue;
108103

109-
tick(tickTime);
110104
fixture.detectChanges();
111105

112106
expect(progress.value).toBe(progressBarValue);
113107
expect(progress.max).toBe(progressBarMaxValue);
114-
}));
115-
116-
it('Should update value when we try to decrease it', fakeAsync(() => {
117-
const fixture = TestBed.createComponent(CircularBarComponent);
118-
fixture.detectChanges();
119-
120-
const progressBar = fixture.componentInstance.progressbar;
121-
let expectedValue = 50;
122-
123-
fixture.componentInstance.value = expectedValue;
124-
125-
tick(tickTime);
126-
fixture.detectChanges();
127-
tick(tickTime);
128-
129-
expect(progressBar.value).toBe(expectedValue);
130-
131-
expectedValue = 20;
132-
fixture.componentInstance.value = expectedValue;
133-
134-
tick(tickTime);
135-
fixture.detectChanges();
136-
tick(tickTime);
137-
138-
expect(progressBar.value).toBe(expectedValue);
139-
}));
108+
});
140109

141110
it('Should update value when we try to decrease it (without animation)', () => {
142111
const fixture = TestBed.createComponent(CircularBarComponent);
@@ -160,21 +129,20 @@ describe('IgCircularBar', () => {
160129
expect(progressBar.value).toBe(expectedValue);
161130
});
162131

163-
it('When passed value is string progress indication should remain the same', fakeAsync(() => {
132+
it('When passed value is string progress indication should remain the same', () => {
164133
const fix = TestBed.createComponent(CircularBarComponent);
165134
fix.detectChanges();
166135

167136
const bar = fix.componentInstance.progressbar;
168137
const expectedRes = fix.componentInstance.value as number;
169138

170-
tick(tickTime);
171139
expect(bar.value).toEqual(expectedRes);
172140

173141
fix.componentInstance.value = '0345-234';
174-
tick(tickTime);
175142
fix.detectChanges();
143+
176144
expect(bar.value).toEqual(expectedRes);
177-
}));
145+
});
178146

179147
it('The update step is 1% of the maximum value, which prevents from slow update with big nums', () => {
180148
const fix = TestBed.createComponent(InitCircularProgressBarComponent);
@@ -193,35 +161,31 @@ describe('IgCircularBar', () => {
193161
expect(bar.step).toBe(expectedValue);
194162
});
195163

196-
it('Value should not exceed the lower limit (0) when operating with floating numbers', fakeAsync(() => {
164+
it('Value should not exceed the lower limit (0) when operating with floating numbers', () => {
197165
const fix = TestBed.createComponent(CircularBarComponent);
198166
const compInstance = fix.componentInstance;
167+
const bar = compInstance.progressbar;
199168
fix.detectChanges();
200-
tick(tickTime);
201169

202-
compInstance.max = 2.5;
170+
compInstance.value = 0;
203171
fix.detectChanges();
204172

173+
compInstance.max = 2.5;
205174
compInstance.value = -0.3;
206175
fix.detectChanges();
207176

208-
tick(tickTime);
209-
const bar = compInstance.progressbar;
210177
const expectedRes = 0;
211178
expect(bar.value).toBe(expectedRes);
212179
expect(bar.valueInPercent).toBe(expectedRes);
213180

214-
compInstance.animate = false;
215-
fix.detectChanges();
216-
217181
compInstance.value = -2;
218182
fix.detectChanges();
219183

220184
expect(bar.value).toBe(expectedRes);
221185
expect(bar.valueInPercent).toBe(expectedRes);
222-
}));
186+
});
223187

224-
it('Value should not exceed the max limit when operating with floating numbers', fakeAsync(() => {
188+
it('Value should not exceed the max limit when operating with floating numbers', () => {
225189
const fix = TestBed.createComponent(CircularBarComponent);
226190
const compInstance = fix.componentInstance;
227191
let value = 2.67;
@@ -234,7 +198,6 @@ describe('IgCircularBar', () => {
234198
fix.detectChanges();
235199

236200
const bar = compInstance.progressbar;
237-
tick(tickTime);
238201
expect(bar.value).toBe(max);
239202
expect(bar.valueInPercent).toBe(100);
240203

@@ -247,7 +210,7 @@ describe('IgCircularBar', () => {
247210

248211
expect(bar.value).toBe(max);
249212
expect(bar.valueInPercent).toBe(100);
250-
}));
213+
});
251214

252215
it('when passing string as value it should be parsed correctly', () => {
253216
const fix = TestBed.createComponent(CircularBarComponent);
@@ -265,7 +228,7 @@ describe('IgCircularBar', () => {
265228
expect(bar.value).toBe(expectedRes);
266229
});
267230

268-
it('when update step is bigger than passed value the progress indicator should follow the value representation', fakeAsync(() => {
231+
it('when update step is bigger than passed value the progress indicator should follow the value representation', () => {
269232
const fix = TestBed.createComponent(InitCircularProgressBarComponent);
270233
fix.detectChanges();
271234

@@ -278,17 +241,16 @@ describe('IgCircularBar', () => {
278241
bar.value = value;
279242

280243
fix.detectChanges();
281-
tick(tickTime);
282244

283245
const percentValue = Common.calcPercentage(value, max);
284246
expect(bar.value).toBe(value);
285247
expect(bar.step).toBe(step);
286248
expect(bar.max).toBe(max);
287249
expect(bar.valueInPercent).toBe(percentValue);
288-
}));
250+
});
289251

290252
it(`when step value is not divisble to passed value the result returned from the
291-
value getter should be the same as the passed one`, fakeAsync(() => {
253+
value getter should be the same as the passed one`, () => {
292254
const fix = TestBed.createComponent(InitCircularProgressBarComponent);
293255
fix.detectChanges();
294256

@@ -299,7 +261,6 @@ describe('IgCircularBar', () => {
299261
bar.step = step;
300262
bar.value = value;
301263

302-
tick(tickTime);
303264
fix.detectChanges();
304265
expect(bar.step).toBe(step);
305266
expect(bar.value).toBe(value);
@@ -308,11 +269,11 @@ describe('IgCircularBar', () => {
308269
value = 10;
309270
valueInPercent = Common.calcPercentage(value, bar.max);
310271
bar.value = value;
311-
tick(tickTime);
312272
fix.detectChanges();
273+
313274
expect(bar.value).toBe(value);
314275
expect(bar.valueInPercent).toBe(valueInPercent);
315-
}));
276+
});
316277

317278
it('should apply its template correctly', () => {
318279
const fixture = TestBed.createComponent(CircularBarTemplateComponent);
@@ -463,7 +424,7 @@ describe('IgCircularBar', () => {
463424
});
464425
});
465426
});
466-
@Component({ template: `<igx-circular-bar></igx-circular-bar>` })
427+
@Component({ template: `<igx-circular-bar [animate]="false"></igx-circular-bar>` })
467428
class InitCircularProgressBarComponent {
468429
@ViewChild(IgxCircularProgressBarComponent, { static: true }) public circularBar: IgxCircularProgressBarComponent;
469430
}
@@ -481,7 +442,7 @@ class CircularBarComponent {
481442

482443
public value: string | number = 30;
483444
public max = 100;
484-
public animate = true;
445+
public animate = false;
485446
}
486447

487448
@Component({

0 commit comments

Comments
 (0)