revert(format): Revert "chore(format): update to latest formatter"

This reverts commit 03627aa84d.
This commit is contained in:
Alex Rickabaugh
2016-04-12 09:40:37 -07:00
parent 03627aa84d
commit 60727c4d2b
527 changed files with 19247 additions and 13970 deletions

View File

@ -1,11 +1,34 @@
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, dispatchEvent, expect, iit, inject, beforeEachProviders, it, xit, TestComponentBuilder} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
beforeEach,
ddescribe,
xdescribe,
describe,
dispatchEvent,
expect,
iit,
inject,
beforeEachProviders,
it,
xit,
TestComponentBuilder
} from 'angular2/testing_internal';
import {SpyRouter, SpyLocation} from '../spies';
import {provide, Component} from 'angular2/core';
import {By} from 'angular2/platform/common_dom';
import {Location, Router, RouteRegistry, RouterLink, RouterOutlet, Route, RouteParams, ComponentInstruction} from 'angular2/router';
import {
Location,
Router,
RouteRegistry,
RouterLink,
RouterOutlet,
Route,
RouteParams,
ComponentInstruction
} from 'angular2/router';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {ResolvedInstruction} from 'angular2/src/router/instruction';
@ -17,64 +40,69 @@ export function main() {
describe('routerLink directive', function() {
var tcb: TestComponentBuilder;
beforeEachProviders(() => [provide(Location, {useValue: makeDummyLocation()}), provide(Router, {
useValue: makeDummyRouter()
})]);
beforeEachProviders(() => [
provide(Location, {useValue: makeDummyLocation()}),
provide(Router, {useValue: makeDummyRouter()})
]);
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));
it('should update a[href] attribute', inject([AsyncTestCompleter], (async) => {
tcb.createAsync(TestComponent).then((testComponent) => {
testComponent.detectChanges();
let anchorElement =
testComponent.debugElement.query(By.css('a.detail-view')).nativeElement;
expect(DOM.getAttribute(anchorElement, 'href')).toEqual('detail');
async.done();
});
tcb.createAsync(TestComponent)
.then((testComponent) => {
testComponent.detectChanges();
let anchorElement =
testComponent.debugElement.query(By.css('a.detail-view')).nativeElement;
expect(DOM.getAttribute(anchorElement, 'href')).toEqual('detail');
async.done();
});
}));
it('should call router.navigate when a link is clicked',
inject([AsyncTestCompleter, Router], (async, router) => {
tcb.createAsync(TestComponent).then((testComponent) => {
testComponent.detectChanges();
// TODO: shouldn't this be just 'click' rather than '^click'?
testComponent.debugElement.query(By.css('a.detail-view'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
tcb.createAsync(TestComponent)
.then((testComponent) => {
testComponent.detectChanges();
// TODO: shouldn't this be just 'click' rather than '^click'?
testComponent.debugElement.query(By.css('a.detail-view'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
}));
it('should call router.navigate when a link is clicked if target is _self',
inject([AsyncTestCompleter, Router], (async, router) => {
tcb.createAsync(TestComponent).then((testComponent) => {
testComponent.detectChanges();
testComponent.debugElement.query(By.css('a.detail-view-self'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
tcb.createAsync(TestComponent)
.then((testComponent) => {
testComponent.detectChanges();
testComponent.debugElement.query(By.css('a.detail-view-self'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
}));
it('should NOT call router.navigate when a link is clicked if target is set to other than _self',
inject([AsyncTestCompleter, Router], (async, router) => {
tcb.createAsync(TestComponent).then((testComponent) => {
testComponent.detectChanges();
testComponent.debugElement.query(By.css('a.detail-view-blank'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).not.toHaveBeenCalled();
async.done();
});
tcb.createAsync(TestComponent)
.then((testComponent) => {
testComponent.detectChanges();
testComponent.debugElement.query(By.css('a.detail-view-blank'))
.triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).not.toHaveBeenCalled();
async.done();
});
}));
});
}
@Component({selector: 'user-cmp', template: 'hello {{user}}'})
@Component({selector: 'user-cmp', template: "hello {{user}}"})
class UserCmp {
user: string;
constructor(params: RouteParams) { this.user = params.get('name'); }

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, describe, proxy, it, iit, ddescribe, expect, inject, beforeEach, beforeEachBindings, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
proxy,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
beforeEachBindings,
SpyObject
} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/facade/lang';
@ -14,43 +26,43 @@ export function main() {
}
describe('parseRouterLinkExpression', () => {
it('should parse simple routes', inject([Parser], (p) => {
it("should parse simple routes", inject([Parser], (p) => {
check(p, `User`, `["User"]`);
check(p, `/User`, `["/User"]`);
check(p, `./User`, `["./User"]`);
check(p, `../../User`, `["../../User"]`);
}));
it('should trim the string', inject([Parser], (p) => { check(p, ` User `, `["User"]`); }));
it("should trim the string", inject([Parser], (p) => { check(p, ` User `, `["User"]`); }));
it('should parse parameters', inject([Parser], (p) => {
it("should parse parameters", inject([Parser], (p) => {
check(p, `./User(id: value, name: 'Bob')`, `["./User", {id: value, name: "Bob"}]`);
}));
it('should parse nested routes', inject([Parser], (p) => {
it("should parse nested routes", inject([Parser], (p) => {
check(p, `User/Modal`, `["User", "Modal"]`);
check(p, `/User/Modal`, `["/User", "Modal"]`);
}));
it('should parse auxiliary routes', inject([Parser], (p) => {
it("should parse auxiliary routes", inject([Parser], (p) => {
check(p, `User[Modal]`, `["User", ["Modal"]]`);
check(p, `User[Modal1][Modal2]`, `["User", ["Modal1"], ["Modal2"]]`);
check(p, `User[Modal1[Modal2]]`, `["User", ["Modal1", ["Modal2"]]]`);
}));
it('should parse combinations', inject([Parser], (p) => {
it("should parse combinations", inject([Parser], (p) => {
check(p, `./User(id: value)/Post(title: 'blog')`, `["./User", {id: value}, "Post", {title: "blog"}]`);
check(p, `./User[Modal(param: value)]`, `["./User", ["Modal", {param: value}]]`);
}));
it('should error on empty fixed parts', inject([Parser], (p) => {
it("should error on empty fixed parts", inject([Parser], (p) => {
expect(() => parseRouterLinkExpression(p, `./(id: value, name: 'Bob')`))
.toThrowErrorWith('Invalid router link');
.toThrowErrorWith("Invalid router link");
}));
it('should error on multiple slashes', inject([Parser], (p) => {
it("should error on multiple slashes", inject([Parser], (p) => {
expect(() => parseRouterLinkExpression(p, `//User`))
.toThrowErrorWith('Invalid router link');
.toThrowErrorWith("Invalid router link");
}));
});
}

View File

@ -1,4 +1,12 @@
import {describeRouter, ddescribeRouter, describeWith, describeWithout, describeWithAndWithout, itShouldRoute, TEST_ROUTER_PROVIDERS} from './util';
import {
describeRouter,
ddescribeRouter,
describeWith,
describeWithout,
describeWithAndWithout,
itShouldRoute,
TEST_ROUTER_PROVIDERS
} from './util';
import {beforeEachProviders, describe} from 'angular2/testing_internal';
@ -17,12 +25,12 @@ export function main() {
describeWithAndWithout('params', itShouldRoute);
});
describeWith(
'sync children', () => { describeWithAndWithout('default routes', itShouldRoute); });
describeWith('sync children',
() => { describeWithAndWithout('default routes', itShouldRoute); });
describeWith('async children', () => {
describeWithAndWithout(
'params', () => { describeWithout('default routes', itShouldRoute); });
describeWithAndWithout('params',
() => { describeWithout('default routes', itShouldRoute); });
});
});
});

View File

@ -1,6 +1,17 @@
import {describeRouter, ddescribeRouter, describeWith, describeWithout, describeWithAndWithout, itShouldRoute, TEST_ROUTER_PROVIDERS} from './util';
import {
describeRouter,
ddescribeRouter,
describeWith,
describeWithout,
describeWithAndWithout,
itShouldRoute,
TEST_ROUTER_PROVIDERS
} from './util';
import {beforeEachProviders, describe,} from 'angular2/testing_internal';
import {
beforeEachProviders,
describe,
} from 'angular2/testing_internal';
import {registerSpecs} from './impl/aux_route_spec_impl';

View File

@ -1,4 +1,18 @@
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, flushMicrotasks, inject, it, xdescribe, TestComponentBuilder, xit,} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
beforeEach,
beforeEachProviders,
ddescribe,
describe,
expect,
iit,
flushMicrotasks,
inject,
it,
xdescribe,
TestComponentBuilder,
xit,
} from 'angular2/testing_internal';
import {bootstrap} from 'angular2/platform/browser';
import {Component, Directive} from 'angular2/src/core/metadata';
@ -6,10 +20,23 @@ import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {Console} from 'angular2/src/core/console';
import {provide, ViewChild, AfterViewInit} from 'angular2/core';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
import {RouteConfig, Route, Redirect, AuxRoute} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
Redirect,
AuxRoute
} from 'angular2/src/router/route_config/route_config_decorator';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
import {ROUTER_PROVIDERS, ROUTER_PRIMARY_COMPONENT, RouteParams, Router, APP_BASE_HREF, ROUTER_DIRECTIVES, LocationStrategy} from 'angular2/router';
import {
ROUTER_PROVIDERS,
ROUTER_PRIMARY_COMPONENT,
RouteParams,
Router,
APP_BASE_HREF,
ROUTER_DIRECTIVES,
LocationStrategy
} from 'angular2/router';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
import {ApplicationRef} from 'angular2/src/core/application_ref';
@ -21,10 +48,11 @@ class DummyConsole implements Console {
export function main() {
describe('router bootstrap', () => {
beforeEachProviders(
() =>
[ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(ApplicationRef, {useClass: MockApplicationRef})]);
beforeEachProviders(() => [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(ApplicationRef, {useClass: MockApplicationRef})
]);
// do not refactor out the `bootstrap` functionality. We still want to
// keep this test around so we can ensure that bootstrapping a router works
@ -33,18 +61,22 @@ export function main() {
var el = DOM.createElement('app-cmp', fakeDoc);
DOM.appendChild(fakeDoc.body, el);
bootstrap(AppCmp, [
ROUTER_PROVIDERS, provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})
]).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('outer { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('');
async.done();
});
});
bootstrap(AppCmp,
[
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}),
provide(Console, {useClass: DummyConsole})
])
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('outer { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('');
async.done();
});
});
}));
describe('broken app', () => {
@ -68,46 +100,47 @@ export function main() {
it('should change the url without pushing a new history state for back navigations',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
var position = 0;
var flipped = false;
var history = [
['/parent/child', 'root { parent { hello } }', '/super-parent/child'],
['/super-parent/child', 'root { super-parent { hello2 } }', '/parent/child'],
['/parent/child', 'root { parent { hello } }', false]
];
tcb.createAsync(HierarchyAppCmp)
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
var position = 0;
var flipped = false;
var history = [
['/parent/child', 'root { parent { hello } }', '/super-parent/child'],
['/super-parent/child', 'root { super-parent { hello2 } }', '/parent/child'],
['/parent/child', 'root { parent { hello } }', false]
];
router.subscribe((_) => {
var location = fixture.debugElement.componentInstance.location;
var element = fixture.debugElement.nativeElement;
var path = location.path();
router.subscribe((_) => {
var location = fixture.debugElement.componentInstance.location;
var element = fixture.debugElement.nativeElement;
var path = location.path();
var entry = history[position];
var entry = history[position];
expect(path).toEqual(entry[0]);
expect(element).toHaveText(entry[1]);
expect(path).toEqual(entry[0]);
expect(element).toHaveText(entry[1]);
var nextUrl = entry[2];
if (nextUrl == false) {
flipped = true;
}
var nextUrl = entry[2];
if (nextUrl == false) {
flipped = true;
}
if (flipped && position == 0) {
async.done();
return;
}
if (flipped && position == 0) {
async.done();
return;
}
position = position + (flipped ? -1 : 1);
if (flipped) {
location.back();
} else {
router.navigateByUrl(nextUrl);
}
});
position = position + (flipped ? -1 : 1);
if (flipped) {
location.back();
} else {
router.navigateByUrl(nextUrl);
}
});
router.navigateByUrl(history[0][0]);
});
router.navigateByUrl(history[0][0]);
});
}), 1000);
});
@ -118,37 +151,40 @@ export function main() {
it('should bootstrap an app with a hierarchy',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement).toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
tcb.createAsync(HierarchyAppCmp)
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
// TODO(btford): mock out level lower than LocationStrategy once that level exists
xdescribe('custom app base ref', () => {
beforeEachProviders(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
it('should bootstrap',
inject(
[AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
inject([AsyncTestCompleter, TestComponentBuilder],
(async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/my/app/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
tcb.createAsync(HierarchyAppCmp)
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/my/app/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
});
});
@ -159,21 +195,22 @@ export function main() {
it('should recognize and return querystring params with the injected RouteParams',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(QueryStringAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
fixture.detectChanges();
tcb.createAsync(QueryStringAppCmp)
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement)
.toHaveText('qParam = search-for-something');
/*
expect(applicationRef.hostComponent.location.path())
.toEqual('/qs?q=search-for-something');*/
async.done();
});
router.navigateByUrl('/qs?q=search-for-something');
fixture.detectChanges();
});
expect(fixture.debugElement.nativeElement)
.toHaveText('qParam = search-for-something');
/*
expect(applicationRef.hostComponent.location.path())
.toEqual('/qs?q=search-for-something');*/
async.done();
});
router.navigateByUrl('/qs?q=search-for-something');
fixture.detectChanges();
});
}));
});
@ -182,28 +219,29 @@ export function main() {
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp})]);
beforeEach(inject(
[TestComponentBuilder], (testComponentBuilder) => { tcb = testComponentBuilder; }));
beforeEach(inject([TestComponentBuilder],
(testComponentBuilder) => { tcb = testComponentBuilder; }));
it('should get a reference and pass data to components loaded inside of outlets',
inject([AsyncTestCompleter], (async) => {
tcb.createAsync(AppWithViewChildren).then(fixture => {
let appInstance = fixture.debugElement.componentInstance;
let router = appInstance.router;
tcb.createAsync(AppWithViewChildren)
.then(fixture => {
let appInstance = fixture.debugElement.componentInstance;
let router = appInstance.router;
router.subscribe((_) => {
fixture.detectChanges();
router.subscribe((_) => {
fixture.detectChanges();
expect(appInstance.helloCmp).toBeAnInstanceOf(HelloCmp);
expect(appInstance.helloCmp.message).toBe('Ahoy');
expect(appInstance.helloCmp).toBeAnInstanceOf(HelloCmp);
expect(appInstance.helloCmp.message).toBe('Ahoy');
async.done();
});
async.done();
});
// TODO(juliemr): This isn't necessary for the test to pass - figure
// out what's going on.
// router.navigateByUrl('/rainbow(pony)');
});
// TODO(juliemr): This isn't necessary for the test to pass - figure
// out what's going on.
// router.navigateByUrl('/rainbow(pony)');
});
}));
});
});
@ -298,7 +336,7 @@ class QueryStringAppCmp {
constructor(public router: Router, public location: LocationStrategy) {}
}
@Component({selector: 'oops-cmp', template: 'oh no'})
@Component({selector: 'oops-cmp', template: "oh no"})
class BrokenCmp {
constructor() { throw new BaseException('oops!'); }
}

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, beforeEach, beforeEachProviders, expect, iit, flushMicrotasks, inject, it, TestComponentBuilder, ComponentFixture, xit,} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
beforeEach,
beforeEachProviders,
expect,
iit,
flushMicrotasks,
inject,
it,
TestComponentBuilder,
ComponentFixture,
xit,
} from 'angular2/testing_internal';
import {By} from 'angular2/platform/common_dom';
@ -7,7 +19,21 @@ import {specs, compile, TEST_ROUTER_PROVIDERS, clickOnElement, getHref} from '..
import {Router, AsyncRoute, Route, Location} from 'angular2/router';
import {HelloCmp, helloCmpLoader, UserCmp, userCmpLoader, TeamCmp, asyncTeamLoader, ParentCmp, parentCmpLoader, asyncParentCmpLoader, asyncDefaultParentCmpLoader, ParentWithDefaultCmp, parentWithDefaultCmpLoader, asyncRouteDataCmp} from './fixture_components';
import {
HelloCmp,
helloCmpLoader,
UserCmp,
userCmpLoader,
TeamCmp,
asyncTeamLoader,
ParentCmp,
parentCmpLoader,
asyncParentCmpLoader,
asyncDefaultParentCmpLoader,
ParentWithDefaultCmp,
parentWithDefaultCmpLoader,
asyncRouteDataCmp
} from './fixture_components';
function getLinkElement(rtc: ComponentFixture) {
return rtc.debugElement.query(By.css('a')).nativeElement;
@ -28,8 +54,10 @@ function asyncRoutesWithoutChildrenWithRouteData() {
it('should inject route data into the component', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/route-data', loader: asyncRouteDataCmp, data: {isAdmin: true}})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/route-data', loader: asyncRouteDataCmp, data: {isAdmin: true}})
]))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
fixture.detectChanges();
@ -42,8 +70,8 @@ function asyncRoutesWithoutChildrenWithRouteData() {
inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/route-data-default', loader: asyncRouteDataCmp})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/route-data-default', loader: asyncRouteDataCmp})]))
.then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => {
fixture.detectChanges();
@ -68,8 +96,8 @@ function asyncRoutesWithoutChildrenWithoutParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.navigateByUrl('/test'))
.then((_) => {
fixture.detectChanges();
@ -81,8 +109,8 @@ function asyncRoutesWithoutChildrenWithoutParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.navigate(['/Hello']))
.then((_) => {
fixture.detectChanges();
@ -94,8 +122,8 @@ function asyncRoutesWithoutChildrenWithoutParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/test');
@ -107,8 +135,8 @@ function asyncRoutesWithoutChildrenWithoutParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/test', loader: helloCmpLoader, name: 'Hello'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('go to hello | ');
@ -141,8 +169,8 @@ function asyncRoutesWithoutChildrenWithParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => {
fixture.detectChanges();
@ -154,9 +182,8 @@ function asyncRoutesWithoutChildrenWithParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.navigate(['/User', {name: 'brian'}]))
.then((_) => {
fixture.detectChanges();
@ -168,8 +195,8 @@ function asyncRoutesWithoutChildrenWithParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/user/naomi');
@ -181,8 +208,8 @@ function asyncRoutesWithoutChildrenWithParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('greet naomi | ');
@ -202,8 +229,8 @@ function asyncRoutesWithoutChildrenWithParams() {
inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/user/:name', loader: userCmpLoader, name: 'User'})]))
.then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => {
fixture.detectChanges();
@ -234,8 +261,8 @@ function asyncRoutesWithSyncChildrenWithoutDefaultRoutes() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -247,8 +274,8 @@ function asyncRoutesWithSyncChildrenWithoutDefaultRoutes() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.navigate(['/Parent', 'Child']))
.then((_) => {
fixture.detectChanges();
@ -260,8 +287,8 @@ function asyncRoutesWithSyncChildrenWithoutDefaultRoutes() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Parent']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/a');
@ -273,8 +300,8 @@ function asyncRoutesWithSyncChildrenWithoutDefaultRoutes() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Parent', 'Child']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config(
[new AsyncRoute({path: '/a/...', loader: parentCmpLoader, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('nav to child | outer { }');
@ -308,8 +335,9 @@ function asyncRoutesWithSyncChildrenWithDefaultRoutes() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
fixture.detectChanges();
@ -321,8 +349,9 @@ function asyncRoutesWithSyncChildrenWithDefaultRoutes() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigate(['/Parent']))
.then((_) => {
fixture.detectChanges();
@ -334,8 +363,9 @@ function asyncRoutesWithSyncChildrenWithDefaultRoutes() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['/Parent']">link to inner</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})
]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/a');
@ -347,8 +377,9 @@ function asyncRoutesWithSyncChildrenWithDefaultRoutes() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['/Parent']">link to inner</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: parentWithDefaultCmpLoader, name: 'Parent'})
]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('link to inner | outer { }');
@ -382,8 +413,9 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithoutDefaultRoutes() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
@ -395,8 +427,9 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithoutDefaultRoutes() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigate(['/Parent', 'Child']))
.then((_) => {
rootTC.detectChanges();
@ -408,8 +441,9 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithoutDefaultRoutes() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Parent', 'Child']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})
]))
.then((_) => {
rootTC.detectChanges();
expect(getHref(getLinkElement(rootTC))).toEqual('/a');
@ -421,8 +455,9 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithoutDefaultRoutes() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Parent', 'Child']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/a/...', loader: asyncParentCmpLoader, name: 'Parent'})
]))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('nav to child | outer { }');
@ -456,8 +491,10 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithDefaultRoutes() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
rootTC.detectChanges();
@ -469,8 +506,10 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithDefaultRoutes() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})
]))
.then((_) => rtr.navigate(['/Parent']))
.then((_) => {
rootTC.detectChanges();
@ -482,8 +521,10 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithDefaultRoutes() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Parent']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})
]))
.then((_) => {
rootTC.detectChanges();
expect(getHref(getLinkElement(rootTC))).toEqual('/a');
@ -495,8 +536,10 @@ function asyncRoutesWithAsyncChildrenWithoutParamsWithDefaultRoutes() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Parent']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {rootTC = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/a/...', loader: asyncDefaultParentCmpLoader, name: 'Parent'})
]))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('nav to child | outer { }');
@ -530,8 +573,9 @@ function asyncRoutesWithAsyncChildrenWithParamsWithoutDefaultRoutes() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `{ <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})
]))
.then((_) => rtr.navigateByUrl('/team/angular/user/matias'))
.then((_) => {
fixture.detectChanges();
@ -544,8 +588,9 @@ function asyncRoutesWithAsyncChildrenWithParamsWithoutDefaultRoutes() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `{ <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})
]))
.then((_) => rtr.navigate(['/Team', {id: 'angular'}, 'User', {name: 'matias'}]))
.then((_) => {
fixture.detectChanges();
@ -560,8 +605,9 @@ function asyncRoutesWithAsyncChildrenWithParamsWithoutDefaultRoutes() {
tcb,
`<a [routerLink]="['/Team', {id: 'angular'}, 'User', {name: 'matias'}]">nav to matias</a> { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})
]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/team/angular');
@ -575,8 +621,9 @@ function asyncRoutesWithAsyncChildrenWithParamsWithoutDefaultRoutes() {
tcb,
`<a [routerLink]="['/Team', {id: 'angular'}, 'User', {name: 'matias'}]">nav to matias</a> { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})]))
.then((_) => rtr.config([
new AsyncRoute({path: '/team/:id/...', loader: asyncTeamLoader, name: 'Team'})
]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('nav to matias { }');

View File

@ -1,10 +1,30 @@
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, xdescribe, describe, el, expect, iit, inject, beforeEachProviders, it, xit} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {By} from 'angular2/platform/common_dom';
import {provide, Component, Injector, Inject} from 'angular2/core';
import {Router, ROUTER_DIRECTIVES, RouteParams, RouteData, Location} from 'angular2/router';
import {RouteConfig, Route, AuxRoute, Redirect} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
AuxRoute,
Redirect
} from 'angular2/src/router/route_config/route_config_decorator';
import {specs, compile, clickOnElement, getHref} from '../util';
import {BaseException} from 'angular2/src/facade/exceptions';
@ -218,7 +238,7 @@ class ModalCmp {
@Component({
selector: 'aux-cmp',
template: 'main {<router-outlet></router-outlet>} | ' +
'aux {<router-outlet name="modal"></router-outlet>}',
'aux {<router-outlet name="modal"></router-outlet>}',
directives: [ROUTER_DIRECTIVES],
})
@RouteConfig([

View File

@ -1,8 +1,19 @@
import {Component} from 'angular2/core';
import {AsyncRoute, Route, Redirect, RouteConfig, RouteParams, RouteData, ROUTER_DIRECTIVES} from 'angular2/router';
import {
AsyncRoute,
Route,
Redirect,
RouteConfig,
RouteParams,
RouteData,
ROUTER_DIRECTIVES
} from 'angular2/router';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {isPresent} from 'angular2/src/facade/lang';
import {DynamicComponentLoader, ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {
DynamicComponentLoader,
ComponentRef
} from 'angular2/src/core/linker/dynamic_component_loader';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
@Component({selector: 'goodbye-cmp', template: `{{farewell}}`})
@ -136,16 +147,16 @@ export class RedirectToParentCmp {
@RouteConfig([new Route({path: '/', component: HelloCmp})])
export class DynamicLoaderCmp {
private _componentRef: ComponentRef = null;
constructor(
private _dynamicComponentLoader: DynamicComponentLoader, private _elementRef: ElementRef) {}
constructor(private _dynamicComponentLoader: DynamicComponentLoader,
private _elementRef: ElementRef) {}
onSomeAction(): Promise<any> {
if (isPresent(this._componentRef)) {
this._componentRef.dispose();
this._componentRef = null;
}
return this._dynamicComponentLoader
.loadIntoLocation(DynamicallyLoadedComponent, this._elementRef, 'viewport')
return this._dynamicComponentLoader.loadIntoLocation(DynamicallyLoadedComponent,
this._elementRef, 'viewport')
.then((cmp) => { this._componentRef = cmp; });
}
}

View File

@ -1,11 +1,30 @@
import {AsyncTestCompleter, beforeEach, beforeEachProviders, expect, iit, flushMicrotasks, inject, it, TestComponentBuilder, ComponentFixture, xit,} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
beforeEach,
beforeEachProviders,
expect,
iit,
flushMicrotasks,
inject,
it,
TestComponentBuilder,
ComponentFixture,
xit,
} from 'angular2/testing_internal';
import {specs, compile, TEST_ROUTER_PROVIDERS, clickOnElement, getHref} from '../util';
import {By} from 'angular2/platform/common_dom';
import {Router, Route, Location} from 'angular2/router';
import {HelloCmp, UserCmp, TeamCmp, ParentCmp, ParentWithDefaultCmp, DynamicLoaderCmp} from './fixture_components';
import {
HelloCmp,
UserCmp,
TeamCmp,
ParentCmp,
ParentWithDefaultCmp,
DynamicLoaderCmp
} from './fixture_components';
import {PromiseWrapper} from 'angular2/src/facade/async';
@ -29,8 +48,8 @@ function syncRoutesWithoutChildrenWithoutParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) => rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) =>
rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) => rtr.navigateByUrl('/test'))
.then((_) => {
fixture.detectChanges();
@ -42,8 +61,8 @@ function syncRoutesWithoutChildrenWithoutParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) => rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) =>
rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) => rtr.navigate(['/Hello']))
.then((_) => {
fixture.detectChanges();
@ -55,8 +74,8 @@ function syncRoutesWithoutChildrenWithoutParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then(
(_) => rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) =>
rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/test');
@ -68,8 +87,8 @@ function syncRoutesWithoutChildrenWithoutParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then(
(_) => rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) =>
rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('go to hello | ');
@ -102,9 +121,8 @@ function syncRoutesWithoutChildrenWithParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => {
fixture.detectChanges();
@ -116,9 +134,8 @@ function syncRoutesWithoutChildrenWithParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.navigate(['/User', {name: 'brian'}]))
.then((_) => {
fixture.detectChanges();
@ -130,9 +147,8 @@ function syncRoutesWithoutChildrenWithParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/user/naomi');
@ -144,9 +160,8 @@ function syncRoutesWithoutChildrenWithParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('greet naomi | ');
@ -166,9 +181,8 @@ function syncRoutesWithoutChildrenWithParams() {
inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => {
fixture.detectChanges();
@ -199,9 +213,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithoutParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.config(
[new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -213,9 +226,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithoutParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.config(
[new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.navigate(['/Parent', 'Child']))
.then((_) => {
fixture.detectChanges();
@ -227,9 +239,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithoutParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['Parent', 'Child']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.config(
[new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/a/b');
@ -241,9 +252,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithoutParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['Parent', 'Child']">nav to child</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then(
(_) =>
rtr.config([new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => rtr.config(
[new Route({path: '/a/...', component: ParentCmp, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('nav to child | outer { }');
@ -277,8 +287,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `{ <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.config(
[new Route({path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.navigateByUrl('/team/angular/user/matias'))
.then((_) => {
fixture.detectChanges();
@ -291,8 +301,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `{ <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.config(
[new Route({path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.navigate(['/Team', {id: 'angular'}, 'User', {name: 'matias'}]))
.then((_) => {
fixture.detectChanges();
@ -307,8 +317,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithParams() {
tcb,
`<a [routerLink]="['/Team', {id: 'angular'}, 'User', {name: 'matias'}]">nav to matias</a> { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.config(
[new Route({path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/team/angular/user/matias');
@ -322,8 +332,8 @@ function syncRoutesWithSyncChildrenWithoutDefaultRoutesWithParams() {
tcb,
`<a [routerLink]="['/Team', {id: 'angular'}, 'User', {name: 'matias'}]">nav to matias</a> { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => rtr.config(
[new Route({path: '/team/:id/...', component: TeamCmp, name: 'Team'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('nav to matias { }');
@ -357,8 +367,9 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
it('should navigate by URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then(
(_) => rtr.config(
[new Route({path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
fixture.detectChanges();
@ -370,8 +381,9 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then(
(_) => rtr.config(
[new Route({path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then((_) => rtr.navigate(['/Parent']))
.then((_) => {
fixture.detectChanges();
@ -383,8 +395,9 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
compile(tcb, `<a [routerLink]="['/Parent']">link to inner</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then(
(_) => rtr.config(
[new Route({path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(getHref(getLinkElement(fixture))).toEqual('/a');
@ -396,8 +409,9 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
inject([AsyncTestCompleter, Location], (async, location) => {
compile(tcb, `<a [routerLink]="['/Parent']">link to inner</a> | outer { <router-outlet></router-outlet> }`)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then(
(_) => rtr.config(
[new Route({path: '/a/...', component: ParentWithDefaultCmp, name: 'Parent'})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('link to inner | outer { }');
@ -429,38 +443,37 @@ function syncRoutesWithDynamicComponents() {
it('should work',
inject(
[AsyncTestCompleter],
(async) => {tcb.createAsync(DynamicLoaderCmp)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route({path: '/', component: HelloCmp})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ }');
return fixture.componentInstance.onSomeAction();
})
.then((_) => {
fixture.detectChanges();
return rtr.navigateByUrl('/');
})
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ hello }');
inject([AsyncTestCompleter],
(async) => {tcb.createAsync(DynamicLoaderCmp)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route({path: '/', component: HelloCmp})]))
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ }');
return fixture.componentInstance.onSomeAction();
})
.then((_) => {
fixture.detectChanges();
return rtr.navigateByUrl('/');
})
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ hello }');
return fixture.componentInstance.onSomeAction();
})
.then((_) => {
return fixture.componentInstance.onSomeAction();
})
.then((_) => {
// TODO(i): This should be rewritten to use NgZone#onStable or
// something
// similar basically the assertion needs to run when the world is
// stable and we don't know when that is, only zones know.
PromiseWrapper.resolve(null).then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ hello }');
async.done();
});
})}));
// TODO(i): This should be rewritten to use NgZone#onStable or
// something
// similar basically the assertion needs to run when the world is
// stable and we don't know when that is, only zones know.
PromiseWrapper.resolve(null).then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('{ hello }');
async.done();
});
})}));
}

View File

@ -1,13 +1,45 @@
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, xdescribe, describe, el, expect, iit, inject, beforeEachProviders, it, xit} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {provide, Component, Injector, Inject} from 'angular2/core';
import {isPresent} from 'angular2/src/facade/lang';
import {PromiseWrapper, PromiseCompleter, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {
PromiseWrapper,
PromiseCompleter,
EventEmitter,
ObservableWrapper
} from 'angular2/src/facade/async';
import {Router, RouterOutlet, RouterLink, RouteParams} from 'angular2/router';
import {RouteConfig, Route, AuxRoute, AsyncRoute, Redirect} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
AuxRoute,
AsyncRoute,
Redirect
} from 'angular2/src/router/route_config/route_config_decorator';
import {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from 'angular2/src/router/interfaces';
import {
OnActivate,
OnDeactivate,
OnReuse,
CanDeactivate,
CanReuse
} from 'angular2/src/router/interfaces';
import {CanActivate} from 'angular2/src/router/lifecycle/lifecycle_annotations';
import {ComponentInstruction} from 'angular2/src/router/instruction';
@ -28,14 +60,14 @@ export function main() {
beforeEachProviders(() => TEST_ROUTER_PROVIDERS);
beforeEach(inject(
[TestComponentBuilder, Router], (tcBuilder: TestComponentBuilder, router: Router) => {
tcb = tcBuilder;
rtr = router;
cmpInstanceCount = 0;
log = [];
eventBus = new EventEmitter();
}));
beforeEach(inject([TestComponentBuilder, Router],
(tcBuilder: TestComponentBuilder, router: Router) => {
tcb = tcBuilder;
rtr = router;
cmpInstanceCount = 0;
log = [];
eventBus = new EventEmitter();
}));
it('should call the routerOnActivate hook', inject([AsyncTestCompleter], (async) => {
compile(tcb)
@ -61,14 +93,16 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigateByUrl('/parent-activate/child-activate').then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('parent {activate cmp}');
expect(log).toEqual([
'parent activate: null -> /parent-activate', 'activate: null -> /child-activate'
]);
async.done();
});
rtr.navigateByUrl('/parent-activate/child-activate')
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('parent {activate cmp}');
expect(log).toEqual([
'parent activate: null -> /parent-activate',
'activate: null -> /child-activate'
]);
async.done();
});
});
}));
@ -169,12 +203,13 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigateByUrl('/can-activate/a').then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('routerCanActivate {A}');
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
async.done();
});
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('routerCanActivate {A}');
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
async.done();
});
});
}));
@ -189,12 +224,13 @@ export function main() {
completer.resolve(false);
}
});
rtr.navigateByUrl('/can-activate/a').then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
async.done();
});
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
async.done();
});
});
}));
@ -343,19 +379,19 @@ export function main() {
}
@Component({selector: 'a-cmp', template: 'A'})
@Component({selector: 'a-cmp', template: "A"})
class A {
}
@Component({selector: 'b-cmp', template: 'B'})
@Component({selector: 'b-cmp', template: "B"})
class B {
}
function logHook(name: string, next: ComponentInstruction, prev: ComponentInstruction) {
var message = name + ': ' + (isPresent(prev) ? ('/' + prev.urlPath) : 'null') + ' -> ' +
(isPresent(next) ? ('/' + next.urlPath) : 'null');
(isPresent(next) ? ('/' + next.urlPath) : 'null');
log.push(message);
ObservableWrapper.callEmit(eventBus, message);
}
@ -447,8 +483,8 @@ class NeverReuseCmp implements OnReuse,
@RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})])
@CanActivate(CanActivateCmp.routerCanActivate)
class CanActivateCmp {
static routerCanActivate(next: ComponentInstruction, prev: ComponentInstruction):
Promise<boolean> {
static routerCanActivate(next: ComponentInstruction,
prev: ComponentInstruction): Promise<boolean> {
completer = PromiseWrapper.completer();
logHook('routerCanActivate', next, prev);
return completer.promise;
@ -557,7 +593,8 @@ class ReuseHooksCmp implements OnActivate, OnReuse, OnDeactivate, CanReuse, CanD
directives: [RouterOutlet]
})
@RouteConfig([
new Route({path: '/a', component: A}), new Route({path: '/on-activate', component: ActivateCmp}),
new Route({path: '/a', component: A}),
new Route({path: '/on-activate', component: ActivateCmp}),
new Route({path: '/parent-activate/...', component: ParentActivateCmp}),
new Route({path: '/on-deactivate', component: DeactivateCmp}),
new Route({path: '/parent-deactivate/...', component: ParentDeactivateCmp}),

View File

@ -1,10 +1,31 @@
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, xdescribe, describe, el, expect, iit, inject, beforeEachProviders, it, xit} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {provide, Component, Injector, Inject} from 'angular2/core';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {Router, RouterOutlet, RouterLink, RouteParams, RouteData, Location} from 'angular2/router';
import {RouteConfig, Route, AuxRoute, AsyncRoute, Redirect} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
AuxRoute,
AsyncRoute,
Redirect
} from 'angular2/src/router/route_config/route_config_decorator';
import {TEST_ROUTER_PROVIDERS, RootCmp, compile} from './util';
@ -155,8 +176,9 @@ export function main() {
it('should inject route data into component', inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/route-data', component: RouteDataCmp, data: {isAdmin: true}})]))
.then((_) => rtr.config([
new Route({path: '/route-data', component: RouteDataCmp, data: {isAdmin: true}})
]))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
fixture.detectChanges();
@ -169,8 +191,10 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new AsyncRoute(
{path: '/route-data', loader: asyncRouteDataCmp, data: {isAdmin: true}})]))
.then((_) => rtr.config([
new AsyncRoute(
{path: '/route-data', loader: asyncRouteDataCmp, data: {isAdmin: true}})
]))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
fixture.detectChanges();
@ -183,8 +207,8 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile(tcb)
.then((rtc) => {fixture = rtc})
.then((_) => rtr.config([new Route(
{path: '/route-data-default', component: RouteDataCmp})]))
.then((_) => rtr.config(
[new Route({path: '/route-data-default', component: RouteDataCmp})]))
.then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => {
fixture.detectChanges();

View File

@ -1,7 +1,28 @@
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, xdescribe, describe, el, expect, iit, inject, beforeEachProviders, it, xit} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {Router, RouterOutlet, RouterLink, RouteParams, RouteData, Location} from 'angular2/router';
import {RouteConfig, Route, AuxRoute, AsyncRoute, Redirect} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
AuxRoute,
AsyncRoute,
Redirect
} from 'angular2/src/router/route_config/route_config_decorator';
import {TEST_ROUTER_PROVIDERS, RootCmp, compile} from './util';
import {HelloCmp, GoodbyeCmp, RedirectToParentCmp} from './impl/fixture_components';

View File

@ -1,4 +1,21 @@
import {ComponentFixture, AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, dispatchEvent, expect, iit, inject, beforeEachProviders, it, xit, TestComponentBuilder, proxy, SpyObject} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
beforeEach,
ddescribe,
xdescribe,
describe,
dispatchEvent,
expect,
iit,
inject,
beforeEachProviders,
it,
xit,
TestComponentBuilder,
proxy,
SpyObject
} from 'angular2/testing_internal';
import {By} from 'angular2/platform/common_dom';
import {NumberWrapper} from 'angular2/src/facade/lang';
@ -8,7 +25,20 @@ import {ListWrapper} from 'angular2/src/facade/collection';
import {provide, Component, DirectiveResolver} from 'angular2/core';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {Location, Router, RouteRegistry, RouterLink, RouterOutlet, AsyncRoute, AuxRoute, Route, RouteParams, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT} from 'angular2/router';
import {
Location,
Router,
RouteRegistry,
RouterLink,
RouterOutlet,
AsyncRoute,
AuxRoute,
Route,
RouteParams,
RouteConfig,
ROUTER_DIRECTIVES,
ROUTER_PRIMARY_COMPONENT
} from 'angular2/router';
import {RootRouter} from 'angular2/src/router/router';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
@ -22,21 +52,23 @@ export function main() {
var router: Router;
var location: Location;
beforeEachProviders(
() =>
[RouteRegistry, DirectiveResolver, provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: MyComp}),
provide(Router, {useClass: RootRouter}),
provide(TEMPLATE_TRANSFORMS, {useClass: RouterLinkTransform, multi: true})]);
beforeEachProviders(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: MyComp}),
provide(Router, {useClass: RootRouter}),
provide(TEMPLATE_TRANSFORMS, {useClass: RouterLinkTransform, multi: true})
]);
beforeEach(inject(
[TestComponentBuilder, Router, Location], (tcBuilder, rtr: Router, loc: Location) => {
tcb = tcBuilder;
router = rtr;
location = loc;
}));
beforeEach(inject([TestComponentBuilder, Router, Location],
(tcBuilder, rtr: Router, loc: Location) => {
tcb = tcBuilder;
router = rtr;
location = loc;
}));
function compile(template: string = '<router-outlet></router-outlet>') {
function compile(template: string = "<router-outlet></router-outlet>") {
return tcb.overrideTemplate(MyComp, ('<div>' + template + '</div>'))
.createAsync(MyComp)
.then((tc) => { fixture = tc; });
@ -46,9 +78,8 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
(<SpyLocation>location).setBaseHref('/my/base');
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
.then(
(_) =>
router.config([new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -60,9 +91,8 @@ export function main() {
it('should generate link hrefs without params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
.then(
(_) =>
router.config([new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -74,8 +104,8 @@ export function main() {
it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [routerLink]="[\'./User\', {name: name}]">{{name}}</a>')
.then((_) => router.config([new Route(
{path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.debugElement.componentInstance.name = 'brian';
@ -89,8 +119,9 @@ export function main() {
it('should generate link hrefs from a child to its sibling',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new Route(
{path: '/page/:number', component: SiblingPageCmp, name: 'Page'})]))
.then(
(_) => router.config(
[new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Page'})]))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
fixture.detectChanges();
@ -102,8 +133,10 @@ export function main() {
it('should generate link hrefs from a child to its sibling with no leading slash',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new Route(
{path: '/page/:number', component: NoPrefixSiblingPageCmp, name: 'Page'})]))
.then((_) => router.config([
new Route(
{path: '/page/:number', component: NoPrefixSiblingPageCmp, name: 'Page'})
]))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
fixture.detectChanges();
@ -115,8 +148,9 @@ export function main() {
it('should generate link hrefs to a child with no leading slash',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new Route(
{path: '/book/:title/...', component: NoPrefixBookCmp, name: 'Book'})]))
.then((_) => router.config([
new Route({path: '/book/:title/...', component: NoPrefixBookCmp, name: 'Book'})
]))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
fixture.detectChanges();
@ -128,8 +162,9 @@ export function main() {
it('should throw when links without a leading slash are ambiguous',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new Route(
{path: '/book/:title/...', component: AmbiguousBookCmp, name: 'Book'})]))
.then((_) => router.config([
new Route({path: '/book/:title/...', component: AmbiguousBookCmp, name: 'Book'})
]))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
var link = ListWrapper.toJSON(['Book', {number: 100}]);
@ -143,11 +178,13 @@ export function main() {
it('should generate link hrefs when asynchronously loaded',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new AsyncRoute({
path: '/child-with-grandchild/...',
loader: parentCmpLoader,
name: 'ChildWithGrandchild'
})]))
.then((_) => router.config([
new AsyncRoute({
path: '/child-with-grandchild/...',
loader: parentCmpLoader,
name: 'ChildWithGrandchild'
})
]))
.then((_) => router.navigateByUrl('/child-with-grandchild/grandchild'))
.then((_) => {
fixture.detectChanges();
@ -159,26 +196,24 @@ export function main() {
it('should generate relative links preserving the existing parent route',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([new Route(
{path: '/book/:title/...', component: BookCmp, name: 'Book'})]))
.then((_) => router.config(
[new Route({path: '/book/:title/...', component: BookCmp, name: 'Book'})]))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
fixture.detectChanges();
// TODO(juliemr): This should be one By.css('book-cmp a') query, but the parse5
// adapter
// can't handle css child selectors.
expect(DOM.getAttribute(
fixture.debugElement.query(By.css('book-cmp'))
.query(By.css('a'))
.nativeElement,
'href'))
expect(DOM.getAttribute(fixture.debugElement.query(By.css('book-cmp'))
.query(By.css('a'))
.nativeElement,
'href'))
.toEqual('/book/1984/page/100');
expect(DOM.getAttribute(
fixture.debugElement.query(By.css('page-cmp'))
.query(By.css('a'))
.nativeElement,
'href'))
expect(DOM.getAttribute(fixture.debugElement.query(By.css('page-cmp'))
.query(By.css('a'))
.nativeElement,
'href'))
.toEqual('/book/1984/page/2');
async.done();
});
@ -198,11 +233,10 @@ export function main() {
describe('router-link-active CSS class', () => {
it('should be added to the associated element', inject([AsyncTestCompleter], (async) => {
router
.config([
new Route({path: '/child', component: HelloCmp, name: 'Child'}),
new Route({path: '/better-child', component: Hello2Cmp, name: 'BetterChild'})
])
router.config([
new Route({path: '/child', component: HelloCmp, name: 'Child'}),
new Route({path: '/better-child', component: Hello2Cmp, name: 'BetterChild'})
])
.then((_) => compile(`<a [routerLink]="['./Child']" class="child-link">Child</a>
<a [routerLink]="['./BetterChild']" class="better-child-link">Better Child</a>
<router-outlet></router-outlet>`))
@ -230,14 +264,14 @@ export function main() {
}));
it('should be added to links in child routes', inject([AsyncTestCompleter], (async) => {
router
.config([
new Route({path: '/child', component: HelloCmp, name: 'Child'}), new Route({
path: '/child-with-grandchild/...',
component: ParentCmp,
name: 'ChildWithGrandchild'
})
])
router.config([
new Route({path: '/child', component: HelloCmp, name: 'Child'}),
new Route({
path: '/child-with-grandchild/...',
component: ParentCmp,
name: 'ChildWithGrandchild'
})
])
.then((_) => compile(`<a [routerLink]="['./Child']" class="child-link">Child</a>
<a [routerLink]="['./ChildWithGrandchild/Grandchild']" class="child-with-grandchild-link">Better Child</a>
<router-outlet></router-outlet>`))
@ -274,8 +308,8 @@ export function main() {
describe('router link dsl', () => {
it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [routerLink]="route:./User(name: name)">{{name}}</a>')
.then((_) => router.config([new Route(
{path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.debugElement.componentInstance.name = 'brian';
@ -299,8 +333,8 @@ export function main() {
it('should navigate to link hrefs without params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
.then((_) => router.config([new Route(
{path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -320,8 +354,8 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
(<SpyLocation>location).setBaseHref('/base');
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
.then((_) => router.config([new Route(
{path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
fixture.detectChanges();
@ -350,7 +384,7 @@ class MyComp {
name;
}
@Component({selector: 'user-cmp', template: 'hello {{user}}'})
@Component({selector: 'user-cmp', template: "hello {{user}}"})
class UserCmp {
user: string;
constructor(params: RouteParams) { this.user = params.get('name'); }

View File

@ -1,4 +1,12 @@
import {describeRouter, ddescribeRouter, describeWith, describeWithout, describeWithAndWithout, itShouldRoute, TEST_ROUTER_PROVIDERS} from './util';
import {
describeRouter,
ddescribeRouter,
describeWith,
describeWithout,
describeWithAndWithout,
itShouldRoute,
TEST_ROUTER_PROVIDERS
} from './util';
import {beforeEachProviders, describe, ddescribe} from 'angular2/testing_internal';
@ -15,8 +23,8 @@ export function main() {
describeWithout('children', () => { describeWithAndWithout('params', itShouldRoute); });
describeWith('sync children', () => {
describeWithout(
'default routes', () => { describeWithAndWithout('params', itShouldRoute); });
describeWithout('default routes',
() => { describeWithAndWithout('params', itShouldRoute); });
describeWith('default routes', () => { describeWithout('params', itShouldRoute); });
});

View File

@ -2,7 +2,20 @@ import {provide, Provider, Component} from 'angular2/core';
import {Type, isBlank} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, xdescribe, describe, el, inject, beforeEachProviders, it, xit} from 'angular2/testing_internal';
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {RootRouter} from 'angular2/src/router/router';
import {Router, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT} from 'angular2/router';
@ -28,14 +41,17 @@ export class RootCmp {
name: string;
}
export function compile(
tcb: TestComponentBuilder, template: string = '<router-outlet></router-outlet>') {
export function compile(tcb: TestComponentBuilder,
template: string = "<router-outlet></router-outlet>") {
return tcb.overrideTemplate(RootCmp, ('<div>' + template + '</div>')).createAsync(RootCmp);
}
export var TEST_ROUTER_PROVIDERS = [
RouteRegistry, DirectiveResolver, provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: RootCmp}), provide(Router, {useClass: RootRouter})
RouteRegistry,
DirectiveResolver,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: RootCmp}),
provide(Router, {useClass: RootRouter})
];
export function clickOnElement(anchorEl) {

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, describe, proxy, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
proxy,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
beforeEachProviders,
SpyObject
} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, describe, proxy, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
proxy,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
beforeEachProviders,
SpyObject
} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/facade/lang';
@ -69,8 +81,8 @@ export function main() {
var locationStrategy = new MockLocationStrategy();
var location = new Location(locationStrategy);
location.go('/home', 'key=value');
expect(location.path()).toEqual('/home?key=value');
location.go('/home', "key=value");
expect(location.path()).toEqual("/home?key=value");
});
});
}

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, describe, proxy, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
proxy,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
beforeEachProviders,
SpyObject
} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/facade/lang';
@ -12,9 +24,10 @@ export function main() {
describe('PathLocationStrategy', () => {
var platformLocation, locationStrategy;
beforeEachProviders(() => [PathLocationStrategy, provide(PlatformLocation, {
useFactory: makeSpyPlatformLocation
})]);
beforeEachProviders(() => [
PathLocationStrategy,
provide(PlatformLocation, {useFactory: makeSpyPlatformLocation})
]);
it('should throw without a base element or APP_BASE_HREF', () => {
platformLocation = new SpyPlatformLocation();

View File

@ -1,4 +1,15 @@
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xdescribe,
xit,
} from 'angular2/testing_internal';
import {bootstrap} from 'angular2/platform/browser';
import {Component, Directive} from 'angular2/src/core/metadata';
@ -8,7 +19,13 @@ import {provide} from 'angular2/core';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
import {Type, IS_DART} from 'angular2/src/facade/lang';
import {ROUTER_PROVIDERS, Router, RouteConfig, APP_BASE_HREF, ROUTER_DIRECTIVES} from 'angular2/router';
import {
ROUTER_PROVIDERS,
Router,
RouteConfig,
APP_BASE_HREF,
ROUTER_DIRECTIVES
} from 'angular2/router';
import {ExceptionHandler} from 'angular2/src/facade/exceptions';
import {LocationStrategy} from 'angular2/src/router/location/location_strategy';
@ -36,7 +53,8 @@ export function main() {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
testBindings = [
ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: MockLocationStrategy}),
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}),
provide(ExceptionHandler, {useValue: exceptionHandler}),
provide(Console, {useClass: DummyConsole})
@ -44,138 +62,153 @@ export function main() {
});
it('should bootstrap an app with a hierarchy', inject([AsyncTestCompleter], (async) => {
bootstrap(HierarchyAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { parent { hello } }');
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
bootstrap(HierarchyAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { parent { hello } }');
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
it('should work in an app with redirects', inject([AsyncTestCompleter], (async) => {
bootstrap(RedirectAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/after');
async.done();
});
router.navigateByUrl('/before');
});
bootstrap(RedirectAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/after');
async.done();
});
router.navigateByUrl('/before');
});
}));
it('should work in an app with async components', inject([AsyncTestCompleter], (async) => {
bootstrap(AsyncAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
bootstrap(AsyncAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
}));
it('should work in an app with aux routes', inject([AsyncTestCompleter], (async) => {
bootstrap(AuxAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello } aside { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello(aside)');
async.done();
});
router.navigateByUrl('/hello(aside)');
});
bootstrap(AuxAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello } aside { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello(aside)');
async.done();
});
router.navigateByUrl('/hello(aside)');
});
}));
it('should work in an app with async components defined with "loader"',
inject([AsyncTestCompleter], (async) => {
bootstrap(ConciseAsyncAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
bootstrap(ConciseAsyncAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
}));
it('should work in an app with a constructor component',
inject([AsyncTestCompleter], (async) => {
bootstrap(ExplicitConstructorAppCmp, testBindings).then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
bootstrap(ExplicitConstructorAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
});
}));
it('should throw if a config is missing a target',
inject(
[AsyncTestCompleter],
(async) => {bootstrap(WrongConfigCmp, testBindings).catch((e) => {
expect(e.originalException)
.toContainError(
'Route config should contain exactly one "component", "loader", or "redirectTo" property.');
async.done();
return null;
})}));
(async) => {
bootstrap(WrongConfigCmp, testBindings)
.catch((e) => {
expect(e.originalException)
.toContainError(
'Route config should contain exactly one "component", "loader", or "redirectTo" property.');
async.done();
return null;
})}));
it('should throw if a config has an invalid component type',
inject(
[AsyncTestCompleter],
(async) => {bootstrap(WrongComponentTypeCmp, testBindings).catch((e) => {
expect(e.originalException)
.toContainError(
'Invalid component type "intentionallyWrongComponentType". Valid types are "constructor" and "loader".');
async.done();
return null;
})}));
(async) => {
bootstrap(WrongComponentTypeCmp, testBindings)
.catch((e) => {
expect(e.originalException)
.toContainError(
'Invalid component type "intentionallyWrongComponentType". Valid types are "constructor" and "loader".');
async.done();
return null;
})}));
it('should throw if a config has an invalid alias name',
inject(
[AsyncTestCompleter],
(async) => {bootstrap(BadAliasNameCmp, testBindings).catch((e) => {
expect(e.originalException)
.toContainError(
`Route "/child" with name "child" does not begin with an uppercase letter. Route names should be CamelCase like "Child".`);
async.done();
return null;
})}));
(async) => {
bootstrap(BadAliasNameCmp, testBindings)
.catch((e) => {
expect(e.originalException)
.toContainError(
`Route "/child" with name "child" does not begin with an uppercase letter. Route names should be CamelCase like "Child".`);
async.done();
return null;
})}));
it('should throw if a config has an invalid alias name with "as"',
inject(
[AsyncTestCompleter],
(async) => {bootstrap(BadAliasCmp, testBindings).catch((e) => {
expect(e.originalException)
.toContainError(
`Route "/child" with name "child" does not begin with an uppercase letter. Route names should be CamelCase like "Child".`);
async.done();
return null;
})}));
(async) => {
bootstrap(BadAliasCmp, testBindings)
.catch((e) => {
expect(e.originalException)
.toContainError(
`Route "/child" with name "child" does not begin with an uppercase letter. Route names should be CamelCase like "Child".`);
async.done();
return null;
})}));
it('should throw if a config has multiple alias properties "as" and "name"',
inject(
[AsyncTestCompleter],
(async) => {bootstrap(MultipleAliasCmp, testBindings).catch((e) => {
expect(e.originalException)
.toContainError(
`Route config should contain exactly one "as" or "name" property.`);
async.done();
return null;
})}));
inject([AsyncTestCompleter],
(async) => {
bootstrap(MultipleAliasCmp, testBindings)
.catch((e) => {
expect(e.originalException)
.toContainError(
`Route config should contain exactly one "as" or "name" property.`);
async.done();
return null;
})}));
});
}
@ -190,7 +223,8 @@ class HelloCmp {
directives: ROUTER_DIRECTIVES
})
@RouteConfig([
{path: '/before', redirectTo: ['Hello']}, {path: '/after', component: HelloCmp, name: 'Hello'}
{path: '/before', redirectTo: ['Hello']},
{path: '/after', component: HelloCmp, name: 'Hello'}
])
class RedirectAppCmp {
constructor(public router: Router, public location: LocationStrategy) {}

View File

@ -1,10 +1,26 @@
import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
SpyObject
} from 'angular2/testing_internal';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {Type, IS_DART} from 'angular2/src/facade/lang';
import {RouteRegistry} from 'angular2/src/router/route_registry';
import {RouteConfig, Route, Redirect, AuxRoute, AsyncRoute} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
Route,
Redirect,
AuxRoute,
AsyncRoute
} from 'angular2/src/router/route_config/route_config_decorator';
export function main() {
@ -17,16 +33,16 @@ export function main() {
registry.config(RootHostCmp, new Route({path: '/', component: DummyCmpA}));
registry.config(RootHostCmp, new Route({path: '/test', component: DummyCmpB}));
registry.recognize('/test', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpB);
async.done();
});
registry.recognize('/test', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpB);
async.done();
});
}));
it('should generate URLs starting at the given component', () => {
registry.config(
RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, name: 'FirstCmp'}));
registry.config(RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, name: 'FirstCmp'}));
var instr = registry.generate(['FirstCmp', 'SecondCmp'], []);
expect(stringifyInstruction(instr)).toEqual('first/second');
@ -76,8 +92,8 @@ export function main() {
});
it('should generate URLs with extra params in the query', () => {
registry.config(
RootHostCmp, new Route({path: '/first/second', component: DummyCmpA, name: 'FirstCmp'}));
registry.config(RootHostCmp,
new Route({path: '/first/second', component: DummyCmpA, name: 'FirstCmp'}));
var instruction = registry.generate(['FirstCmp', {a: 'one'}], []);
expect(instruction.toLinkUrl()).toEqual('first/second?a=one');
@ -94,78 +110,84 @@ export function main() {
expect(stringifyInstruction(instruction)).toEqual('first');
registry.recognize('/first/second', []).then((_) => {
var instruction = registry.generate(['FirstCmp', 'SecondCmp'], []);
expect(stringifyInstruction(instruction)).toEqual('first/second');
async.done();
});
registry.recognize('/first/second', [])
.then((_) => {
var instruction = registry.generate(['FirstCmp', 'SecondCmp'], []);
expect(stringifyInstruction(instruction)).toEqual('first/second');
async.done();
});
}));
it('should throw when generating a url and a parent has no config', () => {
expect(() => registry.generate(['FirstCmp', 'SecondCmp'], [
])).toThrowError('Component "RootHostCmp" has no route config.');
expect(() => registry.generate(['FirstCmp', 'SecondCmp'], []))
.toThrowError('Component "RootHostCmp" has no route config.');
});
it('should generate URLs for aux routes', () => {
registry.config(
RootHostCmp, new Route({path: '/primary', component: DummyCmpA, name: 'Primary'}));
registry.config(RootHostCmp,
new Route({path: '/primary', component: DummyCmpA, name: 'Primary'}));
registry.config(RootHostCmp, new AuxRoute({path: '/aux', component: DummyCmpB, name: 'Aux'}));
expect(stringifyInstruction(registry.generate(['Primary', ['Aux']], [
]))).toEqual('primary(aux)');
expect(stringifyInstruction(registry.generate(['Primary', ['Aux']], [])))
.toEqual('primary(aux)');
});
it('should prefer static segments to dynamic', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/:site', component: DummyCmpB}));
registry.config(RootHostCmp, new Route({path: '/home', component: DummyCmpA}));
registry.recognize('/home', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
registry.recognize('/home', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should prefer dynamic segments to star', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/:site', component: DummyCmpA}));
registry.config(RootHostCmp, new Route({path: '/*site', component: DummyCmpB}));
registry.recognize('/home', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
registry.recognize('/home', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should prefer routes with more dynamic segments', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/:first/*rest', component: DummyCmpA}));
registry.config(RootHostCmp, new Route({path: '/*all', component: DummyCmpB}));
registry.recognize('/some/path', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
registry.recognize('/some/path', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should prefer routes with more static segments', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first/:second', component: DummyCmpA}));
registry.config(RootHostCmp, new Route({path: '/:first/:second', component: DummyCmpB}));
registry.recognize('/first/second', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
registry.recognize('/first/second', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should prefer routes with static segments before dynamic segments',
inject([AsyncTestCompleter], (async) => {
registry.config(
RootHostCmp, new Route({path: '/first/second/:third', component: DummyCmpB}));
registry.config(
RootHostCmp, new Route({path: '/first/:second/third', component: DummyCmpA}));
registry.config(RootHostCmp,
new Route({path: '/first/second/:third', component: DummyCmpB}));
registry.config(RootHostCmp,
new Route({path: '/first/:second/third', component: DummyCmpA}));
registry.recognize('/first/second/third', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpB);
async.done();
});
registry.recognize('/first/second/third', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpB);
async.done();
});
}));
it('should prefer routes with high specificity over routes with children with lower specificity',
@ -173,66 +195,69 @@ export function main() {
registry.config(RootHostCmp, new Route({path: '/first', component: DummyCmpA}));
// terminates to DummyCmpB
registry.config(
RootHostCmp, new Route({path: '/:second/...', component: SingleSlashChildCmp}));
registry.config(RootHostCmp,
new Route({path: '/:second/...', component: SingleSlashChildCmp}));
registry.recognize('/first', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
registry.recognize('/first', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should match the full URL using child components', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp}));
registry.recognize('/first/second', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
expect(instruction.child.component.componentType).toBe(DummyCmpB);
async.done();
});
registry.recognize('/first/second', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
expect(instruction.child.component.componentType).toBe(DummyCmpB);
async.done();
});
}));
it('should match the URL using async child components',
inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyAsyncCmp}));
registry.recognize('/first/second', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyAsyncCmp);
registry.recognize('/first/second', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyAsyncCmp);
instruction.child.resolveComponent().then((childComponentInstruction) => {
expect(childComponentInstruction.componentType).toBe(DummyCmpB);
async.done();
});
});
instruction.child.resolveComponent().then((childComponentInstruction) => {
expect(childComponentInstruction.componentType).toBe(DummyCmpB);
async.done();
});
});
}));
it('should match the URL using an async parent component',
inject([AsyncTestCompleter], (async) => {
registry.config(
RootHostCmp, new AsyncRoute({path: '/first/...', loader: asyncParentLoader}));
registry.config(RootHostCmp,
new AsyncRoute({path: '/first/...', loader: asyncParentLoader}));
registry.recognize('/first/second', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
registry.recognize('/first/second', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
instruction.child.resolveComponent().then((childType) => {
expect(childType.componentType).toBe(DummyCmpB);
async.done();
});
});
instruction.child.resolveComponent().then((childType) => {
expect(childType.componentType).toBe(DummyCmpB);
async.done();
});
});
}));
it('should throw when a parent config is missing the `...` suffix any of its children add routes',
() => {
expect(
() => registry.config(RootHostCmp, new Route({path: '/', component: DummyParentCmp})))
expect(() =>
registry.config(RootHostCmp, new Route({path: '/', component: DummyParentCmp})))
.toThrowError(
'Child routes are not allowed for "/". Use "..." on the parent\'s route path.');
});
it('should throw when a parent config uses `...` suffix before the end of the route', () => {
expect(
() => registry.config(
RootHostCmp, new Route({path: '/home/.../fun/', component: DummyParentCmp})))
expect(() => registry.config(RootHostCmp,
new Route({path: '/home/.../fun/', component: DummyParentCmp})))
.toThrowError('Unexpected "..." before the end of the path for "home/.../fun/".');
});
@ -245,32 +270,31 @@ export function main() {
// This would never happen in Dart
if (!IS_DART) {
expect(
() => registry.config(RootHostCmp, new Route({path: '/', component: <Type>(<any>4)})))
expect(() => registry.config(RootHostCmp, new Route({path: '/', component:<Type>(<any>4)})))
.toThrowError('Component for route "/" is not defined, or is not a class.');
}
});
it('should throw when linkParams are not terminal', () => {
registry.config(
RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp, name: 'First'}));
expect(() => {
registry.generate(['First'], []);
}).toThrowError('Link "["First"]" does not resolve to a terminal instruction.');
registry.config(RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, name: 'First'}));
expect(() => { registry.generate(['First'], []); })
.toThrowError('Link "["First"]" does not resolve to a terminal instruction.');
});
it('should match matrix params on child components and query params on the root component',
inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp}));
registry.recognize('/first/second;filter=odd?comments=all', []).then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
expect(instruction.component.params).toEqual({'comments': 'all'});
registry.recognize('/first/second;filter=odd?comments=all', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyParentCmp);
expect(instruction.component.params).toEqual({'comments': 'all'});
expect(instruction.child.component.componentType).toBe(DummyCmpB);
expect(instruction.child.component.params).toEqual({'filter': 'odd'});
async.done();
});
expect(instruction.child.component.componentType).toBe(DummyCmpB);
expect(instruction.child.component.params).toEqual({'filter': 'odd'});
async.done();
});
}));
it('should generate URLs with matrix and query params', () => {
@ -280,7 +304,10 @@ export function main() {
var url = stringifyInstruction(registry.generate(
[
'FirstCmp', {param: 'one', query: 'cats'}, 'SecondCmp', {
'FirstCmp',
{param: 'one', query: 'cats'},
'SecondCmp',
{
param: 'two',
sort: 'asc',
}
@ -324,8 +351,10 @@ class SingleSlashChildCmp {
}
@RouteConfig([new Route(
{path: '/second/...', component: DefaultRouteCmp, name: 'SecondCmp', useAsDefault: true})])
@RouteConfig([
new Route(
{path: '/second/...', component: DefaultRouteCmp, name: 'SecondCmp', useAsDefault: true})
])
class MultipleDefaultCmp {
}

View File

@ -1,4 +1,16 @@
import {AsyncTestCompleter, describe, proxy, it, iit, xit, ddescribe, expect, inject, beforeEach, beforeEachProviders} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
proxy,
it,
iit,
xit,
ddescribe,
expect,
inject,
beforeEach,
beforeEachProviders
} from 'angular2/testing_internal';
import {SpyRouterOutlet} from './spies';
import {Type} from 'angular2/src/facade/lang';
import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
@ -9,7 +21,12 @@ import {SpyLocation} from 'angular2/src/mock/location_mock';
import {Location} from 'angular2/src/router/location/location';
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from 'angular2/src/router/route_registry';
import {RouteConfig, AsyncRoute, Route, Redirect} from 'angular2/src/router/route_config/route_config_decorator';
import {
RouteConfig,
AsyncRoute,
Route,
Redirect
} from 'angular2/src/router/route_config/route_config_decorator';
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
import {provide} from 'angular2/core';
@ -20,11 +37,13 @@ export function main() {
var router: Router;
var location: Location;
beforeEachProviders(
() =>
[RouteRegistry, DirectiveResolver, provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(Router, {useClass: RootRouter})]);
beforeEachProviders(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(Router, {useClass: RootRouter})
]);
beforeEach(inject([Router, Location], (rtr: Router, loc: Location) => {
@ -64,9 +83,8 @@ export function main() {
var outlet = makeDummyOutlet();
router.registerPrimaryOutlet(outlet)
.then(
(_) =>
router.config([new Route({path: '/a', component: DummyComponent, name: 'A'})]))
.then((_) => router.config(
[new Route({path: '/a', component: DummyComponent, name: 'A'})]))
.then((_) => router.navigate(['/A']))
.then((_) => {
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
@ -191,10 +209,11 @@ export function main() {
router.config([new AsyncRoute({path: '/first', loader: loader, name: 'FirstCmp'})]);
var instruction = router.generate(['/FirstCmp']);
router.navigateByInstruction(instruction).then((_) => {
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
async.done();
});
router.navigateByInstruction(instruction)
.then((_) => {
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
async.done();
});
}));
it('should return whether a given instruction is active with isRouteActive',
@ -260,8 +279,9 @@ export function main() {
it('should serialize parameters that are not part of the route definition as query string params',
() => {
router.config([new Route(
{path: '/one/two/:three', component: DummyComponent, name: 'NumberUrl'})]);
router.config([
new Route({path: '/one/two/:three', component: DummyComponent, name: 'NumberUrl'})
]);
var instruction = router.generate(['/NumberUrl', {'three': 'three', 'four': 'four'}]);
var path = stringifyInstruction(instruction);

View File

@ -1,4 +1,14 @@
import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
SpyObject
} from 'angular2/testing_internal';
import {ParamRoutePath} from 'angular2/src/router/rules/route_paths/param_route_path';
import {parser, Url} from 'angular2/src/router/url_parser';

View File

@ -1,4 +1,14 @@
import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
SpyObject
} from 'angular2/testing_internal';
import {GeneratedUrl} from 'angular2/src/router/rules/route_paths/route_path';
import {RegexRoutePath} from 'angular2/src/router/rules/route_paths/regex_route_path';

View File

@ -1,4 +1,14 @@
import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
SpyObject
} from 'angular2/testing_internal';
import {Map, StringMapWrapper} from 'angular2/src/facade/collection';
@ -20,43 +30,47 @@ export function main() {
it('should recognize a static segment', inject([AsyncTestCompleter], (async) => {
recognizer.config(new Route({path: '/test', component: DummyCmpA}));
recognize(recognizer, '/test').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
async.done();
});
recognize(recognizer, '/test')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
async.done();
});
}));
it('should recognize a single slash', inject([AsyncTestCompleter], (async) => {
recognizer.config(new Route({path: '/', component: DummyCmpA}));
recognize(recognizer, '/').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
async.done();
});
recognize(recognizer, '/')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
async.done();
});
}));
it('should recognize a dynamic segment', inject([AsyncTestCompleter], (async) => {
recognizer.config(new Route({path: '/user/:name', component: DummyCmpA}));
recognize(recognizer, '/user/brian').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0])).toEqual({'name': 'brian'});
async.done();
});
recognize(recognizer, '/user/brian')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0])).toEqual({'name': 'brian'});
async.done();
});
}));
it('should recognize a star segment', inject([AsyncTestCompleter], (async) => {
recognizer.config(new Route({path: '/first/*rest', component: DummyCmpA}));
recognize(recognizer, '/first/second/third').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0])).toEqual({'rest': 'second/third'});
async.done();
});
recognize(recognizer, '/first/second/third')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0])).toEqual({'rest': 'second/third'});
async.done();
});
}));
it('should recognize a regex', inject([AsyncTestCompleter], (async) => {
@ -64,13 +78,14 @@ export function main() {
recognizer.config(
new Route({regex: '^(.+)/(.+)$', serializer: emptySerializer, component: DummyCmpA}));
recognize(recognizer, '/first/second').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0]))
.toEqual({'0': 'first/second', '1': 'first', '2': 'second'});
async.done();
});
recognize(recognizer, '/first/second')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getComponentType(solutions[0])).toEqual(DummyCmpA);
expect(getParams(solutions[0]))
.toEqual({'0': 'first/second', '1': 'first', '2': 'second'});
async.done();
});
}));
@ -83,15 +98,13 @@ export function main() {
it('should throw when given two routes that have dynamic segments in the same order', () => {
recognizer.config(new Route({path: '/hello/:person/how/:doyoudou', component: DummyCmpA}));
expect(
() => recognizer.config(
new Route({path: '/hello/:friend/how/:areyou', component: DummyCmpA})))
expect(() => recognizer.config(
new Route({path: '/hello/:friend/how/:areyou', component: DummyCmpA})))
.toThrowError(
'Configuration \'/hello/:friend/how/:areyou\' conflicts with existing route \'/hello/:person/how/:doyoudou\'');
expect(
() => recognizer.config(
new Redirect({path: '/hello/:pal/how/:goesit', redirectTo: ['/Foo']})))
expect(() => recognizer.config(
new Redirect({path: '/hello/:pal/how/:goesit', redirectTo: ['/Foo']})))
.toThrowError(
'Configuration \'/hello/:pal/how/:goesit\' conflicts with existing route \'/hello/:person/how/:doyoudou\'');
});
@ -100,15 +113,16 @@ export function main() {
it('should recognize redirects', inject([AsyncTestCompleter], (async) => {
recognizer.config(new Route({path: '/b', component: DummyCmpA}));
recognizer.config(new Redirect({path: '/a', redirectTo: ['B']}));
recognize(recognizer, '/a').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
var solution = solutions[0];
expect(solution).toBeAnInstanceOf(RedirectMatch);
if (solution instanceof RedirectMatch) {
expect(solution.redirectTo).toEqual(['B']);
}
async.done();
});
recognize(recognizer, '/a')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
var solution = solutions[0];
expect(solution).toBeAnInstanceOf(RedirectMatch);
if (solution instanceof RedirectMatch) {
expect(solution.redirectTo).toEqual(['B']);
}
async.done();
});
}));
@ -152,9 +166,8 @@ export function main() {
it('should throw if the route alias is not TitleCase', () => {
expect(
() => recognizer.config(
new Route({path: 'app/user/:name', component: DummyCmpA, name: 'user'})))
expect(() => recognizer.config(
new Route({path: 'app/user/:name', component: DummyCmpA, name: 'user'})))
.toThrowError(
`Route "app/user/:name" with name "user" does not begin with an uppercase letter. Route names should be CamelCase like "User".`);
});
@ -165,11 +178,12 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
recognizer.config(
new Route({path: 'profile/:name', component: DummyCmpA, name: 'User'}));
recognize(recognizer, '/profile/matsko?comments=all').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getParams(solutions[0])).toEqual({'name': 'matsko', 'comments': 'all'});
async.done();
});
recognize(recognizer, '/profile/matsko?comments=all')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getParams(solutions[0])).toEqual({'name': 'matsko', 'comments': 'all'});
async.done();
});
}));
@ -190,11 +204,12 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
recognizer.config(
new Route({path: 'profile/:name', component: DummyCmpA, name: 'User'}));
recognize(recognizer, '/profile/yegor?name=igor').then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getParams(solutions[0])).toEqual({'name': 'yegor'});
async.done();
});
recognize(recognizer, '/profile/yegor?name=igor')
.then((solutions: RouteMatch[]) => {
expect(solutions.length).toBe(1);
expect(getParams(solutions[0])).toEqual({'name': 'yegor'});
async.done();
});
}));

View File

@ -1,4 +1,14 @@
import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, SpyObject} from 'angular2/testing_internal';
import {
AsyncTestCompleter,
describe,
it,
iit,
ddescribe,
expect,
inject,
beforeEach,
SpyObject
} from 'angular2/testing_internal';
import {UrlParser, Url} from 'angular2/src/router/url_parser';