@@ -55,7 +55,7 @@ describe('widget', function() {
55
55
} ) ;
56
56
57
57
58
- describe ( 'ng:include' , inject ( function ( $rootScope , $compile ) {
58
+ describe ( 'ng:include' , function ( ) {
59
59
60
60
function putIntoCache ( url , content ) {
61
61
return function ( $templateCache ) {
@@ -227,9 +227,74 @@ describe('widget', function() {
227
227
expect ( log . join ( '; ' ) ) . toEqual ( 'url2; url2' ) ; // it's here twice because we go through at
228
228
// least two digest cycles
229
229
} ) ) ;
230
- } ) ) ;
231
230
232
231
232
+ describe ( 'autoscoll' , function ( ) {
233
+ var autoScrollSpy ;
234
+
235
+ function spyOnAutoScroll ( ) {
236
+ return function ( $provide ) {
237
+ autoScrollSpy = jasmine . createSpy ( '$autoScroll' ) ;
238
+ $provide . value ( '$autoScroll' , autoScrollSpy ) ;
239
+ } ;
240
+ }
241
+
242
+ function compileAndLink ( tpl ) {
243
+ return function ( $compile , $rootScope ) {
244
+ $compile ( tpl ) ( $rootScope ) ;
245
+ } ;
246
+ }
247
+
248
+ function changeTplAndValueTo ( template , value ) {
249
+ return function ( $rootScope , $browser ) {
250
+ $rootScope . $apply ( function ( ) {
251
+ $rootScope . tpl = template ;
252
+ $rootScope . value = value ;
253
+ } ) ;
254
+ $browser . defer . flush ( ) ;
255
+ } ;
256
+ }
257
+
258
+ beforeEach ( inject (
259
+ spyOnAutoScroll ( ) ,
260
+ putIntoCache ( 'template.html' , 'CONTENT' ) ,
261
+ putIntoCache ( 'another.html' , 'CONTENT' ) ) ) ;
262
+
263
+
264
+ it ( 'should call $autoScroll if autoscroll attribute is present' , inject (
265
+ compileAndLink ( '<ng:include src="tpl" autoscroll></ng:include>' ) ,
266
+ changeTplAndValueTo ( 'template.html' ) , function ( ) {
267
+ expect ( autoScrollSpy ) . toHaveBeenCalledOnce ( ) ;
268
+ } ) ) ;
269
+
270
+
271
+ it ( 'should call $autoScroll if autoscroll evaluates to true' , inject (
272
+ compileAndLink ( '<ng:include src="tpl" autoscroll="value"></ng:include>' ) ,
273
+ changeTplAndValueTo ( 'template.html' , true ) ,
274
+ changeTplAndValueTo ( 'another.html' , 'some-string' ) ,
275
+ changeTplAndValueTo ( 'template.html' , 100 ) , function ( ) {
276
+ expect ( autoScrollSpy ) . toHaveBeenCalled ( ) ;
277
+ expect ( autoScrollSpy . callCount ) . toBe ( 3 ) ;
278
+ } ) ) ;
279
+
280
+
281
+ it ( 'should not call $autoScroll if autoscroll attribute is not present' , inject (
282
+ compileAndLink ( '<ng:include src="tpl"></ng:include>' ) ,
283
+ changeTplAndValueTo ( 'template.html' ) , function ( ) {
284
+ expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
285
+ } ) ) ;
286
+
287
+
288
+ it ( 'should not call $autoScroll if autoscroll evaluates to false' , inject (
289
+ compileAndLink ( '<ng:include src="tpl" autoscroll="value"></ng:include>' ) ,
290
+ changeTplAndValueTo ( 'template.html' , false ) ,
291
+ changeTplAndValueTo ( 'template.html' , undefined ) ,
292
+ changeTplAndValueTo ( 'template.html' , null ) , function ( ) {
293
+ expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
294
+ } ) ) ;
295
+ } ) ;
296
+ } ) ;
297
+
233
298
describe ( 'a' , function ( ) {
234
299
it ( 'should prevent default action to be executed when href is empty' ,
235
300
inject ( function ( $rootScope , $compile ) {
0 commit comments