diff options
| author | Igor Minar | 2011-02-07 14:32:28 -0800 | 
|---|---|---|
| committer | Igor Minar | 2011-02-07 23:56:33 -0800 | 
| commit | 86321d1f5722e0aefcdbe8f3e5a14bd15d4caecb (patch) | |
| tree | f4375a0af8af9da94878214f3c24ad33d7ed97f4 /test | |
| parent | 8724e97b7e6638797d3607a45682ef0b76311aae (diff) | |
| download | angular.js-86321d1f5722e0aefcdbe8f3e5a14bd15d4caecb.tar.bz2 | |
add support for hashSearch redirection and custom redirection functions
Diffstat (limited to 'test')
| -rw-r--r-- | test/servicesSpec.js | 43 | 
1 files changed, 35 insertions, 8 deletions
| diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 637f767c..0186684e 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -523,14 +523,14 @@ describe("service", function(){        expect(onChangeSpy.callCount).toBe(1);      }); - -    it('should interpolate route variables in the redirected path from hashPath', function() { +    it('should interpolate route variables in the redirected hashPath from the original hashPath', +        function() {        var scope = angular.scope(),            $location = scope.$service('$location'),            $browser = scope.$service('$browser'),            $route = scope.$service('$route'); -      $route.when('/foo/:id/foo/:subid/:ignoredId', {redirectTo: '/bar/:id/:subid/23'}); +      $route.when('/foo/:id/foo/:subid/:extraId', {redirectTo: '/bar/:id/:subid/23'});        $route.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'});        scope.$eval(); @@ -538,27 +538,54 @@ describe("service", function(){        scope.$eval(); //triggers initial route change - match the redirect route        $browser.defer.flush(); //triger route change - match the route we redirected to -      expect($location.hash).toBe('/bar/id1/subid3/23'); +      expect($location.hash).toBe('/bar/id1/subid3/23?extraId=gah');        expect($route.current.template).toBe('bar.html');      }); -    it('should interpolate route variables in the redirected path from hashSearch', function() { +    it('should interpolate route variables in the redirected hashPath from the original hashSearch', +        function() {        var scope = angular.scope(),            $location = scope.$service('$location'),            $browser = scope.$service('$browser'),            $route = scope.$service('$route');        $route.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'}); -      $route.when('/foo/:id', {redirectTo: '/bar/:id/:subid/99'}); +      $route.when('/foo/:id/:extra', {redirectTo: '/bar/:id/:subid/99'});        scope.$eval(); -      $location.hash = '/foo/id3?subid=sid1&ignored=true'; +      $location.hash = '/foo/id3/eId?subid=sid1&appended=true';        scope.$eval(); //triggers initial route change - match the redirect route        $browser.defer.flush(); //triger route change - match the route we redirected to -      expect($location.hash).toBe('/bar/id3/sid1/99'); +      expect($location.hash).toBe('/bar/id3/sid1/99?appended=true&extra=eId');        expect($route.current.template).toBe('bar.html');      }); + +    it('should allow custom redirectTo function to be used', function() { +      var scope = angular.scope(), +          $location = scope.$service('$location'), +          $browser = scope.$service('$browser'), +          $route = scope.$service('$route'); + +      $route.when('/bar/:id/:subid/:subsubid', {template: 'bar.html'}); +      $route.when('/foo/:id', +                  {redirectTo: customRedirectFn}); +      scope.$eval(); + +      $location.hash = '/foo/id3?subid=sid1&appended=true'; +      scope.$eval(); //triggers initial route change - match the redirect route +      $browser.defer.flush(); //triger route change - match the route we redirected to + +      expect($location.hash).toBe('custom'); + +      function customRedirectFn(routePathParams, hash, hashPath, hashSearch) { +        expect(routePathParams).toEqual({id: 'id3'}); +        expect(hash).toEqual($location.hash); +        expect(hashPath).toEqual($location.hashPath); +        expect(hashSearch).toEqual($location.hashSearch); +        return 'custom'; +      } +    });    }); | 
