From 6c0cf17404e8e6de0c398fff8e71497f39090408 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 31 Jan 2011 23:26:10 -0800 Subject: add redirection support to $route Closes #217 --- test/servicesSpec.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f7151dbc..ddad5d89 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -460,6 +460,49 @@ describe("service", function(){ expect($route.current.scope.notFoundProp).toBeUndefined(); expect(onChangeSpy).toHaveBeenCalled(); }); + + it('should support redirection via redirectTo property by updating $location', function() { + var scope = angular.scope(), + $location = scope.$service('$location'), + $browser = scope.$service('$browser'), + $route = scope.$service('$route'), + onChangeSpy = jasmine.createSpy('onChange'); + + $route.when('', {redirectTo: '/foo'}); + $route.when('/foo', {template: 'foo.html'}); + $route.when('/bar', {template: 'bar.html'}); + $route.when('/baz', {redirectTo: '/bar'}); + $route.otherwise({template: '404.html'}); + $route.onChange(onChangeSpy); + expect($route.current).toBeNull(); + expect(onChangeSpy).not.toHaveBeenCalled(); + + scope.$eval(); //triggers initial route change - match the redirect route + $browser.poll(); //triger route change - match the route we redirected to + + expect($location.hash).toBe('/foo'); + expect($route.current.template).toBe('foo.html'); + expect(onChangeSpy.callCount).toBe(1); + + onChangeSpy.reset(); + $location.updateHash(''); + scope.$eval(); //match the redirect route + update $browser + $browser.poll(); //match the route we redirected to + + + expect($location.hash).toBe('/foo'); + expect($route.current.template).toBe('foo.html'); + expect(onChangeSpy.callCount).toBe(1); + + onChangeSpy.reset(); + $location.updateHash('/baz'); + scope.$eval(); //match the redirect route + update $browser + $browser.poll(); //match the route we redirected to + + expect($location.hash).toBe('/bar'); + expect($route.current.template).toBe('bar.html'); + expect(onChangeSpy.callCount).toBe(1); + }); }); -- cgit v1.2.3