diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ngRoute/routeParamsSpec.js | 33 | ||||
| -rw-r--r-- | test/ngRoute/routeSpec.js | 40 |
2 files changed, 69 insertions, 4 deletions
diff --git a/test/ngRoute/routeParamsSpec.js b/test/ngRoute/routeParamsSpec.js index 1391151c..7c10a922 100644 --- a/test/ngRoute/routeParamsSpec.js +++ b/test/ngRoute/routeParamsSpec.js @@ -45,4 +45,37 @@ describe('$routeParams', function() { expect($routeParams).toEqual({barId: 'barvalue', fooId: 'foovalue'}); }); }); + + it('should correctly extract the params when an optional param name is part of the route', function() { + module(function($routeProvider) { + $routeProvider.when('/bar/:foo?', {}); + $routeProvider.when('/baz/:foo?/edit', {}); + $routeProvider.when('/qux/:bar?/:baz?', {}); + }); + + inject(function($rootScope, $route, $location, $routeParams) { + $location.path('/bar'); + $rootScope.$digest(); + expect($routeParams).toEqual({}); + + $location.path('/bar/fooValue'); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'fooValue'}); + + $location.path('/baz/fooValue/edit'); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'fooValue'}); + + $location.path('/baz/edit'); + $rootScope.$digest(); + expect($routeParams).toEqual({}); + + $location.path('/qux//bazValue'); + $rootScope.$digest(); + expect($routeParams).toEqual({baz: 'bazValue', bar: undefined}); + + }); + }); + + }); 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'); }); }); |
