@@ -109,20 +109,21 @@ describe('buttons', function() {
109
109
} ) ;
110
110
111
111
describe ( 'setting buttonConfig' , function ( ) {
112
- var originalActiveClass , originalToggleEvent ;
112
+ var uibButtonConfig , originalActiveClass , originalToggleEvent ;
113
113
114
- beforeEach ( inject ( function ( uibButtonConfig ) {
114
+ beforeEach ( inject ( function ( _uibButtonConfig_ ) {
115
+ uibButtonConfig = _uibButtonConfig_ ;
115
116
originalActiveClass = uibButtonConfig . activeClass ;
116
117
originalToggleEvent = uibButtonConfig . toggleEvent ;
117
118
uibButtonConfig . activeClass = false ;
118
119
uibButtonConfig . toggleEvent = false ;
119
120
} ) ) ;
120
121
121
- afterEach ( inject ( function ( uibButtonConfig ) {
122
+ afterEach ( function ( ) {
122
123
// return it to the original value
123
124
uibButtonConfig . activeClass = originalActiveClass ;
124
125
uibButtonConfig . toggleEvent = originalToggleEvent ;
125
- } ) ) ;
126
+ } ) ;
126
127
127
128
it ( 'should use default config when buttonConfig.activeClass and buttonConfig.toggleEvent is false' , function ( ) {
128
129
$scope . model = false ;
@@ -133,6 +134,29 @@ describe('buttons', function() {
133
134
$scope . $digest ( ) ;
134
135
expect ( btn ) . toHaveClass ( 'active' ) ;
135
136
} ) ;
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
+ } ) ;
136
160
} ) ;
137
161
138
162
} ) ;
@@ -157,7 +181,7 @@ describe('buttons', function() {
157
181
} ) ) ;
158
182
159
183
//model -> UI
160
- it ( 'should work correctly set active class based on model' , function ( ) {
184
+ it ( 'should set active class based on model' , function ( ) {
161
185
var btns = compileButtons ( '<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>' , $scope ) ;
162
186
expect ( btns . eq ( 0 ) ) . not . toHaveClass ( 'active' ) ;
163
187
expect ( btns . eq ( 1 ) ) . not . toHaveClass ( 'active' ) ;
@@ -169,7 +193,7 @@ describe('buttons', function() {
169
193
} ) ;
170
194
171
195
//UI->model
172
- it ( 'should work correctly set active class based on model ' , function ( ) {
196
+ it ( 'should set active class via click ' , function ( ) {
173
197
var btns = compileButtons ( '<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>' , $scope ) ;
174
198
expect ( $scope . model ) . toBeUndefined ( ) ;
175
199
@@ -203,7 +227,7 @@ describe('buttons', function() {
203
227
expect ( btns . eq ( 1 ) ) . toHaveClass ( 'active' ) ;
204
228
} ) ;
205
229
206
- it ( 'should do nothing when click active radio' , function ( ) {
230
+ it ( 'should do nothing when clicking an active radio' , function ( ) {
207
231
$scope . model = 1 ;
208
232
var btns = compileButtons ( '<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2">click2</button>' , $scope ) ;
209
233
expect ( btns . eq ( 0 ) ) . toHaveClass ( 'active' ) ;
@@ -266,7 +290,7 @@ describe('buttons', function() {
266
290
} ) ;
267
291
268
292
//UI->model
269
- it ( 'should unset active class based on model ' , function ( ) {
293
+ it ( 'should unset active class via click ' , function ( ) {
270
294
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 ) ;
271
295
expect ( $scope . model ) . toBeUndefined ( ) ;
272
296
0 commit comments