@@ -260,4 +260,139 @@ describe('$route', function() {
260
260
}
261
261
} ) ;
262
262
} ) ;
263
+
264
+
265
+ describe ( 'reloadOnSearch' , function ( ) {
266
+ it ( 'should reload a route when reloadOnSearch is enabled and hashSearch changes' , function ( ) {
267
+ var scope = angular . scope ( ) ,
268
+ $location = scope . $service ( '$location' ) ,
269
+ $route = scope . $service ( '$route' ) ,
270
+ reloaded = jasmine . createSpy ( 'route reload' ) ;
271
+
272
+ $route . when ( '/foo' , { controller : FooCtrl } ) ;
273
+ $route . onChange ( reloaded ) ;
274
+
275
+ function FooCtrl ( ) {
276
+ reloaded ( ) ;
277
+ }
278
+
279
+ $location . updateHash ( '/foo' ) ;
280
+ scope . $digest ( ) ;
281
+ expect ( reloaded ) . toHaveBeenCalled ( ) ;
282
+ reloaded . reset ( ) ;
283
+
284
+ // trigger reload
285
+ $location . hashSearch . foo = 'bar' ;
286
+ scope . $digest ( ) ;
287
+ expect ( reloaded ) . toHaveBeenCalled ( ) ;
288
+ } ) ;
289
+
290
+
291
+ it ( 'should not reload a route when reloadOnSearch is disabled and only hashSearch changes' ,
292
+ function ( ) {
293
+ var scope = angular . scope ( ) ,
294
+ $location = scope . $service ( '$location' ) ,
295
+ $route = scope . $service ( '$route' ) ,
296
+ reloaded = jasmine . createSpy ( 'route reload' ) ;
297
+
298
+ $route . when ( '/foo' , { controller : FooCtrl , reloadOnSearch : false } ) ;
299
+ $route . onChange ( reloaded ) ;
300
+
301
+ function FooCtrl ( ) {
302
+ reloaded ( ) ;
303
+ }
304
+
305
+ expect ( reloaded ) . not . toHaveBeenCalled ( ) ;
306
+
307
+ $location . updateHash ( '/foo' ) ;
308
+ scope . $digest ( ) ;
309
+ expect ( reloaded ) . toHaveBeenCalled ( ) ;
310
+ reloaded . reset ( ) ;
311
+
312
+ // don't trigger reload
313
+ $location . hashSearch . foo = 'bar' ;
314
+ scope . $digest ( ) ;
315
+ expect ( reloaded ) . not . toHaveBeenCalled ( ) ;
316
+ } ) ;
317
+
318
+
319
+ it ( 'should reload reloadOnSearch route when url differs only in route path param' , function ( ) {
320
+ var scope = angular . scope ( ) ,
321
+ $location = scope . $service ( '$location' ) ,
322
+ $route = scope . $service ( '$route' ) ,
323
+ reloaded = jasmine . createSpy ( 'routeReload' ) ,
324
+ onRouteChange = jasmine . createSpy ( 'onRouteChange' ) ;
325
+
326
+ $route . when ( '/foo/:fooId' , { controller : FooCtrl , reloadOnSearch : false } ) ;
327
+ $route . onChange ( onRouteChange ) ;
328
+
329
+ function FooCtrl ( ) {
330
+ reloaded ( ) ;
331
+ }
332
+
333
+ expect ( reloaded ) . not . toHaveBeenCalled ( ) ;
334
+ expect ( onRouteChange ) . not . toHaveBeenCalled ( ) ;
335
+
336
+ $location . updateHash ( '/foo/aaa' ) ;
337
+ scope . $digest ( ) ;
338
+ expect ( reloaded ) . toHaveBeenCalled ( ) ;
339
+ expect ( onRouteChange ) . toHaveBeenCalled ( ) ;
340
+ reloaded . reset ( ) ;
341
+ onRouteChange . reset ( ) ;
342
+
343
+ $location . updateHash ( '/foo/bbb' ) ;
344
+ scope . $digest ( ) ;
345
+ expect ( reloaded ) . toHaveBeenCalled ( ) ;
346
+ expect ( onRouteChange ) . toHaveBeenCalled ( ) ;
347
+ reloaded . reset ( ) ;
348
+ onRouteChange . reset ( ) ;
349
+
350
+ $location . hashSearch . foo = 'bar' ;
351
+ scope . $digest ( ) ;
352
+ expect ( reloaded ) . not . toHaveBeenCalled ( ) ;
353
+ expect ( onRouteChange ) . not . toHaveBeenCalled ( ) ;
354
+ } ) ;
355
+
356
+
357
+ it ( 'should update route params when reloadOnSearch is disabled and hashSearch' , function ( ) {
358
+ var scope = angular . scope ( ) ,
359
+ $location = scope . $service ( '$location' ) ,
360
+ $route = scope . $service ( '$route' ) ,
361
+ routeParams = jasmine . createSpy ( 'routeParams' ) ;
362
+
363
+ $route . when ( '/foo' , { controller : FooCtrl } ) ;
364
+ $route . when ( '/bar/:barId' , { controller : FooCtrl , reloadOnSearch : false } ) ;
365
+
366
+ function FooCtrl ( ) {
367
+ this . $watch ( function ( ) {
368
+ return $route . current . params ;
369
+ } , function ( scope , value ) {
370
+ routeParams ( value ) ;
371
+ } ) ;
372
+ }
373
+
374
+ expect ( routeParams ) . not . toHaveBeenCalled ( ) ;
375
+
376
+ $location . updateHash ( '/foo' ) ;
377
+ scope . $digest ( ) ;
378
+ expect ( routeParams ) . toHaveBeenCalledWith ( { } ) ;
379
+ routeParams . reset ( ) ;
380
+
381
+ // trigger reload
382
+ $location . hashSearch . foo = 'bar' ;
383
+ scope . $digest ( ) ;
384
+ expect ( routeParams ) . toHaveBeenCalledWith ( { foo : 'bar' } ) ;
385
+ routeParams . reset ( ) ;
386
+
387
+ $location . updateHash ( '/bar/123' ) ;
388
+ scope . $digest ( ) ;
389
+ expect ( routeParams ) . toHaveBeenCalledWith ( { barId : '123' } ) ;
390
+ routeParams . reset ( ) ;
391
+
392
+ // don't trigger reload
393
+ $location . hashSearch . foo = 'bar' ;
394
+ scope . $digest ( ) ;
395
+ expect ( routeParams ) . toHaveBeenCalledWith ( { barId : '123' , foo : 'bar' } ) ;
396
+ } ) ;
397
+ } ) ;
263
398
} ) ;
0 commit comments