2015-04-17 12:59:56 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
describe,
|
2015-05-29 17:58:41 -04:00
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
ddescribe,
|
|
|
|
expect,
|
|
|
|
inject,
|
|
|
|
beforeEach,
|
|
|
|
SpyObject
|
|
|
|
} from 'angular2/test_lib';
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-01 08:53:38 -04:00
|
|
|
import {RouteRegistry} from 'angular2/src/router/route_registry';
|
2015-05-29 17:58:41 -04:00
|
|
|
import {RouteConfig} from 'angular2/src/router/route_config_decorator';
|
2015-04-17 12:59:56 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('RouteRegistry', () => {
|
2015-05-29 17:58:41 -04:00
|
|
|
var registry, rootHostComponent = new Object();
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
beforeEach(() => { registry = new RouteRegistry(); });
|
2015-04-17 12:59:56 -04:00
|
|
|
|
|
|
|
it('should match the full URL', () => {
|
2015-04-29 18:47:12 -04:00
|
|
|
registry.config(rootHostComponent, {'path': '/', 'component': DummyCompA});
|
|
|
|
registry.config(rootHostComponent, {'path': '/test', 'component': DummyCompB});
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-01 08:53:38 -04:00
|
|
|
var instruction = registry.recognize('/test', rootHostComponent);
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-14 16:01:48 -04:00
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompB);
|
2015-04-17 12:59:56 -04:00
|
|
|
});
|
|
|
|
|
2015-05-12 17:53:13 -04:00
|
|
|
it('should prefer static segments to dynamic', () => {
|
|
|
|
registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompB});
|
|
|
|
registry.config(rootHostComponent, {'path': '/home', 'component': DummyCompA});
|
|
|
|
|
|
|
|
var instruction = registry.recognize('/home', rootHostComponent);
|
|
|
|
|
2015-05-14 16:01:48 -04:00
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompA);
|
2015-05-12 17:53:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefer dynamic segments to star', () => {
|
|
|
|
registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompA});
|
|
|
|
registry.config(rootHostComponent, {'path': '/*site', 'component': DummyCompB});
|
|
|
|
|
|
|
|
var instruction = registry.recognize('/home', rootHostComponent);
|
|
|
|
|
2015-05-14 16:01:48 -04:00
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompA);
|
2015-05-12 17:53:13 -04:00
|
|
|
});
|
|
|
|
|
2015-05-15 05:05:57 -04:00
|
|
|
it('should prefer routes with more dynamic segments', () => {
|
|
|
|
registry.config(rootHostComponent, {'path': '/:first/*rest', 'component': DummyCompA});
|
|
|
|
registry.config(rootHostComponent, {'path': '/*all', 'component': DummyCompB});
|
|
|
|
|
|
|
|
var instruction = registry.recognize('/some/path', rootHostComponent);
|
|
|
|
|
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompA);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefer routes with more static segments', () => {
|
|
|
|
registry.config(rootHostComponent, {'path': '/first/:second', 'component': DummyCompA});
|
|
|
|
registry.config(rootHostComponent, {'path': '/:first/:second', 'component': DummyCompB});
|
|
|
|
|
|
|
|
var instruction = registry.recognize('/first/second', rootHostComponent);
|
|
|
|
|
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompA);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefer routes with static segments before dynamic segments', () => {
|
|
|
|
registry.config(rootHostComponent, {'path': '/first/second/:third', 'component': DummyCompB});
|
|
|
|
registry.config(rootHostComponent, {'path': '/first/:second/third', 'component': DummyCompA});
|
|
|
|
|
|
|
|
var instruction = registry.recognize('/first/second/third', rootHostComponent);
|
|
|
|
|
|
|
|
expect(instruction.getChild('default').component).toBe(DummyCompB);
|
|
|
|
});
|
|
|
|
|
2015-04-17 12:59:56 -04:00
|
|
|
it('should match the full URL recursively', () => {
|
2015-04-29 18:47:12 -04:00
|
|
|
registry.config(rootHostComponent, {'path': '/first', 'component': DummyParentComp});
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-01 08:53:38 -04:00
|
|
|
var instruction = registry.recognize('/first/second', rootHostComponent);
|
2015-04-17 12:59:56 -04:00
|
|
|
|
2015-05-14 16:01:48 -04:00
|
|
|
var parentInstruction = instruction.getChild('default');
|
|
|
|
var childInstruction = parentInstruction.getChild('default');
|
2015-04-29 18:47:12 -04:00
|
|
|
|
|
|
|
expect(parentInstruction.component).toBe(DummyParentComp);
|
|
|
|
expect(childInstruction.component).toBe(DummyCompB);
|
2015-04-17 12:59:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2015-04-29 18:47:12 -04:00
|
|
|
|
|
|
|
class DummyCompA {}
|
|
|
|
class DummyCompB {}
|
2015-05-29 17:58:41 -04:00
|
|
|
|
|
|
|
@RouteConfig([{'path': '/second', 'component': DummyCompB}])
|
|
|
|
class DummyParentComp {
|
|
|
|
}
|