@@ -6,7 +6,7 @@ describe('rating directive', function() {
6
6
$compile = _$compile_ ;
7
7
$rootScope = _$rootScope_ ;
8
8
$rootScope . rate = 3 ;
9
- element = $compile ( '<rating ng-model="rate"></rating>' ) ( $rootScope ) ;
9
+ element = $compile ( '<uib- rating ng-model="rate"></uib- rating>' ) ( $rootScope ) ;
10
10
$rootScope . $digest ( ) ;
11
11
} ) ) ;
12
12
@@ -15,14 +15,14 @@ describe('rating directive', function() {
15
15
}
16
16
17
17
function getStar ( number ) {
18
- return getStars ( ) . eq ( number - 1 ) ;
18
+ return getStars ( ) . eq ( number - 1 ) ;
19
19
}
20
20
21
21
function getState ( classOn , classOff ) {
22
22
var stars = getStars ( ) ;
23
23
var state = [ ] ;
24
24
for ( var i = 0 , n = stars . length ; i < n ; i ++ ) {
25
- state . push ( ( stars . eq ( i ) . hasClass ( classOn || 'glyphicon-star' ) && ! stars . eq ( i ) . hasClass ( classOff || 'glyphicon-star-empty' ) ) ) ;
25
+ state . push ( ( stars . eq ( i ) . hasClass ( classOn || 'glyphicon-star' ) && ! stars . eq ( i ) . hasClass ( classOff || 'glyphicon-star-empty' ) ) ) ;
26
26
}
27
27
return state ;
28
28
}
@@ -109,7 +109,7 @@ describe('rating directive', function() {
109
109
} ) ;
110
110
111
111
it ( 'shows different number of icons when `max` attribute is set' , function ( ) {
112
- element = $compile ( '<rating ng-model="rate" max="7"></rating>' ) ( $rootScope ) ;
112
+ element = $compile ( '<uib- rating ng-model="rate" max="7"></uib- rating>' ) ( $rootScope ) ;
113
113
$rootScope . $digest ( ) ;
114
114
115
115
expect ( getStars ( ) . length ) . toBe ( 7 ) ;
@@ -118,15 +118,15 @@ describe('rating directive', function() {
118
118
119
119
it ( 'shows different number of icons when `max` attribute is from scope variable' , function ( ) {
120
120
$rootScope . max = 15 ;
121
- element = $compile ( '<rating ng-model="rate" max="max"></rating>' ) ( $rootScope ) ;
121
+ element = $compile ( '<uib- rating ng-model="rate" max="max"></uib- rating>' ) ( $rootScope ) ;
122
122
$rootScope . $digest ( ) ;
123
123
expect ( getStars ( ) . length ) . toBe ( 15 ) ;
124
124
expect ( element . attr ( 'aria-valuemax' ) ) . toBe ( '15' ) ;
125
125
} ) ;
126
126
127
127
it ( 'handles readonly attribute' , function ( ) {
128
128
$rootScope . isReadonly = true ;
129
- element = $compile ( '<rating ng-model="rate" readonly="isReadonly"></rating>' ) ( $rootScope ) ;
129
+ element = $compile ( '<uib- rating ng-model="rate" readonly="isReadonly"></uib- rating>' ) ( $rootScope ) ;
130
130
$rootScope . $digest ( ) ;
131
131
132
132
expect ( getState ( ) ) . toEqual ( [ true , true , true , false , false ] ) ;
@@ -146,7 +146,7 @@ describe('rating directive', function() {
146
146
147
147
it ( 'should fire onHover' , function ( ) {
148
148
$rootScope . hoveringOver = jasmine . createSpy ( 'hoveringOver' ) ;
149
- element = $compile ( '<rating ng-model="rate" on-hover="hoveringOver(value)"></rating>' ) ( $rootScope ) ;
149
+ element = $compile ( '<uib- rating ng-model="rate" on-hover="hoveringOver(value)"></uib- rating>' ) ( $rootScope ) ;
150
150
$rootScope . $digest ( ) ;
151
151
152
152
getStar ( 3 ) . trigger ( 'mouseover' ) ;
@@ -156,7 +156,7 @@ describe('rating directive', function() {
156
156
157
157
it ( 'should fire onLeave' , function ( ) {
158
158
$rootScope . leaving = jasmine . createSpy ( 'leaving' ) ;
159
- element = $compile ( '<rating ng-model="rate" on-leave="leaving()"></rating>' ) ( $rootScope ) ;
159
+ element = $compile ( '<uib- rating ng-model="rate" on-leave="leaving()"></uib- rating>' ) ( $rootScope ) ;
160
160
$rootScope . $digest ( ) ;
161
161
162
162
element . trigger ( 'mouseleave' ) ;
@@ -216,7 +216,7 @@ describe('rating directive', function() {
216
216
beforeEach ( inject ( function ( ) {
217
217
$rootScope . classOn = 'icon-ok-sign' ;
218
218
$rootScope . classOff = 'icon-ok-circle' ;
219
- element = $compile ( '<rating ng-model="rate" state-on="classOn" state-off="classOff"></rating>' ) ( $rootScope ) ;
219
+ element = $compile ( '<uib- rating ng-model="rate" state-on="classOn" state-off="classOff"></uib- rating>' ) ( $rootScope ) ;
220
220
$rootScope . $digest ( ) ;
221
221
} ) ) ;
222
222
@@ -233,7 +233,7 @@ describe('rating directive', function() {
233
233
{ stateOn : 'heart' } ,
234
234
{ stateOff : 'off' }
235
235
] ;
236
- element = $compile ( '<rating ng-model="rate" rating-states="states"></rating>' ) ( $rootScope ) ;
236
+ element = $compile ( '<uib- rating ng-model="rate" rating-states="states"></uib- rating>' ) ( $rootScope ) ;
237
237
$rootScope . $digest ( ) ;
238
238
} ) ) ;
239
239
@@ -256,20 +256,20 @@ describe('rating directive', function() {
256
256
} ) ;
257
257
} ) ;
258
258
259
- describe ( 'setting ratingConfig ' , function ( ) {
259
+ describe ( 'setting uibRatingConfig ' , function ( ) {
260
260
var originalConfig = { } ;
261
- beforeEach ( inject ( function ( ratingConfig ) {
261
+ beforeEach ( inject ( function ( uibRatingConfig ) {
262
262
$rootScope . rate = 5 ;
263
- angular . extend ( originalConfig , ratingConfig ) ;
264
- ratingConfig . max = 10 ;
265
- ratingConfig . stateOn = 'on' ;
266
- ratingConfig . stateOff = 'off' ;
267
- element = $compile ( '<rating ng-model="rate"></rating>' ) ( $rootScope ) ;
263
+ angular . extend ( originalConfig , uibRatingConfig ) ;
264
+ uibRatingConfig . max = 10 ;
265
+ uibRatingConfig . stateOn = 'on' ;
266
+ uibRatingConfig . stateOff = 'off' ;
267
+ element = $compile ( '<uib- rating ng-model="rate"></uib- rating>' ) ( $rootScope ) ;
268
268
$rootScope . $digest ( ) ;
269
269
} ) ) ;
270
- afterEach ( inject ( function ( ratingConfig ) {
270
+ afterEach ( inject ( function ( uibRatingConfig ) {
271
271
// return it to the original state
272
- angular . extend ( ratingConfig , originalConfig ) ;
272
+ angular . extend ( uibRatingConfig , originalConfig ) ;
273
273
} ) ) ;
274
274
275
275
it ( 'should change number of icon elements' , function ( ) {
@@ -289,16 +289,16 @@ describe('rating directive', function() {
289
289
290
290
describe ( 'shows different title when `max` attribute is greater than the titles array ' , function ( ) {
291
291
var originalConfig = { } ;
292
- beforeEach ( inject ( function ( ratingConfig ) {
292
+ beforeEach ( inject ( function ( uibRatingConfig ) {
293
293
$rootScope . rate = 5 ;
294
- angular . extend ( originalConfig , ratingConfig ) ;
295
- ratingConfig . max = 10 ;
296
- element = $compile ( '<rating ng-model="rate"></rating>' ) ( $rootScope ) ;
294
+ angular . extend ( originalConfig , uibRatingConfig ) ;
295
+ uibRatingConfig . max = 10 ;
296
+ element = $compile ( '<uib- rating ng-model="rate"></uib- rating>' ) ( $rootScope ) ;
297
297
$rootScope . $digest ( ) ;
298
298
} ) ) ;
299
- afterEach ( inject ( function ( ratingConfig ) {
299
+ afterEach ( inject ( function ( uibRatingConfig ) {
300
300
// return it to the original state
301
- angular . extend ( ratingConfig , originalConfig ) ;
301
+ angular . extend ( uibRatingConfig , originalConfig ) ;
302
302
} ) ) ;
303
303
304
304
it ( 'should return the default title for each star' , function ( ) {
@@ -309,20 +309,52 @@ describe('rating directive', function() {
309
309
describe ( 'shows custom titles ' , function ( ) {
310
310
it ( 'should return the custom title for each star' , function ( ) {
311
311
$rootScope . titles = [ 44 , 45 , 46 ] ;
312
- element = $compile ( '<rating ng-model="rate" titles="titles"></rating>' ) ( $rootScope ) ;
312
+ element = $compile ( '<uib- rating ng-model="rate" titles="titles"></uib- rating>' ) ( $rootScope ) ;
313
313
$rootScope . $digest ( ) ;
314
314
expect ( getTitles ( ) ) . toEqual ( [ '44' , '45' , '46' , '4' , '5' ] ) ;
315
315
} ) ;
316
316
it ( 'should return the default title if the custom title is empty' , function ( ) {
317
317
$rootScope . titles = [ ] ;
318
- element = $compile ( '<rating ng-model="rate" titles="titles"></rating>' ) ( $rootScope ) ;
318
+ element = $compile ( '<uib- rating ng-model="rate" titles="titles"></uib- rating>' ) ( $rootScope ) ;
319
319
$rootScope . $digest ( ) ;
320
320
expect ( getTitles ( ) ) . toEqual ( [ 'one' , 'two' , 'three' , 'four' , 'five' ] ) ;
321
321
} ) ;
322
322
it ( 'should return the default title if the custom title is not an array' , function ( ) {
323
- element = $compile ( '<rating ng-model="rate" titles="test"></rating>' ) ( $rootScope ) ;
323
+ element = $compile ( '<uib- rating ng-model="rate" titles="test"></uib- rating>' ) ( $rootScope ) ;
324
324
$rootScope . $digest ( ) ;
325
325
expect ( getTitles ( ) ) . toEqual ( [ 'one' , 'two' , 'three' , 'four' , 'five' ] ) ;
326
326
} ) ;
327
327
} ) ;
328
328
} ) ;
329
+
330
+ /* Deprecation tests below */
331
+
332
+ describe ( 'rating deprecation' , function ( ) {
333
+ beforeEach ( module ( 'ui.bootstrap.rating' ) ) ;
334
+ beforeEach ( module ( 'template/rating/rating.html' ) ) ;
335
+
336
+ it ( 'should suppress warning' , function ( ) {
337
+ module ( function ( $provide ) {
338
+ $provide . value ( '$ratingSuppressWarning' , true ) ;
339
+ } ) ;
340
+
341
+ inject ( function ( $compile , $log , $rootScope ) {
342
+ spyOn ( $log , 'warn' ) ;
343
+
344
+ var element = $compile ( '<rating ng-model="rate"></rating>' ) ( $rootScope ) ;
345
+ $rootScope . $digest ( ) ;
346
+
347
+ expect ( $log . warn . calls . count ( ) ) . toBe ( 0 ) ;
348
+ } ) ;
349
+ } ) ;
350
+
351
+ it ( 'should give warning by default' , inject ( function ( $compile , $log , $rootScope ) {
352
+ spyOn ( $log , 'warn' ) ;
353
+
354
+ var element = $compile ( '<rating ng-model="rate"></rating>' ) ( $rootScope ) ;
355
+ $rootScope . $digest ( ) ;
356
+
357
+ expect ( $log . warn . calls . count ( ) ) . toBe ( 1 ) ;
358
+ expect ( $log . warn . calls . argsFor ( 0 ) ) . toEqual ( [ 'rating is now deprecated. Use uib-rating instead.' ] ) ;
359
+ } ) ) ;
360
+ } ) ;
0 commit comments