Skip to content

Commit

Permalink
fix(buttons): add unit tests for buttons
Browse files Browse the repository at this point in the history
Adds unit tests to buttons, helping bring test coverage to 100%

Closes angular-ui#3030
  • Loading branch information
cookfront authored and wesleycho committed Mar 25, 2015
1 parent 35b8512 commit 9468d72
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ describe('buttons', function () {
expect(btn).toHaveClass('active');
expect($scope.model).toEqual(2);
});

describe('setting buttonConfig', function () {
var originalActiveClass, originalToggleEvent;

beforeEach(inject(function(buttonConfig) {
originalActiveClass = buttonConfig.activeClass;
originalToggleEvent = buttonConfig.toggleEvent;
buttonConfig.activeClass = false;
buttonConfig.toggleEvent = false;
}));

afterEach(inject(function(buttonConfig) {
// return it to the original value
buttonConfig.activeClass = originalActiveClass;
buttonConfig.toggleEvent = originalToggleEvent;
}));

it('should use default config when buttonConfig.activeClass and buttonConfig.toggleEvent is false', function () {
$scope.model = false;
var btn = compileButton('<button ng-model="model" btn-checkbox>click</button>', $scope);
expect(btn).not.toHaveClass('active');

$scope.model = true;
$scope.$digest();
expect(btn).toHaveClass('active');
});
});

});

describe('radio', function () {
Expand Down Expand Up @@ -137,6 +165,18 @@ describe('buttons', function () {
expect(btns.eq(1)).toHaveClass('active');
});

it('should do nothing when click active radio', function () {
$scope.model = 1;
var btns = compileButtons('<button ng-model="model" btn-radio="1">click1</button><button ng-model="model" btn-radio="2">click2</button>', $scope);
expect(btns.eq(0)).toHaveClass('active');
expect(btns.eq(1)).not.toHaveClass('active');

btns.eq(0).click();
$scope.$digest();
expect(btns.eq(0)).toHaveClass('active');
expect(btns.eq(1)).not.toHaveClass('active');
});

describe('uncheckable', function () {
//model -> UI
it('should set active class based on model', function () {
Expand Down

0 comments on commit 9468d72

Please sign in to comment.