Skip to content

Commit 8ba098f

Browse files
authored
Merge pull request #7491 from IgniteUI/progressbar-back-fill
fix(progressbar): decrease the progress when pass lower value
2 parents 7f25696 + d874d21 commit 8ba098f

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
async,
44
fakeAsync,
55
TestBed,
6-
tick,
7-
flush
6+
tick
87
} from '@angular/core/testing';
98
import { By } from '@angular/platform-browser';
109
import { IgxCircularProgressBarComponent, IgxProgressBarModule } from './progressbar.component';
@@ -15,7 +14,6 @@ import { configureTestSuite } from '../test-utils/configure-suite';
1514
const CIRCULAR_INNER_CLASS = 'igx-circular-bar__inner';
1615
const CIRCULAR_OUTER_CLASS = 'igx-circular-bar__outer';
1716
const CIRCULAR_TEXT_CLASS = 'igx-circular-bar__text';
18-
const CIRCULAR_HIDDEN_TEXT_CLASS = 'igx-circular-bar__text--hidden';
1917
const CIRCULAR_INDETERMINATE_CLASS = 'igx-circular-bar--indeterminate';
2018

2119
describe('IgCircularBar', () => {
@@ -259,17 +257,20 @@ describe('IgCircularBar', () => {
259257
it('when passing string as value it should be parsed correctly', () => {
260258
const fix = TestBed.createComponent(CircularBarComponent);
261259
const compInstance = fix.componentInstance;
262-
const stringValue = '0.50';
260+
const stringValue = '10';
261+
262+
compInstance.animate = false;
263+
fix.detectChanges();
264+
263265
compInstance.value = stringValue;
264266
fix.detectChanges();
265267

266268
const bar = compInstance.progressbar;
267-
268-
const expectedRes = parseFloat(stringValue);
269+
const expectedRes = parseInt(stringValue, 10);
269270
expect(bar.value).toBe(expectedRes);
270271
});
271272

272-
it('when update step is bigger than passed value the progress indicator should follow the value representation', () => {
273+
it('when update step is bigger than passed value the progress indicator should follow the value representation', fakeAsync(() => {
273274
const fix = TestBed.createComponent(InitCircularProgressBarComponent);
274275
fix.detectChanges();
275276

@@ -282,13 +283,14 @@ describe('IgCircularBar', () => {
282283
bar.value = value;
283284

284285
fix.detectChanges();
286+
tick(tickTime);
285287

286288
const percentValue = Common.calcPercentage(value, max);
287289
expect(bar.value).toBe(value);
288290
expect(bar.step).toBe(step);
289291
expect(bar.max).toBe(max);
290292
expect(bar.valueInPercent).toBe(percentValue);
291-
});
293+
}));
292294

293295
it(`when step value is not divisble to passed value the result returned from the
294296
value getter should be the same as the passed one`, fakeAsync(() => {

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,20 @@ describe('IgLinearBar', () => {
282282
it('when passing string as value it should be parsed correctly', () => {
283283
const fix = TestBed.createComponent(LinearBarComponent);
284284
const compInstance = fix.componentInstance;
285-
const stringValue = '0.50';
286-
compInstance.value = stringValue;
285+
const bar = compInstance.progressbar;
286+
287+
compInstance.animate = false;
287288
fix.detectChanges();
288289

289-
const bar = compInstance.progressbar;
290+
const stringValue = '20';
291+
compInstance.value = stringValue;
292+
fix.detectChanges();
290293

291-
let expectedRes: number | string = stringValue.toString();
292-
expectedRes = parseFloat(stringValue);
294+
const expectedRes = parseInt(stringValue, 10);
293295
expect(bar.value).toBe(expectedRes);
294296
});
295297

296-
it('when update step is bigger than passed value the progress indicator should follow the value representation', () => {
298+
it('when update step is bigger than passed value the progress indicator should follow the value itself', fakeAsync(() => {
297299
const fix = TestBed.createComponent(InitLinearProgressBarComponent);
298300
fix.detectChanges();
299301

@@ -306,13 +308,14 @@ describe('IgLinearBar', () => {
306308
bar.value = value;
307309

308310
fix.detectChanges();
311+
tick(tickTime);
309312

310313
const percentValue = Common.calcPercentage(value, max);
311314
expect(bar.value).toBe(value);
312315
expect(bar.step).toBe(step);
313316
expect(bar.max).toBe(max);
314317
expect(bar.valueInPercent).toBe(percentValue);
315-
});
318+
}));
316319

317320
it(`when step value is not divisble to passed value the result returned from the
318321
value getter should be as same as the passed one`, fakeAsync(() => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export abstract class BaseProgress {
198198
};
199199

200200
const stepDirection = this.directionFlow(oldVal, newVal);
201-
if (this._animate && newVal >= this.step) {
201+
if (this._animate) {
202202
this.runAnimation(newVal, stepDirection);
203203
} else {
204204
this.updateProgressDirectly(newVal);
@@ -219,7 +219,7 @@ export abstract class BaseProgress {
219219
* @hidden
220220
*/
221221
protected updateProgressSmoothly(val: number, step: number) {
222-
this._value += step;
222+
this._value = valueInRange(this._value, this._max) + step;
223223
const passedValue = toPercent(val, this._max);
224224
const progressValue = toPercent(this._value, this._max);
225225
if (this.valueInPercent === passedValue) {
@@ -238,7 +238,7 @@ export abstract class BaseProgress {
238238
* @hidden
239239
*/
240240
protected updateProgressDirectly(val: number) {
241-
this._value = val;
241+
this._value = valueInRange(val, this._max);
242242
this.valueInPercent = toPercent(this._value, this._max);
243243
}
244244

@@ -284,7 +284,7 @@ export abstract class BaseProgress {
284284
* @param step
285285
*/
286286
private updateProgress(val: number) {
287-
this._value = val;
287+
this._value = valueInRange(val, this._max);
288288
this.valueInPercent = toPercent(this._value, this._max);
289289
}
290290
}

0 commit comments

Comments
 (0)