refactor(router): clean up naming

This commit is contained in:
vsavkin
2016-07-06 16:19:52 -07:00
parent 8aa2a0c1b2
commit 37e6da6dfb
18 changed files with 326 additions and 89 deletions

View File

@ -2,7 +2,7 @@ import {Observable} from 'rxjs/Observable';
import {of } from 'rxjs/observable/of';
import {applyRedirects} from '../src/apply_redirects';
import {RouterConfig} from '../src/config';
import {Routes} from '../src/config';
import {LoadedRouterConfig} from '../src/router_config_loader';
import {DefaultUrlSerializer, UrlSegment, UrlTree, equalPathsWithParams} from '../src/url_tree';
@ -136,7 +136,7 @@ describe('applyRedirects', () => {
const loadedConfig =
new LoadedRouterConfig([{path: 'b', component: ComponentB}], <any>'stubFactoryResolver');
const loader = {load: (p: any) => of (loadedConfig)};
const config = [{path: 'a', component: ComponentA, mountChildren: 'children'}];
const config = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
applyRedirects(<any>loader, tree('a/b'), config).forEach(r => {
compareTrees(r, tree('/a/b'));
@ -148,7 +148,7 @@ describe('applyRedirects', () => {
const loader = {
load: (p: any) => new Observable<any>((obs: any) => obs.error(new Error('Loading Error')))
};
const config = [{path: 'a', component: ComponentA, mountChildren: 'children'}];
const config = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
applyRedirects(<any>loader, tree('a/b'), config).subscribe(() => {}, (e) => {
expect(e.message).toEqual('Loading Error');
@ -188,7 +188,7 @@ describe('applyRedirects', () => {
});
it('should redirect empty path route only when terminal', () => {
const config: RouterConfig = [
const config: Routes = [
{
path: 'a',
component: ComponentA,
@ -315,7 +315,7 @@ describe('applyRedirects', () => {
});
it('should not create a new child (terminal)', () => {
const config: RouterConfig = [{
const config: Routes = [{
path: 'a',
children: [
{path: 'b', component: ComponentB, children: [{path: 'd', component: ComponentB}]},
@ -338,7 +338,7 @@ describe('applyRedirects', () => {
});
});
function checkRedirect(config: RouterConfig, url: string, callback: any): void {
function checkRedirect(config: Routes, url: string, callback: any): void {
applyRedirects(null, tree(url), config).subscribe(callback, e => { throw e; });
}

View File

@ -15,16 +15,16 @@ describe('config', () => {
`Invalid configuration of route 'a': redirectTo and children cannot be used together`);
});
it('should throw when redirectTo and mountChildren are used together', () => {
expect(() => { validateConfig([{path: 'a', redirectTo: 'b', mountChildren: 'value'}]); })
it('should throw when redirectTo and loadChildren are used together', () => {
expect(() => { validateConfig([{path: 'a', redirectTo: 'b', loadChildren: 'value'}]); })
.toThrowError(
`Invalid configuration of route 'a': redirectTo and mountChildren cannot be used together`);
`Invalid configuration of route 'a': redirectTo and loadChildren cannot be used together`);
});
it('should throw when children and mountChildren are used together', () => {
expect(() => { validateConfig([{path: 'a', children: [], mountChildren: 'value'}]); })
it('should throw when children and loadChildren are used together', () => {
expect(() => { validateConfig([{path: 'a', children: [], loadChildren: 'value'}]); })
.toThrowError(
`Invalid configuration of route 'a': children and mountChildren cannot be used together`);
`Invalid configuration of route 'a': children and loadChildren cannot be used together`);
});
it('should throw when component and redirectTo are used together', () => {
@ -42,7 +42,7 @@ describe('config', () => {
it('should throw when none of component and children or direct are missing', () => {
expect(() => { validateConfig([{path: 'a'}]); })
.toThrowError(
`Invalid configuration of route 'a': component, redirectTo, children, mountChildren must be provided`);
`Invalid configuration of route 'a': component, redirectTo, children, loadChildren must be provided`);
});
it('should throw when path starts with a slash', () => {

View File

@ -1,4 +1,4 @@
import {RouterConfig} from '../src/config';
import {Routes} from '../src/config';
import {createRouterState} from '../src/create_router_state';
import {recognize} from '../src/recognize';
import {ActivatedRoute, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState} from '../src/router_state';
@ -84,7 +84,7 @@ function advanceNode(node: TreeNode<ActivatedRoute>): void {
node.children.forEach(advanceNode);
}
function createState(config: RouterConfig, url: string): RouterStateSnapshot {
function createState(config: Routes, url: string): RouterStateSnapshot {
let res: RouterStateSnapshot;
recognize(RootComponent, config, tree(url), url).forEach(s => res = s);
return res;

View File

@ -1,4 +1,4 @@
import {RouterConfig} from '../src/config';
import {Routes} from '../src/config';
import {recognize} from '../src/recognize';
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
import {PRIMARY_OUTLET, Params} from '../src/shared';
@ -529,7 +529,7 @@ describe('recognize', () => {
});
});
function checkRecognize(config: RouterConfig, url: string, callback: any): void {
function checkRecognize(config: Routes, url: string, callback: any): void {
recognize(RootComponent, config, tree(url), url).subscribe(callback, e => { throw e; });
}

View File

@ -1,4 +1,4 @@
import {RouterConfig} from '../src/config';
import {Routes} from '../src/config';
import {recognize} from '../src/recognize';
import {resolve} from '../src/resolve';
import {RouterStateSnapshot} from '../src/router_state';
@ -22,7 +22,7 @@ describe('resolve', () => {
});
function checkResolve(
config: RouterConfig, url: string, resolved: {[k: string]: string}, callback: any): void {
config: Routes, url: string, resolved: {[k: string]: string}, callback: any): void {
const resolver = {
resolveComponent: (component: string): Promise<any> => {
if (resolved[component]) {

View File

@ -11,13 +11,12 @@ import {expect} from '@angular/platform-browser/testing/matchers';
import {Observable} from 'rxjs/Observable';
import {of } from 'rxjs/observable/of';
import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, DefaultUrlSerializer, Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Params, ROUTER_DIRECTIVES, Resolve, Router, RouterConfig, RouterOutletMap, RouterStateSnapshot, RoutesRecognized, UrlSerializer, provideRoutes} from '../index';
import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, DefaultUrlSerializer, Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Params, ROUTER_DIRECTIVES, Resolve, Router, RouterOutletMap, RouterStateSnapshot, Routes, RoutesRecognized, UrlSerializer, provideRoutes} from '../index';
describe('Integration', () => {
beforeEachProviders(() => {
let config: RouterConfig =
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}];
let config: Routes = [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}];
return [
RouterOutletMap,
@ -1124,7 +1123,7 @@ describe('Integration', () => {
const fixture = createRoot(tcb, router, RootCmp);
router.resetConfig([{path: 'lazy', mountChildren: 'expected'}]);
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
router.navigateByUrl('/lazy/loaded/child');
advance(fixture);
@ -1142,7 +1141,7 @@ describe('Integration', () => {
(<any>loader).expectedPath = 'expected';
const fixture = createRoot(tcb, router, RootCmp);
router.resetConfig([{path: 'lazy', mountChildren: 'invalid'}]);
router.resetConfig([{path: 'lazy', loadChildren: 'invalid'}]);
const recordedEvents: any = [];
router.events.forEach(e => recordedEvents.push(e));