Skip to content

Commit a9c9f56

Browse files
committed
test(ngRoute): add test case for special params in redirectUrl
Make sure that :name? and :name* vars are properly interpolated in redirectUrl.
1 parent 6f77610 commit a9c9f56

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/ngRoute/routeSpec.js

+41
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,47 @@ describe('$route', function() {
813813
});
814814

815815

816+
it('should interpolate optional route vars in the redirected path from original path', function() {
817+
module(function($routeProvider) {
818+
$routeProvider.when('/foo/:id/foo/:subid?/:extraId', {redirectTo: '/bar/:id/:subid?/23'});
819+
$routeProvider.when('/bar/:id/:subid?/:subsubid', {templateUrl: 'bar.html'});
820+
});
821+
822+
inject(function($route, $location, $rootScope) {
823+
$location.path('/foo/id1/foo/subid3/gah');
824+
$rootScope.$digest();
825+
826+
expect($location.path()).toEqual('/bar/id1/subid3/23');
827+
expect($location.search()).toEqual({extraId: 'gah'});
828+
expect($route.current.params).toEqual({id:'id1', subid:'subid3', subsubid:'23', extraId:'gah'});
829+
expect($route.current.templateUrl).toEqual('bar.html');
830+
831+
$location.path('/foo/id1/foo/gah');
832+
$rootScope.$digest();
833+
834+
expect($location.path()).toEqual('/bar/id1/23');
835+
expect($location.search()).toEqual({extraId: 'gah'});
836+
expect($route.current.params).toEqual({id:'id1', subsubid:'23', extraId:'gah'});
837+
});
838+
});
839+
840+
841+
it('should interpolate catch-all route vars in the redirected path from original path', function() {
842+
module(function($routeProvider) {
843+
$routeProvider.when('/baz/:id/:path*', {redirectTo: '/path/:path*/:id'});
844+
$routeProvider.when('/path/:path*/:id', {templateUrl: 'foo.html'});
845+
});
846+
847+
inject(function($route, $location, $rootScope) {
848+
$location.path('/baz/1/foovalue/barvalue');
849+
$rootScope.$digest();
850+
expect($location.path()).toEqual('/path/foovalue/barvalue/1');
851+
expect($route.current.params).toEqual({id:'1', path:'foovalue/barvalue'});
852+
expect($route.current.templateUrl).toEqual('foo.html');
853+
});
854+
});
855+
856+
816857
it('should interpolate route vars in the redirected path from original search', function() {
817858
module(function($routeProvider) {
818859
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});

0 commit comments

Comments
 (0)