2016-06-01 17:32:15 -04:00
|
|
|
import {Component, Injector} from '@angular/core';
|
2016-05-24 16:23:27 -04:00
|
|
|
import {
|
|
|
|
describe,
|
2016-06-02 14:30:38 -04:00
|
|
|
ddescribe,
|
2016-06-02 17:44:57 -04:00
|
|
|
xdescribe,
|
2016-05-24 16:23:27 -04:00
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
beforeEachProviders,
|
|
|
|
inject,
|
|
|
|
fakeAsync,
|
|
|
|
tick
|
|
|
|
} from '@angular/core/testing';
|
|
|
|
|
|
|
|
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
|
|
|
import { ComponentResolver } from '@angular/core';
|
2016-06-15 19:45:19 -04:00
|
|
|
import { Location } from '@angular/common';
|
2016-05-24 16:23:27 -04:00
|
|
|
import { SpyLocation } from '@angular/common/testing';
|
2016-06-02 17:44:57 -04:00
|
|
|
import { UrlSerializer, DefaultUrlSerializer, RouterOutletMap, Router, ActivatedRoute, ROUTER_DIRECTIVES, Params,
|
2016-06-10 11:57:03 -04:00
|
|
|
RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RoutesRecognized, RouterConfig } from '../src/index';
|
2016-05-24 16:23:27 -04:00
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
import 'rxjs/add/operator/map';
|
2016-06-06 13:55:12 -04:00
|
|
|
import {of} from 'rxjs/observable/of';
|
2016-05-24 16:23:27 -04:00
|
|
|
|
2016-05-20 16:55:17 -04:00
|
|
|
describe("Integration", () => {
|
2016-06-02 19:34:04 -04:00
|
|
|
|
|
|
|
beforeEachProviders(() => {
|
|
|
|
let config: RouterConfig = [
|
2016-06-14 17:55:59 -04:00
|
|
|
{ path: '', component: BlankCmp },
|
2016-06-02 19:34:04 -04:00
|
|
|
{ path: 'simple', component: SimpleCmp }
|
|
|
|
];
|
|
|
|
|
|
|
|
return [
|
|
|
|
RouterOutletMap,
|
|
|
|
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
|
|
|
{provide: Location, useClass: SpyLocation},
|
|
|
|
{
|
|
|
|
provide: Router,
|
2016-06-15 19:45:19 -04:00
|
|
|
useFactory: (resolver:ComponentResolver, urlSerializer:UrlSerializer, outletMap:RouterOutletMap, location:Location, injector:Injector) => {
|
2016-06-06 18:44:12 -04:00
|
|
|
const r = new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector, config);
|
|
|
|
r.initialNavigation();
|
|
|
|
return r;
|
|
|
|
},
|
2016-06-02 19:34:04 -04:00
|
|
|
deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector]
|
|
|
|
},
|
2016-06-15 19:45:19 -04:00
|
|
|
{provide: ActivatedRoute, useFactory: (r:Router) => r.routerState.root, deps: [Router]},
|
2016-06-02 19:34:04 -04:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should navigate with a provided config',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-02 19:34:04 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.navigateByUrl('/simple');
|
|
|
|
advance(fixture);
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-06-02 19:34:04 -04:00
|
|
|
expect(location.path()).toEqual('/simple');
|
|
|
|
})));
|
2016-06-01 17:32:15 -04:00
|
|
|
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
it('should update location when navigating',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp }
|
2016-05-24 16:23:27 -04:00
|
|
|
]);
|
2016-06-02 19:34:04 -04:00
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/33');
|
|
|
|
})));
|
|
|
|
|
2016-06-10 11:57:03 -04:00
|
|
|
it('should navigate back and forward',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'simple', component: SimpleCmp },
|
|
|
|
{ path: 'user/:name', component: UserCmp }
|
2016-05-24 16:23:27 -04:00
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33/simple');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33/simple');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
location.back();
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33/simple');
|
|
|
|
|
|
|
|
location.forward();
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/user/victor');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it('should navigate when locations changes',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'user/:name', component: UserCmp }
|
2016-05-24 16:23:27 -04:00
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-15 19:45:19 -04:00
|
|
|
(<any>location).simulateHashChange("/team/22/user/fedor");
|
2016-05-24 16:23:27 -04:00
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user fedor, right: }');
|
|
|
|
})));
|
|
|
|
|
2016-06-14 19:22:36 -04:00
|
|
|
it('should update the location when the matched route does not change',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 19:22:36 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: '**', component: SimpleCmp }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/one/two');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/one/two');
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('simple');
|
|
|
|
|
|
|
|
router.navigateByUrl('/three/four');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/three/four');
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('simple');
|
|
|
|
})));
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
it('should support secondary routes',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'user/:name', component: UserCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp, outlet: 'right' }
|
2016-05-24 16:23:27 -04:00
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
router.navigateByUrl('/team/22/(user/victor//right:simple)');
|
2016-05-24 16:23:27 -04:00
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement)
|
|
|
|
.toHaveText('team 22 { user victor, right: simple }');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it('should deactivate outlets',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'user/:name', component: UserCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp, outlet: 'right' }
|
2016-05-24 16:23:27 -04:00
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
router.navigateByUrl('/team/22/(user/victor//right:simple)');
|
2016-05-24 16:23:27 -04:00
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user victor, right: }');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it('should deactivate nested outlets',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'user/:name', component: UserCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp, outlet: 'right' }
|
2016-06-14 17:55:59 -04:00
|
|
|
] },
|
|
|
|
{ path: '', component: BlankCmp}
|
2016-05-24 16:23:27 -04:00
|
|
|
]);
|
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
router.navigateByUrl('/team/22/(user/victor//right:simple)');
|
2016-05-24 16:23:27 -04:00
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.navigateByUrl('/');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('');
|
|
|
|
})));
|
2016-05-24 17:33:34 -04:00
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
it('should set query params and fragment',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'query', component: QueryParamsAndFragmentCmp }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/query?name=1#fragment1');
|
|
|
|
advance(fixture);
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('query: 1 fragment: fragment1');
|
|
|
|
|
|
|
|
router.navigateByUrl('/query?name=2#fragment2');
|
|
|
|
advance(fixture);
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('query: 2 fragment: fragment2');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it('should push params only when they change',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'user/:name', component: UserCmp }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
const team = fixture.debugElement.children[1].componentInstance;
|
|
|
|
const user = fixture.debugElement.children[1].children[1].componentInstance;
|
|
|
|
|
|
|
|
expect(team.recordedParams).toEqual([{id: '22'}]);
|
|
|
|
expect(user.recordedParams).toEqual([{name: 'victor'}]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/fedor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(team.recordedParams).toEqual([{id: '22'}]);
|
|
|
|
expect(user.recordedParams).toEqual([{name: 'victor'}, {name: 'fedor'}]);
|
|
|
|
})));
|
|
|
|
|
2016-06-02 14:30:38 -04:00
|
|
|
it('should work when navigating to /',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-02 14:30:38 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ index: true, component: SimpleCmp },
|
|
|
|
{ path: '/user/:name', component: UserCmp }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('user victor');
|
|
|
|
|
|
|
|
router.navigateByUrl('/');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('simple');
|
|
|
|
})));
|
|
|
|
|
2016-06-03 17:07:01 -04:00
|
|
|
it("should cancel in-flight navigations",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-03 17:07:01 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: '/user/:name', component: UserCmp }
|
|
|
|
]);
|
|
|
|
|
2016-06-15 19:45:19 -04:00
|
|
|
const recordedEvents:any = [];
|
2016-06-03 17:25:18 -04:00
|
|
|
router.events.forEach(e => recordedEvents.push(e));
|
|
|
|
|
2016-06-03 17:07:01 -04:00
|
|
|
router.navigateByUrl('/user/init');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
const user = fixture.debugElement.children[1].componentInstance;
|
|
|
|
|
2016-06-15 19:45:19 -04:00
|
|
|
let r1:any, r2:any;
|
2016-06-03 17:07:01 -04:00
|
|
|
router.navigateByUrl('/user/victor').then(_ => r1 = _);
|
|
|
|
router.navigateByUrl('/user/fedor').then(_ => r2 = _);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(r1).toEqual(false); // returns false because it was canceled
|
|
|
|
expect(r2).toEqual(true); // returns true because it was successful
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('user fedor');
|
|
|
|
expect(user.recordedParams).toEqual([{name: 'init'}, {name: 'fedor'}]);
|
2016-06-03 17:25:18 -04:00
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
expectEvents(recordedEvents, [
|
2016-06-03 17:25:18 -04:00
|
|
|
[NavigationStart, '/user/init'],
|
2016-06-09 17:31:49 -04:00
|
|
|
[RoutesRecognized, '/user/init'],
|
2016-06-03 17:25:18 -04:00
|
|
|
[NavigationEnd, '/user/init'],
|
|
|
|
|
|
|
|
[NavigationStart, '/user/victor'],
|
|
|
|
[NavigationStart, '/user/fedor'],
|
|
|
|
|
|
|
|
[NavigationCancel, '/user/victor'],
|
2016-06-09 17:31:49 -04:00
|
|
|
[RoutesRecognized, '/user/fedor'],
|
2016-06-03 17:25:18 -04:00
|
|
|
[NavigationEnd, '/user/fedor']
|
|
|
|
]);
|
2016-06-03 17:07:01 -04:00
|
|
|
})));
|
|
|
|
|
|
|
|
it("should handle failed navigations gracefully",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-03 17:07:01 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: '/user/:name', component: UserCmp }
|
|
|
|
]);
|
|
|
|
|
2016-06-15 19:45:19 -04:00
|
|
|
const recordedEvents:any = [];
|
2016-06-03 17:25:18 -04:00
|
|
|
router.events.forEach(e => recordedEvents.push(e));
|
|
|
|
|
2016-06-15 19:45:19 -04:00
|
|
|
let e:any;
|
2016-06-03 17:07:01 -04:00
|
|
|
router.navigateByUrl('/invalid').catch(_ => e = _);
|
|
|
|
advance(fixture);
|
|
|
|
expect(e.message).toContain("Cannot match any routes");
|
|
|
|
|
|
|
|
router.navigateByUrl('/user/fedor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('user fedor');
|
2016-06-09 17:31:49 -04:00
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
expectEvents(recordedEvents, [
|
2016-06-03 17:25:18 -04:00
|
|
|
[NavigationStart, '/invalid'],
|
|
|
|
[NavigationError, '/invalid'],
|
|
|
|
|
|
|
|
[NavigationStart, '/user/fedor'],
|
2016-06-09 17:31:49 -04:00
|
|
|
[RoutesRecognized, '/user/fedor'],
|
2016-06-03 17:25:18 -04:00
|
|
|
[NavigationEnd, '/user/fedor']
|
|
|
|
]);
|
2016-06-03 17:07:01 -04:00
|
|
|
})));
|
2016-06-10 11:57:03 -04:00
|
|
|
|
|
|
|
it('should replace state when path is equal to current path',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-10 11:57:03 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'simple', component: SimpleCmp },
|
|
|
|
{ path: 'user/:name', component: UserCmp }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33/simple');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
location.back();
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33/simple');
|
|
|
|
})));
|
2016-06-06 17:05:57 -04:00
|
|
|
|
2016-05-24 17:33:34 -04:00
|
|
|
describe("router links", () => {
|
|
|
|
it("should support string router links",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-24 17:33:34 -04:00
|
|
|
router.resetConfig([
|
2016-05-26 19:51:56 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: StringLinkCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { link, right: }');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.getAttribute("href")).toEqual("/team/33/simple");
|
|
|
|
native.click();
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 33 { simple, right: }');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it("should support absolute router links",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-26 19:51:56 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: AbsoluteLinkCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp }
|
2016-05-24 17:33:34 -04:00
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { link, right: }');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.getAttribute("href")).toEqual("/team/33/simple");
|
|
|
|
native.click();
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('team 33 { simple, right: }');
|
|
|
|
})));
|
2016-05-26 19:51:56 -04:00
|
|
|
|
|
|
|
it("should support relative router links",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-05-26 19:51:56 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: RelativeLinkCmp },
|
|
|
|
{ path: 'simple', component: SimpleCmp }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
expect(fixture.debugElement.nativeElement)
|
|
|
|
.toHaveText('team 22 { link, right: }');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.getAttribute("href")).toEqual("/team/22/simple");
|
|
|
|
native.click();
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement)
|
|
|
|
.toHaveText('team 22 { simple, right: }');
|
|
|
|
})));
|
|
|
|
|
|
|
|
it("should support top-level link",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
2016-05-26 19:51:56 -04:00
|
|
|
let fixture = tcb.createFakeAsync(AbsoluteLinkCmp);
|
|
|
|
advance(fixture);
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-05-26 19:51:56 -04:00
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('link');
|
|
|
|
})));
|
2016-06-06 18:44:12 -04:00
|
|
|
|
|
|
|
it("should support query params and fragments",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, Location, TestComponentBuilder], (router:Router, location:Location, tcb:TestComponentBuilder) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-06 18:44:12 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: LinkWithQueryParamsAndFragment },
|
|
|
|
{ path: 'simple', component: SimpleCmp }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.getAttribute("href")).toEqual("/team/22/simple?q=1#f");
|
|
|
|
native.click();
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(fixture.debugElement.nativeElement)
|
|
|
|
.toHaveText('team 22 { simple, right: }');
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/22/simple?q=1#f');
|
|
|
|
})));
|
2016-05-24 17:33:34 -04:00
|
|
|
});
|
2016-06-01 17:32:15 -04:00
|
|
|
|
2016-06-08 19:14:26 -04:00
|
|
|
describe("redirects", () => {
|
2016-06-15 19:45:19 -04:00
|
|
|
it("should work", fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-08 19:14:26 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: '/old/team/:id', redirectTo: 'team/:id' },
|
|
|
|
{ path: '/team/:id', component: TeamCmp }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('old/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
describe("guards", () => {
|
|
|
|
describe("CanActivate", () => {
|
|
|
|
describe("should not activate a route when CanActivate returns false", () => {
|
|
|
|
beforeEachProviders(() => [
|
2016-06-15 19:45:19 -04:00
|
|
|
{provide: 'alwaysFalse', useValue: (a:any, b:any) => false}
|
2016-06-01 17:32:15 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, canActivate: ["alwaysFalse"] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
expect(location.path()).toEqual('/');
|
2016-06-01 17:32:15 -04:00
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("should activate a route when CanActivate returns true", () => {
|
|
|
|
beforeEachProviders(() => [
|
2016-06-02 18:29:15 -04:00
|
|
|
{provide: 'alwaysTrue', useValue: (a:ActivatedRouteSnapshot, s:RouterStateSnapshot) => true}
|
2016-06-01 17:32:15 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-01 17:32:15 -04:00
|
|
|
router.resetConfig([
|
2016-06-02 18:29:15 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, canActivate: ["alwaysTrue"] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("should work when given a class", () => {
|
|
|
|
class AlwaysTrue implements CanActivate {
|
|
|
|
canActivate(route:ActivatedRouteSnapshot, state:RouterStateSnapshot):boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEachProviders(() => [AlwaysTrue]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-02 18:29:15 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, canActivate: [AlwaysTrue] }
|
2016-06-01 17:32:15 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
})));
|
|
|
|
});
|
2016-06-06 13:55:12 -04:00
|
|
|
|
|
|
|
describe("should work when returns an observable", () => {
|
|
|
|
beforeEachProviders(() => [
|
|
|
|
{provide: 'CanActivate', useValue: (a:ActivatedRouteSnapshot, b:RouterStateSnapshot) => {
|
|
|
|
return of(false);
|
|
|
|
}}
|
|
|
|
]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-06 13:55:12 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, canActivate: ['CanActivate'] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
2016-06-14 17:55:59 -04:00
|
|
|
expect(location.path()).toEqual('/');
|
2016-06-06 13:55:12 -04:00
|
|
|
})));
|
|
|
|
});
|
2016-06-01 17:32:15 -04:00
|
|
|
});
|
2016-06-02 17:44:57 -04:00
|
|
|
|
|
|
|
describe("CanDeactivate", () => {
|
|
|
|
describe("should not deactivate a route when CanDeactivate returns false", () => {
|
|
|
|
beforeEachProviders(() => [
|
2016-06-15 18:45:42 -04:00
|
|
|
{provide: 'CanDeactivateTeam', useValue: (c:TeamCmp, a:ActivatedRouteSnapshot, b:RouterStateSnapshot) => {
|
2016-06-02 17:44:57 -04:00
|
|
|
return c.route.snapshot.params['id'] === "22";
|
2016-06-15 18:45:42 -04:00
|
|
|
}},
|
|
|
|
{provide: 'CanDeactivateUser', useValue: (c:UserCmp, a:ActivatedRouteSnapshot, b:RouterStateSnapshot) => {
|
|
|
|
return a.params['name'] === 'victor';
|
2016-06-02 17:44:57 -04:00
|
|
|
}}
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-02 17:44:57 -04:00
|
|
|
router.resetConfig([
|
2016-06-15 18:45:42 -04:00
|
|
|
{ path: 'team/:id', component: TeamCmp, canDeactivate: ["CanDeactivateTeam"] }
|
2016-06-02 17:44:57 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/33');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/44');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
expect(location.path()).toEqual('/team/33');
|
|
|
|
})));
|
2016-06-15 18:45:42 -04:00
|
|
|
|
|
|
|
it('works with a nested route',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-15 18:45:42 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{path: '/', terminal: true, component: SimpleCmp},
|
|
|
|
{path: 'user/:name', component: UserCmp, canDeactivate: ["CanDeactivateUser"] }
|
|
|
|
]}
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/user/victor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
// this works because we can deactivate victor
|
|
|
|
router.navigateByUrl('/team/33');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33/user/fedor');
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
// this doesn't work cause we cannot deactivate fedor
|
|
|
|
router.navigateByUrl('/team/44');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33/user/fedor');
|
|
|
|
})));
|
2016-06-02 17:44:57 -04:00
|
|
|
});
|
2016-06-02 18:29:15 -04:00
|
|
|
|
|
|
|
describe("should work when given a class", () => {
|
|
|
|
class AlwaysTrue implements CanDeactivate<TeamCmp> {
|
|
|
|
canDeactivate(component: TeamCmp, route:ActivatedRouteSnapshot, state:RouterStateSnapshot):boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEachProviders(() => [AlwaysTrue]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-02 18:29:15 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, canDeactivate: [AlwaysTrue] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
2016-06-06 13:55:12 -04:00
|
|
|
|
|
|
|
router.navigateByUrl('/team/33');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/33');
|
2016-06-02 18:29:15 -04:00
|
|
|
})));
|
|
|
|
});
|
2016-06-02 17:44:57 -04:00
|
|
|
});
|
2016-06-06 13:55:12 -04:00
|
|
|
|
|
|
|
describe("should work when returns an observable", () => {
|
|
|
|
beforeEachProviders(() => [
|
|
|
|
{provide: 'CanDeactivate', useValue: (c:TeamCmp, a:ActivatedRouteSnapshot, b:RouterStateSnapshot) => {
|
|
|
|
return of(false);
|
|
|
|
}}
|
|
|
|
]);
|
|
|
|
|
|
|
|
it('works',
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-14 17:55:59 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
2016-06-06 13:55:12 -04:00
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, canDeactivate: ['CanDeactivate'] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/33');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22');
|
|
|
|
})));
|
|
|
|
});
|
2016-06-01 17:32:15 -04:00
|
|
|
});
|
2016-06-15 12:01:05 -04:00
|
|
|
|
|
|
|
describe("routerActiveLink", () => {
|
|
|
|
it("should set the class when the link is active (exact = true)",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-15 12:01:05 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: DummyLinkCmp, children: [
|
|
|
|
{path: 'simple', component: SimpleCmp},
|
|
|
|
{path: '', component: BlankCmp}
|
|
|
|
] }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.className).toEqual("active");
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link/simple');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link/simple');
|
|
|
|
expect(native.className).toEqual("");
|
|
|
|
})));
|
|
|
|
|
|
|
|
it("should set the class on a parent element when the link is active (exact = true)",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-15 12:01:05 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: DummyLinkWithParentCmp, children: [
|
|
|
|
{path: 'simple', component: SimpleCmp},
|
|
|
|
{path: '', component: BlankCmp}
|
|
|
|
] }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("link-parent");
|
|
|
|
expect(native.className).toEqual("active");
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link/simple');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link/simple');
|
|
|
|
expect(native.className).toEqual("");
|
|
|
|
})));
|
|
|
|
|
|
|
|
it("should set the class when the link is active (exact = false)",
|
2016-06-15 19:45:19 -04:00
|
|
|
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
2016-06-15 12:01:05 -04:00
|
|
|
const fixture = tcb.createFakeAsync(RootCmp);
|
|
|
|
advance(fixture);
|
|
|
|
|
|
|
|
router.resetConfig([
|
|
|
|
{ path: 'team/:id', component: TeamCmp, children: [
|
|
|
|
{ path: 'link', component: DummyLinkCmp, children: [
|
|
|
|
{path: 'simple', component: SimpleCmp},
|
|
|
|
{path: '', component: BlankCmp}
|
|
|
|
] }
|
|
|
|
] }
|
|
|
|
]);
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link;exact=false');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link;exact=false');
|
|
|
|
|
|
|
|
const native = fixture.debugElement.nativeElement.querySelector("a");
|
|
|
|
expect(native.className).toEqual("active");
|
|
|
|
|
|
|
|
router.navigateByUrl('/team/22/link/simple');
|
|
|
|
advance(fixture);
|
|
|
|
expect(location.path()).toEqual('/team/22/link/simple');
|
|
|
|
expect(native.className).toEqual("active");
|
|
|
|
})));
|
|
|
|
|
|
|
|
});
|
2016-05-20 16:22:57 -04:00
|
|
|
});
|
2016-05-24 16:23:27 -04:00
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
function expectEvents(events:Event[], pairs: any[]) {
|
2016-06-03 17:25:18 -04:00
|
|
|
for (let i = 0; i < events.length; ++i) {
|
|
|
|
expect((<any>events[i].constructor).name).toBe(pairs[i][0].name);
|
2016-06-14 17:55:59 -04:00
|
|
|
expect((<any>events[i]).url).toBe(pairs[i][1]);
|
2016-06-03 17:25:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-24 17:33:34 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
|
|
|
template: `<a routerLink="/team/33/simple">link</a>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class StringLinkCmp {}
|
2016-05-24 16:23:27 -04:00
|
|
|
|
2016-05-26 19:51:56 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
2016-06-14 17:55:59 -04:00
|
|
|
template: `<router-outlet></router-outlet><a [routerLink]="['/team/33/simple']">link</a>`,
|
2016-05-26 19:51:56 -04:00
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class AbsoluteLinkCmp {}
|
|
|
|
|
2016-06-15 12:01:05 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
|
|
|
template: `<router-outlet></router-outlet><a routerLinkActive="active" [routerLinkActiveOptions]="{exact: exact}" [routerLink]="['./']">link</a>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class DummyLinkCmp {
|
|
|
|
private exact: boolean;
|
|
|
|
constructor(route: ActivatedRoute) {
|
|
|
|
// convert 'false' into false
|
|
|
|
this.exact = (<any>route.snapshot.params).exact !== 'false';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
|
|
|
template: `<router-outlet></router-outlet><link-parent routerLinkActive="active"><a [routerLink]="['./']">link</a></link-parent>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class DummyLinkWithParentCmp {
|
|
|
|
}
|
|
|
|
|
2016-05-26 19:51:56 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
|
|
|
template: `<a [routerLink]="['../simple']">link</a>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class RelativeLinkCmp {}
|
|
|
|
|
2016-06-06 18:44:12 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'link-cmp',
|
|
|
|
template: `<a [routerLink]="['../simple']" [queryParams]="{q: '1'}" fragment="f">link</a>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class LinkWithQueryParamsAndFragment {}
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'simple-cmp',
|
|
|
|
template: `simple`,
|
2016-05-24 17:33:34 -04:00
|
|
|
directives: ROUTER_DIRECTIVES
|
2016-05-24 16:23:27 -04:00
|
|
|
})
|
2016-05-24 17:33:34 -04:00
|
|
|
class SimpleCmp {
|
|
|
|
}
|
2016-05-24 16:23:27 -04:00
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'blank-cmp',
|
|
|
|
template: ``,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
class BlankCmp {
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'team-cmp',
|
|
|
|
template: `team {{id | async}} { <router-outlet></router-outlet>, right: <router-outlet name="right"></router-outlet> }`,
|
2016-05-24 17:33:34 -04:00
|
|
|
directives: ROUTER_DIRECTIVES
|
2016-05-24 16:23:27 -04:00
|
|
|
})
|
|
|
|
class TeamCmp {
|
|
|
|
id: Observable<string>;
|
2016-06-01 17:32:15 -04:00
|
|
|
recordedParams: Params[] = [];
|
2016-05-24 16:23:27 -04:00
|
|
|
|
2016-06-02 17:44:57 -04:00
|
|
|
constructor(public route: ActivatedRoute) {
|
2016-05-24 16:23:27 -04:00
|
|
|
this.id = route.params.map(p => p['id']);
|
2016-06-01 17:32:15 -04:00
|
|
|
route.params.forEach(_ => this.recordedParams.push(_));
|
2016-05-24 16:23:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'user-cmp',
|
|
|
|
template: `user {{name | async}}`,
|
|
|
|
directives: [ROUTER_DIRECTIVES]
|
|
|
|
})
|
|
|
|
class UserCmp {
|
|
|
|
name: Observable<string>;
|
2016-06-01 17:32:15 -04:00
|
|
|
recordedParams: Params[] = [];
|
|
|
|
|
2016-05-24 16:23:27 -04:00
|
|
|
constructor(route: ActivatedRoute) {
|
|
|
|
this.name = route.params.map(p => p['name']);
|
2016-06-01 17:32:15 -04:00
|
|
|
route.params.forEach(_ => this.recordedParams.push(_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'query-cmp',
|
|
|
|
template: `query: {{name | async}} fragment: {{fragment | async}}`,
|
|
|
|
directives: [ROUTER_DIRECTIVES]
|
|
|
|
})
|
|
|
|
class QueryParamsAndFragmentCmp {
|
|
|
|
name: Observable<string>;
|
|
|
|
fragment: Observable<string>;
|
|
|
|
|
|
|
|
constructor(router: Router) {
|
|
|
|
this.name = router.routerState.queryParams.map(p => p['name']);
|
|
|
|
this.fragment = router.routerState.fragment;
|
2016-05-24 16:23:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'root-cmp',
|
|
|
|
template: `<router-outlet></router-outlet>`,
|
|
|
|
directives: [ROUTER_DIRECTIVES]
|
|
|
|
})
|
|
|
|
class RootCmp {}
|
|
|
|
|
|
|
|
function advance(fixture: ComponentFixture<any>): void {
|
|
|
|
tick();
|
|
|
|
fixture.detectChanges();
|
|
|
|
}
|