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

Commit

Permalink
fix(progressbar): fix default max value
Browse files Browse the repository at this point in the history
- Fix logic around falling back to default max value

Closes #5374
Fixes #5373
  • Loading branch information
MartinNuc authored and wesleycho committed Feb 2, 2016
1 parent 81498a7 commit 258b341
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/progressbar/progressbar.js
Expand Up @@ -10,7 +10,7 @@ angular.module('ui.bootstrap.progressbar', [])
animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;

this.bars = [];
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
$scope.max = getMaxOrDefault();

this.addBar = function(bar, element, attrs) {
if (!animate) {
Expand All @@ -19,7 +19,7 @@ angular.module('ui.bootstrap.progressbar', [])

this.bars.push(bar);

bar.max = $scope.max;
bar.max = getMaxOrDefault();
bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';

bar.$watch('value', function(value) {
Expand Down Expand Up @@ -50,12 +50,17 @@ angular.module('ui.bootstrap.progressbar', [])
});
};

$scope.$watch('max', function(max) {
//$attrs.$observe('maxParam', function(maxParam) {
$scope.$watch('maxParam', function(maxParam) {
self.bars.forEach(function(bar) {
bar.max = $scope.max;
bar.max = getMaxOrDefault();
bar.recalculatePercentage();
});
});

function getMaxOrDefault () {
return angular.isDefined($scope.maxParam) ? $scope.maxParam : progressConfig.max;
}
}])

.directive('uibProgress', function() {
Expand All @@ -65,7 +70,7 @@ angular.module('ui.bootstrap.progressbar', [])
controller: 'UibProgressController',
require: 'uibProgress',
scope: {
max: '=?'
maxParam: '=?max'
},
templateUrl: 'uib/template/progressbar/progress.html'
};
Expand Down Expand Up @@ -94,7 +99,7 @@ angular.module('ui.bootstrap.progressbar', [])
controller: 'UibProgressController',
scope: {
value: '=',
max: '=?',
maxParam: '=?max',
type: '@'
},
templateUrl: 'uib/template/progressbar/progressbar.html',
Expand Down
24 changes: 24 additions & 0 deletions src/progressbar/test/progressbar.spec.js
Expand Up @@ -133,6 +133,30 @@ describe('progressbar directive', function() {
});
});

describe('"max" attribute using object', function() {
beforeEach(inject(function() {
element = $compile('<uib-progressbar max="settings.max" animate="false" value="settings.value">{{settings.value}}/{{settings.max}}</uib-progressbar>')($rootScope);
$rootScope.$digest();
}));

it('should not modify outside object', function() {
if (typeof $rootScope.settings === 'object') {
// angular set's up the nested object therefore we have to check like this to avoid test crash
expect($rootScope.settings.max).toBeUndefined();
}
expect($rootScope.settings).toBeUndefined();
expect(getBar(0).attr('aria-valuemax')).toBe('100');
$rootScope.settings = {
max: 300,
value: 40
};
$rootScope.$digest();
expect($rootScope.settings.max).toBe(300);
expect(getBar(0).attr('aria-valuemax')).toBe('300');
});
});


describe('"type" attribute', function() {
beforeEach(inject(function() {
$rootScope.type = 'success';
Expand Down

0 comments on commit 258b341

Please sign in to comment.