fix(router): use lists for RouteConfig annotations

This commit is contained in:
Brian Ford
2015-04-29 15:47:12 -07:00
parent ea546f5069
commit 4965226f3f
7 changed files with 115 additions and 62 deletions
+6 -6
View File
@@ -53,7 +53,7 @@ export function main() {
it('should work in a simple case', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config('/test', HelloCmp))
.then((_) => router.config({'path': '/test', 'component': HelloCmp}))
.then((_) => router.navigate('/test'))
.then((_) => {
view.detectChanges();
@@ -65,7 +65,7 @@ export function main() {
it('should navigate between components with different parameters', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config('/user/:name', UserCmp))
.then((_) => router.config({'path': '/user/:name', 'component': UserCmp}))
.then((_) => router.navigate('/user/brian'))
.then((_) => {
view.detectChanges();
@@ -82,7 +82,7 @@ export function main() {
it('should work with child routers', inject([AsyncTestCompleter], (async) => {
compile('outer { <router-outlet></router-outlet> }')
.then((_) => router.config('/a', ParentCmp))
.then((_) => router.config({'path': '/a', 'component': ParentCmp}))
.then((_) => router.navigate('/a/b'))
.then((_) => {
view.detectChanges();
@@ -95,7 +95,7 @@ export function main() {
it('should generate link hrefs', inject([AsyncTestCompleter], (async) => {
ctx.name = 'brian';
compile('<a href="hello" router-link="user" [router-params]="{name: name}">{{name}}</a>')
.then((_) => router.config('/user/:name', UserCmp, 'user'))
.then((_) => router.config({'path': '/user/:name', 'component': UserCmp, 'alias': 'user'}))
.then((_) => router.navigate('/a/b'))
.then((_) => {
view.detectChanges();
@@ -144,10 +144,10 @@ class UserCmp {
template: "inner { <router-outlet></router-outlet> }",
directives: [RouterOutlet]
})
@RouteConfig({
@RouteConfig([{
path: '/b',
component: HelloCmp
})
}])
class ParentCmp {
constructor() {}
}
+19 -10
View File
@@ -6,36 +6,45 @@ import {
inject, beforeEach,
SpyObject} from 'angular2/test_lib';
import {RouteRegistry} from 'angular2/src/router/route_registry';
import {RouteRegistry, rootHostComponent} from 'angular2/src/router/route_registry';
import {RouteConfig} from 'angular2/src/router/route_config';
export function main() {
describe('RouteRegistry', () => {
var registry;
var handler = {};
var handler2 = {};
beforeEach(() => {
registry = new RouteRegistry();
});
it('should match the full URL', () => {
registry.config('/', '/', handler);
registry.config('/', '/test', handler2);
registry.config(rootHostComponent, {'path': '/', 'component': DummyCompA});
registry.config(rootHostComponent, {'path': '/test', 'component': DummyCompB});
var instruction = registry.recognize('/test');
expect(instruction.getChildInstruction('default').component).toBe(handler2);
expect(instruction.getChildInstruction('default').component).toBe(DummyCompB);
});
it('should match the full URL recursively', () => {
registry.config('/', '/first', handler);
registry.config(handler, '/second', handler2);
registry.config(rootHostComponent, {'path': '/first', 'component': DummyParentComp});
var instruction = registry.recognize('/first/second');
expect(instruction.getChildInstruction('default').component).toBe(handler);
expect(instruction.getChildInstruction('default').getChildInstruction('default').component).toBe(handler2);
var parentInstruction = instruction.getChildInstruction('default');
var childInstruction = parentInstruction.getChildInstruction('default');
expect(parentInstruction.component).toBe(DummyParentComp);
expect(childInstruction.component).toBe(DummyCompB);
});
});
}
@RouteConfig([
{'path': '/second', 'component': DummyCompB }
])
class DummyParentComp {}
class DummyCompA {}
class DummyCompB {}
+4 -4
View File
@@ -28,11 +28,11 @@ export function main() {
it('should navigate based on the initial URL state', inject([AsyncTestCompleter], (async) => {
var outlet = makeDummyRef();
router.config('/', {'component': 'Index' })
router.config({'path': '/', 'component': 'Index' })
.then((_) => router.registerOutlet(outlet))
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
expect(location.urlChanges).toEqual(['/']);
expect(location.urlChanges).toEqual([]);
async.done();
});
}));
@@ -43,7 +43,7 @@ export function main() {
router.registerOutlet(outlet)
.then((_) => {
return router.config('/a', {'component': 'A' });
return router.config({'path': '/a', 'component': 'A' });
})
.then((_) => router.navigate('/a'))
.then((_) => {
@@ -60,7 +60,7 @@ export function main() {
.then((_) => router.navigate('/a'))
.then((_) => {
expect(outlet.spy('activate')).not.toHaveBeenCalled();
return router.config('/a', {'component': 'A' });
return router.config({'path': '/a', 'component': 'A' });
})
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();