refactor(router): rename navigate and navigateInstruction methods

This commit is contained in:
Brian Ford
2015-09-08 21:41:56 -07:00
parent 5e49d7e624
commit acc2722cb8
17 changed files with 126 additions and 125 deletions

View File

@ -91,7 +91,7 @@ export function main() {
it('should call the onActivate hook', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-activate'))
.then((_) => rtr.navigateByUrl('/on-activate'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('activate cmp');
@ -110,7 +110,7 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigate('/parent-activate/child-activate')
rtr.navigateByUrl('/parent-activate/child-activate')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('parent {activate cmp}');
@ -126,8 +126,8 @@ export function main() {
it('should call the onDeactivate hook', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-deactivate'))
.then((_) => rtr.navigate('/a'))
.then((_) => rtr.navigateByUrl('/on-deactivate'))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
@ -140,7 +140,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/parent-deactivate/child-deactivate'))
.then((_) => rtr.navigateByUrl('/parent-deactivate/child-deactivate'))
.then((_) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('deactivate')) {
@ -149,7 +149,7 @@ export function main() {
expect(rootTC.nativeElement).toHaveText('parent {deactivate cmp}');
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
expect(log).toEqual([
@ -165,14 +165,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-reuse/1/a'))
.then((_) => rtr.navigateByUrl('/on-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigate('/on-reuse/2/b'))
.then((_) => rtr.navigateByUrl('/on-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual(['reuse: /on-reuse/1 -> /on-reuse/2']);
@ -187,14 +187,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/never-reuse/1/a'))
.then((_) => rtr.navigateByUrl('/never-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigate('/never-reuse/2/b'))
.then((_) => rtr.navigateByUrl('/never-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
@ -214,7 +214,7 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigate('/can-activate/a')
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canActivate {A}');
@ -234,7 +234,7 @@ export function main() {
completer.resolve(false);
}
});
rtr.navigate('/can-activate/a')
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('');
@ -248,7 +248,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/can-deactivate/a'))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
@ -260,7 +260,7 @@ export function main() {
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
@ -273,7 +273,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/can-deactivate/a'))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
@ -285,7 +285,7 @@ export function main() {
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
@ -299,7 +299,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/activation-hooks/child'))
.then((_) => rtr.navigateByUrl('/activation-hooks/child'))
.then((_) => {
expect(log).toEqual([
'canActivate child: null -> /child',
@ -309,7 +309,7 @@ export function main() {
]);
log = [];
return rtr.navigate('/a');
return rtr.navigateByUrl('/a');
})
.then((_) => {
expect(log).toEqual([
@ -325,7 +325,7 @@ export function main() {
it('should only run reuse hooks when reusing', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/reuse-hooks/1'))
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
.then((_) => {
expect(log).toEqual(
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
@ -338,7 +338,7 @@ export function main() {
log = [];
return rtr.navigate('/reuse-hooks/2');
return rtr.navigateByUrl('/reuse-hooks/2');
})
.then((_) => {
expect(log).toEqual([
@ -352,7 +352,7 @@ export function main() {
it('should not run reuse hooks when not reusing', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/reuse-hooks/1'))
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
.then((_) => {
expect(log).toEqual(
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
@ -364,7 +364,7 @@ export function main() {
});
log = [];
return rtr.navigate('/reuse-hooks/2');
return rtr.navigateByUrl('/reuse-hooks/2');
})
.then((_) => {
expect(log).toEqual([

View File

@ -75,7 +75,7 @@ export function main() {
it('should work in a simple case', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/test', component: HelloCmp})]))
.then((_) => rtr.navigate('/test'))
.then((_) => rtr.navigateByUrl('/test'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello');
@ -88,12 +88,12 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/user/:name', component: UserCmp})]))
.then((_) => rtr.navigate('/user/brian'))
.then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello brian');
})
.then((_) => rtr.navigate('/user/igor'))
.then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello igor');
@ -105,7 +105,7 @@ export function main() {
it('should navigate to child routes', inject([AsyncTestCompleter], (async) => {
compile('outer { <router-outlet></router-outlet> }')
.then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
.then((_) => rtr.navigate('/a/b'))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }');
@ -117,7 +117,7 @@ export function main() {
it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => {
compile('outer { <router-outlet></router-outlet> }')
.then((_) => rtr.config([new AsyncRoute({path: '/a/...', loader: parentLoader})]))
.then((_) => rtr.navigate('/a/b'))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }');
@ -133,7 +133,7 @@ export function main() {
new Redirect({path: '/original', redirectTo: '/redirected'}),
new Route({path: '/redirected', component: HelloCmp})
]))
.then((_) => rtr.navigate('/original'))
.then((_) => rtr.navigateByUrl('/original'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello');
@ -146,13 +146,13 @@ export function main() {
it('should reuse common parent components', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigate('/team/angular/user/rado'))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigate('/team/angular/user/victor'))
.then((_) => rtr.navigateByUrl('/team/angular/user/victor'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
@ -165,14 +165,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigate('/team/angular/user/rado'))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(childCmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigate('/team/dart/user/rado'))
.then((_) => rtr.navigateByUrl('/team/dart/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(2);
@ -187,7 +187,7 @@ export function main() {
.then((_) => rtr.config([
new Route({path: '/route-data', component: RouteDataCmp, data: {'isAdmin': true}})
]))
.then((_) => rtr.navigate('/route-data'))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true}));
@ -202,7 +202,7 @@ export function main() {
new AsyncRoute(
{path: '/route-data', loader: AsyncRouteDataCmp, data: {isAdmin: true}})
]))
.then((_) => rtr.navigate('/route-data'))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true}));
@ -215,7 +215,7 @@ export function main() {
compile()
.then((_) => rtr.config(
[new Route({path: '/route-data-default', component: RouteDataCmp})]))
.then((_) => rtr.navigate('/route-data-default'))
.then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('null');
@ -228,7 +228,7 @@ export function main() {
.then((_) => rtr.config([
new Route({path: '/route-data-array', component: RouteDataCmp, data: [1, 2, 3]})
]))
.then((_) => rtr.navigate('/route-data-array'))
.then((_) => rtr.navigateByUrl('/route-data-array'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify([1, 2, 3]));
@ -242,7 +242,7 @@ export function main() {
new Route(
{path: '/route-data-string', component: RouteDataCmp, data: 'hello world'})
]))
.then((_) => rtr.navigate('/route-data-string'))
.then((_) => rtr.navigateByUrl('/route-data-string'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify('hello world'));
@ -254,7 +254,7 @@ export function main() {
it('should recognize a simple case', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: AuxCmp})]))
.then((_) => rtr.navigate('/hello(modal)'))
.then((_) => rtr.navigateByUrl('/hello(modal)'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('main {hello} | aux {modal}');

View File

@ -72,7 +72,7 @@ export function main() {
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.componentInstance.router;
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!');
async.done();
@ -123,11 +123,11 @@ export function main() {
if (flipped) {
location.back();
} else {
router.navigate(nextUrl);
router.navigateByUrl(nextUrl);
}
});
router.navigate(history[0][0]);
router.navigateByUrl(history[0][0]);
});
}), 1000);
});
@ -146,7 +146,7 @@ export function main() {
expect(rootTC.componentInstance.location.path()).toEqual('/parent/child');
async.done();
});
router.navigate('/parent/child');
router.navigateByUrl('/parent/child');
});
}), 1000);
@ -165,7 +165,7 @@ export function main() {
.toEqual('/my/app/parent/child');
async.done();
});
router.navigate('/parent/child');
router.navigateByUrl('/parent/child');
});
}),
1000);
@ -190,7 +190,7 @@ export function main() {
.toEqual('/qs?q=search-for-something');*/
async.done();
});
router.navigate('/qs?q=search-for-something');
router.navigateByUrl('/qs?q=search-for-something');
rootTC.detectChanges();
});
}), 1000);

View File

@ -76,7 +76,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/my/base/user');
@ -89,7 +89,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/user');
@ -102,7 +102,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\', {name: name}]">{{name}}</a>')
.then((_) => router.config(
[new Route({path: '/user/:name', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.componentInstance.name = 'brian';
rootTC.detectChanges();
@ -118,7 +118,7 @@ export function main() {
compile()
.then((_) => router.config(
[new Route({path: '/page/:number', component: SiblingPageCmp, as: 'page'})]))
.then((_) => router.navigate('/page/1'))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(
@ -159,7 +159,7 @@ export function main() {
compile()
.then((_) => router.config(
[new Route({path: '/book/:title/...', component: BookCmp, as: 'book'})]))
.then((_) => router.navigate('/book/1984/page/1'))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(
@ -206,7 +206,7 @@ export function main() {
async.done();
});
router.navigate('/better-child');
router.navigateByUrl('/better-child');
});
}));
@ -247,7 +247,7 @@ export function main() {
async.done();
});
router.navigate('/child-with-grandchild/grandchild');
router.navigateByUrl('/child-with-grandchild/grandchild');
});
}));
});
@ -265,7 +265,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
@ -286,7 +286,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();