diff options
| author | joshrtay | 2012-12-26 21:45:11 -0800 | 
|---|---|---|
| committer | James deBoer | 2013-08-12 11:04:37 -0700 | 
| commit | 04cebcc133c8b433a3ac5f72ed19f3631778142b (patch) | |
| tree | 17c7307558e2c41624d1092a7e826a20967112ee /test/ngRoute/routeSpec.js | |
| parent | c173ca412878d537b18df01f39e400ea48a4b398 (diff) | |
| download | angular.js-04cebcc133c8b433a3ac5f72ed19f3631778142b.tar.bz2 | |
feat($route): express style route matching
Added new route matching capabilities:
  - optional param
Changed route matching syntax:
 - named wildcard
BREAKING CHANGE: the syntax for named wildcard parameters in routes
    has changed from *wildcard to :wildcard*
    To migrate the code, follow the example below.  Here, *highlight becomes
    :highlight*:
    Before:
    $routeProvider.when('/Book1/:book/Chapter/:chapter/*highlight/edit',
              {controller: noop, templateUrl: 'Chapter.html'});
    After:
    $routeProvider.when('/Book1/:book/Chapter/:chapter/:highlight*/edit',
            {controller: noop, templateUrl: 'Chapter.html'});
Diffstat (limited to 'test/ngRoute/routeSpec.js')
| -rw-r--r-- | test/ngRoute/routeSpec.js | 40 | 
1 files changed, 36 insertions, 4 deletions
diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 29c2b798..0064c26c 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -68,9 +68,9 @@ describe('$route', function() {          nextRoute;      module(function($routeProvider) { -      $routeProvider.when('/Book1/:book/Chapter/:chapter/*highlight/edit', +      $routeProvider.when('/Book1/:book/Chapter/:chapter/:highlight*/edit',            {controller: noop, templateUrl: 'Chapter.html'}); -      $routeProvider.when('/Book2/:book/*highlight/Chapter/:chapter', +      $routeProvider.when('/Book2/:book/:highlight*/Chapter/:chapter',            {controller: noop, templateUrl: 'Chapter.html'});        $routeProvider.when('/Blank', {});      }); @@ -127,9 +127,9 @@ describe('$route', function() {          nextRoute;      module(function($routeProvider) { -      $routeProvider.when('/Book1/:book/Chapter/:chapter/*highlight/edit', +      $routeProvider.when('/Book1/:book/Chapter/:chapter/:highlight*/edit',            {controller: noop, templateUrl: 'Chapter.html', caseInsensitiveMatch: true}); -      $routeProvider.when('/Book2/:book/*highlight/Chapter/:chapter', +      $routeProvider.when('/Book2/:book/:highlight*/Chapter/:chapter',            {controller: noop, templateUrl: 'Chapter.html'});        $routeProvider.when('/Blank', {});      }); @@ -245,6 +245,31 @@ describe('$route', function() {    }); +  describe('should match a route that contains optional params in the path', function() { +    beforeEach(module(function($routeProvider) { +      $routeProvider.when('/test/:opt?/:baz/edit', {templateUrl: 'test.html'}); +    })); + +    it('matches a URL with optional params', inject(function($route, $location, $rootScope) { +      $location.path('/test/optValue/bazValue/edit'); +      $rootScope.$digest(); +      expect($route.current).toBeDefined(); +    })); + +    it('matches a URL without optional param', inject(function($route, $location, $rootScope) { +      $location.path('/test//bazValue/edit'); +      $rootScope.$digest(); +      expect($route.current).toBeDefined(); +    })); + +    it('not match a URL with a required param', inject(function($route, $location, $rootScope) { +      $location.path('///edit'); +      $rootScope.$digest(); +      expect($route.current).not.toBeDefined(); +    })); +  }); + +    it('should change route even when only search param changes', function() {      module(function($routeProvider) {        $routeProvider.when('/test', {templateUrl: 'test.html'}); @@ -723,6 +748,8 @@ describe('$route', function() {        module(function($routeProvider) {          $routeProvider.when('/foo/:id/foo/:subid/:extraId', {redirectTo: '/bar/:id/:subid/23'});          $routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'}); +        $routeProvider.when('/baz/:id/:path*', {redirectTo: '/path/:path/:id'}); +        $routeProvider.when('/path/:path*/:id', {templateUrl: 'foo.html'});        });        inject(function($route, $location, $rootScope) { @@ -732,6 +759,11 @@ describe('$route', function() {          expect($location.path()).toEqual('/bar/id1/subid3/23');          expect($location.search()).toEqual({extraId: 'gah'});          expect($route.current.templateUrl).toEqual('bar.html'); + +        $location.path('/baz/1/foovalue/barvalue'); +        $rootScope.$digest(); +        expect($location.path()).toEqual('/path/foovalue/barvalue/1'); +        expect($route.current.templateUrl).toEqual('foo.html');        });      });  | 
