This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
improve interpolation of params in ngRoute #8200
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -813,6 +813,47 @@ describe('$route', function() { | |
}); | ||
|
||
|
||
it('should interpolate optional route vars in the redirected path from original path', 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'}); | ||
}); | ||
|
||
inject(function($route, $location, $rootScope) { | ||
$location.path('/foo/id1/foo/subid3/gah'); | ||
$rootScope.$digest(); | ||
|
||
expect($location.path()).toEqual('/bar/id1/subid3/23'); | ||
expect($location.search()).toEqual({extraId: 'gah'}); | ||
expect($route.current.params).toEqual({id:'id1', subid:'subid3', subsubid:'23', extraId:'gah'}); | ||
expect($route.current.templateUrl).toEqual('bar.html'); | ||
|
||
$location.path('/foo/id1/foo/gah'); | ||
$rootScope.$digest(); | ||
|
||
expect($location.path()).toEqual('/bar/id1/23'); | ||
expect($location.search()).toEqual({extraId: 'gah'}); | ||
expect($route.current.params).toEqual({id:'id1', subsubid:'23', extraId:'gah'}); | ||
}); | ||
}); | ||
|
||
|
||
it('should interpolate catch-all route vars in the redirected path from original path', function() { | ||
module(function($routeProvider) { | ||
$routeProvider.when('/baz/:id/:path*', {redirectTo: '/path/:path*/:id'}); | ||
$routeProvider.when('/path/:path*/:id', {templateUrl: 'foo.html'}); | ||
}); | ||
|
||
inject(function($route, $location, $rootScope) { | ||
$location.path('/baz/1/foovalue/barvalue'); | ||
$rootScope.$digest(); | ||
expect($location.path()).toEqual('/path/foovalue/barvalue/1'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also split this test apart, because this is not testing just one unit of functionality. It would be better to have separate test cases for each of the things being tested here. |
||
expect($route.current.params).toEqual({id:'1', path:'foovalue/barvalue'}); | ||
expect($route.current.templateUrl).toEqual('foo.html'); | ||
}); | ||
}); | ||
|
||
|
||
it('should interpolate route vars in the redirected path from original search', function() { | ||
module(function($routeProvider) { | ||
$routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test that
$route.current.params
equal what we expect, not just$location.search()
(for each of these cases).