Skip to content

Commit

Permalink
fix(progressbar): display progressbar correctly when max is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstnbrn committed Oct 4, 2019
1 parent d0654c1 commit cce1662
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/progressbar/progressbar.spec.ts
Expand Up @@ -58,6 +58,13 @@ describe('ngb-progressbar', () => {
expect(progressCmp.getPercentValue()).toBe(20);
});

it('should calculate the percentage (custom max size of zero)', () => {
progressCmp.max = 0;

progressCmp.value = 25;
expect(progressCmp.getPercentValue()).toBe(100);
});

it('should set the value to 0 for negative numbers', () => {
progressCmp.value = -20;
expect(progressCmp.getValue()).toBe(0);
Expand Down Expand Up @@ -120,15 +127,13 @@ describe('ngb-progressbar', () => {
expect(getBarWidth(fixture.nativeElement)).toBe('5%');
});


it('accepts a value and max value above default values', () => {
const html = '<ngb-progressbar [value]="150" [max]="150"></ngb-progressbar>';
const fixture = createTestComponent(html);

expect(getBarWidth(fixture.nativeElement)).toBe('100%');
});


it('accepts a custom type', () => {
const html = '<ngb-progressbar [value]="value" [type]="type"></ngb-progressbar>';
const fixture = createTestComponent(html);
Expand All @@ -151,7 +156,6 @@ describe('ngb-progressbar', () => {
expect(getProgressbar(fixture.nativeElement)).not.toHaveCssClass('progress-bar-animated');
});


it('accepts striped as normal attr', () => {
const html = '<ngb-progressbar [value]="value" [striped]="striped"></ngb-progressbar>';
const fixture = createTestComponent(html);
Expand All @@ -163,7 +167,6 @@ describe('ngb-progressbar', () => {
expect(getProgressbar(fixture.nativeElement)).not.toHaveCssClass('progress-bar-striped');
});


it('should not add "false" CSS class', () => {
const html = '<ngb-progressbar [value]="value" [striped]="striped"></ngb-progressbar>';
const fixture = createTestComponent(html);
Expand Down
8 changes: 7 additions & 1 deletion src/progressbar/progressbar.ts
Expand Up @@ -73,5 +73,11 @@ export class NgbProgressbar {

getValue() { return getValueInRange(this.value, this.max); }

getPercentValue() { return 100 * this.getValue() / this.max; }
getPercentValue() {
if (!this.max) {
return 100;
}

return (100 * this.getValue()) / this.max;
}
}

0 comments on commit cce1662

Please sign in to comment.