feat(router): change location when navigating

This commit is contained in:
vsavkin
2016-04-28 08:01:27 -07:00
committed by Victor Savkin
parent de56dd5f30
commit 560cc14d97
11 changed files with 589 additions and 11 deletions
@@ -28,8 +28,10 @@ import {
Routes,
RouterUrlSerializer,
DefaultRouterUrlSerializer,
OnActivate
OnActivate,
Location
} from 'angular2/alt_router';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
export function main() {
@@ -37,14 +39,28 @@ export function main() {
beforeEachProviders(() => [
provide(RouterUrlSerializer, {useClass: DefaultRouterUrlSerializer}),
RouterOutletMap,
provide(Location, {useClass: SpyLocation}),
provide(Router,
{
useFactory: (resolver, urlParser, outletMap) =>
new Router(RootCmp, resolver, urlParser, outletMap),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap]
useFactory: (resolver, urlParser, outletMap, location) =>
new Router(RootCmp, resolver, urlParser, outletMap, location),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
})
]);
it('should update location when navigating',
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
let fixture = tcb.createFakeAsync(RootCmp);
router.navigateByUrl('/team/22/user/victor');
advance(fixture);
expect(location.path()).toEqual('/team/22/user/victor');
router.navigateByUrl('/team/33/simple');
advance(fixture);
expect(location.path()).toEqual('/team/33/simple');
})));
it('should support nested routes',
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
let fixture = tcb.createFakeAsync(RootCmp);
@@ -19,11 +19,9 @@ import {DefaultRouterUrlSerializer} from 'angular2/src/alt_router/router_url_ser
import {UrlSegment} from 'angular2/src/alt_router/segments';
export function main() {
describe('url parsing', () => {
describe('url serializer', () => {
let url = new DefaultRouterUrlSerializer();
it('should throw on an empty urls', () => { expect(() => url.parse("")).toThrow(); });
it('should parse the root url', () => {
let tree = url.parse("/");
expectSegment(tree.root, "");