test(angular1_router): test that location handles query strings

See 6698
This commit is contained in:
Peter Bacon Darwin 2016-02-07 22:09:06 +00:00 committed by Igor Minar
parent 0f22dce036
commit 72ab35bceb
1 changed files with 36 additions and 0 deletions

View File

@ -36,6 +36,14 @@ describe('navigation', function () {
template: '<div>{{$ctrl.number}}</div>', template: '<div>{{$ctrl.number}}</div>',
controller: function () {this.number = 'three'} controller: function () {this.number = 'three'}
}); });
registerComponent('getParams', {
template: '<div>{{$ctrl.params.x}}</div>',
controller: function () {
this.$routerOnActivate = function(next) {
this.params = next.params;
};
}
})
}); });
it('should work in a simple case', function () { it('should work in a simple case', function () {
@ -186,6 +194,21 @@ describe('navigation', function () {
})); }));
it('should pass through query terms to the location', inject(function ($location) {
$router.config([
{ path: '/user', component: 'userCmp' }
]);
compile('<div ng-outlet></div>');
$router.navigateByUrl('/user?x=y');
$rootScope.$digest();
expect($location.path()).toBe('/user');
expect($location.search()).toEqual({ x: 'y'});
}));
it('should change location to the canonical route', inject(function ($location) { it('should change location to the canonical route', inject(function ($location) {
compile('<div ng-outlet></div>'); compile('<div ng-outlet></div>');
@ -245,6 +268,19 @@ describe('navigation', function () {
})); }));
it('should navigate when the location query changes', inject(function ($location) {
$router.config([
{ path: '/get/params', component: 'getParams' }
]);
compile('<div ng-outlet></div>');
$location.url('/get/params?x=y');
$rootScope.$digest();
expect(elt.text()).toBe('y');
}));
it('should expose a "navigating" property on $router', inject(function ($q) { it('should expose a "navigating" property on $router', inject(function ($q) {
var defer; var defer;
registerDirective('pendingActivate', { registerDirective('pendingActivate', {