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

Commit 3e60d27

Browse files
Foxandxssaroop
authored andcommitted
chore(buttons): update tests
Closes #4644
1 parent 72fb495 commit 3e60d27

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

Diff for: src/buttons/test/buttons.spec.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,21 @@ describe('buttons', function() {
109109
});
110110

111111
describe('setting buttonConfig', function() {
112-
var originalActiveClass, originalToggleEvent;
112+
var uibButtonConfig, originalActiveClass, originalToggleEvent;
113113

114-
beforeEach(inject(function(uibButtonConfig) {
114+
beforeEach(inject(function(_uibButtonConfig_) {
115+
uibButtonConfig = _uibButtonConfig_;
115116
originalActiveClass = uibButtonConfig.activeClass;
116117
originalToggleEvent = uibButtonConfig.toggleEvent;
117118
uibButtonConfig.activeClass = false;
118119
uibButtonConfig.toggleEvent = false;
119120
}));
120121

121-
afterEach(inject(function(uibButtonConfig) {
122+
afterEach(function() {
122123
// return it to the original value
123124
uibButtonConfig.activeClass = originalActiveClass;
124125
uibButtonConfig.toggleEvent = originalToggleEvent;
125-
}));
126+
});
126127

127128
it('should use default config when buttonConfig.activeClass and buttonConfig.toggleEvent is false', function() {
128129
$scope.model = false;
@@ -133,6 +134,29 @@ describe('buttons', function() {
133134
$scope.$digest();
134135
expect(btn).toHaveClass('active');
135136
});
137+
138+
it('should be able to use a different active class', function() {
139+
uibButtonConfig.activeClass = 'foo';
140+
$scope.model = false;
141+
var btn = compileButton('<button ng-model="model" uib-btn-checkbox>click</button>', $scope);
142+
expect(btn).not.toHaveClass('foo');
143+
144+
$scope.model = true;
145+
$scope.$digest();
146+
expect(btn).toHaveClass('foo');
147+
});
148+
149+
it('should be able to use a different toggle event', function() {
150+
uibButtonConfig.toggleEvent = 'mouseenter';
151+
$scope.model = false;
152+
var btn = compileButton('<button ng-model="model" uib-btn-checkbox>click</button>', $scope);
153+
expect(btn).not.toHaveClass('active');
154+
155+
btn.trigger('mouseenter');
156+
157+
$scope.$digest();
158+
expect(btn).toHaveClass('active');
159+
});
136160
});
137161

138162
});
@@ -157,7 +181,7 @@ describe('buttons', function() {
157181
}));
158182

159183
//model -> UI
160-
it('should work correctly set active class based on model', function() {
184+
it('should set active class based on model', function() {
161185
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>', $scope);
162186
expect(btns.eq(0)).not.toHaveClass('active');
163187
expect(btns.eq(1)).not.toHaveClass('active');
@@ -169,7 +193,7 @@ describe('buttons', function() {
169193
});
170194

171195
//UI->model
172-
it('should work correctly set active class based on model', function() {
196+
it('should set active class via click', function() {
173197
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>', $scope);
174198
expect($scope.model).toBeUndefined();
175199

@@ -203,7 +227,7 @@ describe('buttons', function() {
203227
expect(btns.eq(1)).toHaveClass('active');
204228
});
205229

206-
it('should do nothing when click active radio', function() {
230+
it('should do nothing when clicking an active radio', function() {
207231
$scope.model = 1;
208232
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>', $scope);
209233
expect(btns.eq(0)).toHaveClass('active');
@@ -266,7 +290,7 @@ describe('buttons', function() {
266290
});
267291

268292
//UI->model
269-
it('should unset active class based on model', function() {
293+
it('should unset active class via click', function() {
270294
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1" uncheckable>click1</button><button ng-model="model" uib-btn-radio="2" uncheckable>click2</button>', $scope);
271295
expect($scope.model).toBeUndefined();
272296

0 commit comments

Comments
 (0)