Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
chore(progressbar): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleycho committed Oct 11, 2015
1 parent 7e3542e commit f7047e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/progressbar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ angular.module('ui.bootstrap.progressbar', [])
bar.$watch('value', function(value) {
bar.recalculatePercentage();
});

bar.recalculatePercentage = function() {
var totalPercentage = self.bars.reduce(function(total, bar) {
bar.percent = +(100 * bar.value / bar.max).toFixed(2);
Expand Down
24 changes: 24 additions & 0 deletions src/progressbar/test/progressbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,30 @@ describe('progressbar directive', function() {
}
expect(totalWidth.toFixed(2)).toBe('100.00');
});

it('should not have a total width over 100%', function() {
$rootScope.objects = [
{ value: 60, type: 'warning' },
{ value: 103 },
{ value: 270, type: 'info' }
];
$rootScope.max = 433;
$rootScope.$digest();
var totalWidth = 0;
for (var i = 0; i < 3; i++) {
totalWidth += parseFloat(getBar(i).css('width'));
}
expect(totalWidth.toFixed(2)).toBe('100.00');

$rootScope.objects.splice(2, 1);
$rootScope.max = 163;
$rootScope.$digest();
totalWidth = 0;
for (i = 0; i < 2; i++) {
totalWidth += parseFloat(getBar(i).css('width'));
}
expect(totalWidth.toFixed(2)).toBe('100.00');
});
});
});
});
Expand Down

0 comments on commit f7047e3

Please sign in to comment.