| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   xit, | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-22 10:18:04 -07:00
										 |  |  | import {bootstrap} from 'angular2/bootstrap'; | 
					
						
							| 
									
										
										
										
											2015-09-03 22:01:36 -07:00
										 |  |  | import {Component, Directive, View} from 'angular2/src/core/metadata'; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:28:25 -07:00
										 |  |  | import {DOM} from 'angular2/src/core/dom/dom_adapter'; | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  | import {provide} from 'angular2/core'; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:28:25 -07:00
										 |  |  | import {DOCUMENT} from 'angular2/src/core/render/render'; | 
					
						
							|  |  |  | import {Type} from 'angular2/src/core/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |   ROUTER_PROVIDERS, | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |   Router, | 
					
						
							|  |  |  |   RouteConfig, | 
					
						
							| 
									
										
										
										
											2015-08-10 21:42:47 -07:00
										 |  |  |   APP_BASE_HREF, | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  |   ROUTER_DIRECTIVES | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | } from 'angular2/router'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 15:25:36 -07:00
										 |  |  | import {ExceptionHandler} from 'angular2/src/core/facade/exceptions'; | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | import {LocationStrategy} from 'angular2/src/router/location_strategy'; | 
					
						
							|  |  |  | import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | class _ArrayLogger { | 
					
						
							|  |  |  |   res: any[] = []; | 
					
						
							|  |  |  |   log(s: any): void { this.res.push(s); } | 
					
						
							| 
									
										
										
										
											2015-08-24 11:35:27 -07:00
										 |  |  |   logError(s: any): void { this.res.push(s); } | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |   logGroup(s: any): void { this.res.push(s); } | 
					
						
							|  |  |  |   logGroupEnd(){}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe('RouteConfig with POJO arguments', () => { | 
					
						
							|  |  |  |     var fakeDoc, el, testBindings; | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       fakeDoc = DOM.createHtmlDocument(); | 
					
						
							|  |  |  |       el = DOM.createElement('app-cmp', fakeDoc); | 
					
						
							|  |  |  |       DOM.appendChild(fakeDoc.body, el); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |       var logger = new _ArrayLogger(); | 
					
						
							|  |  |  |       var exceptionHandler = new ExceptionHandler(logger, true); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |       testBindings = [ | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |         ROUTER_PROVIDERS, | 
					
						
							| 
									
										
										
										
											2015-10-12 11:30:34 -07:00
										 |  |  |         provide(LocationStrategy, {useClass: MockLocationStrategy}), | 
					
						
							|  |  |  |         provide(DOCUMENT, {useValue: fakeDoc}), | 
					
						
							|  |  |  |         provide(ExceptionHandler, {useValue: exceptionHandler}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |       ]; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should bootstrap an app with a hierarchy', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |          bootstrap(HierarchyAppCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              .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(); | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |                router.navigateByUrl('/parent/child'); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-09-09 16:41:11 +02:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should work in an app with redirects', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |          bootstrap(RedirectAppCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              .then((applicationRef) => { | 
					
						
							|  |  |  |                var router = applicationRef.hostComponent.router; | 
					
						
							|  |  |  |                router.subscribe((_) => { | 
					
						
							|  |  |  |                  expect(el).toHaveText('root { hello }'); | 
					
						
							|  |  |  |                  expect(applicationRef.hostComponent.location.path()).toEqual('/after'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |                router.navigateByUrl('/before'); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-09-09 16:41:11 +02:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should work in an app with async components', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |          bootstrap(AsyncAppCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              .then((applicationRef) => { | 
					
						
							|  |  |  |                var router = applicationRef.hostComponent.router; | 
					
						
							|  |  |  |                router.subscribe((_) => { | 
					
						
							|  |  |  |                  expect(el).toHaveText('root { hello }'); | 
					
						
							|  |  |  |                  expect(applicationRef.hostComponent.location.path()).toEqual('/hello'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |                router.navigateByUrl('/hello'); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-09-09 16:41:11 +02:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 12:27:55 -07:00
										 |  |  |     it('should work in an app with async components defined with "loader"', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |          bootstrap(ConciseAsyncAppCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-10-08 12:27:55 -07:00
										 |  |  |              .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'); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |     it('should work in an app with a constructor component', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |          bootstrap(ExplicitConstructorAppCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              .then((applicationRef) => { | 
					
						
							|  |  |  |                var router = applicationRef.hostComponent.router; | 
					
						
							|  |  |  |                router.subscribe((_) => { | 
					
						
							|  |  |  |                  expect(el).toHaveText('root { hello }'); | 
					
						
							|  |  |  |                  expect(applicationRef.hostComponent.location.path()).toEqual('/hello'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |                router.navigateByUrl('/hello'); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-09-09 16:41:11 +02:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |     it('should throw if a config is missing a target', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [AsyncTestCompleter], | 
					
						
							|  |  |  |            (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |                bootstrap(WrongConfigCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |                    .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) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |                bootstrap(WrongComponentTypeCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |                    .catch((e) => { | 
					
						
							|  |  |  |                      expect(e.originalException) | 
					
						
							|  |  |  |                          .toContainError( | 
					
						
							|  |  |  |                              'Invalid component type "intentionallyWrongComponentType". Valid types are "constructor" and "loader".'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                      return null; | 
					
						
							|  |  |  |                    })})); | 
					
						
							| 
									
										
										
										
											2015-09-14 16:01:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should throw if a config has an invalid alias name', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [AsyncTestCompleter], | 
					
						
							|  |  |  |            (async) => { | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |                bootstrap(BadAliasCmp, testBindings) | 
					
						
							| 
									
										
										
										
											2015-09-14 16:01:09 -07:00
										 |  |  |                    .catch((e) => { | 
					
						
							|  |  |  |                      expect(e.originalException) | 
					
						
							|  |  |  |                          .toContainError( | 
					
						
							|  |  |  |                              `Route '/child' with alias 'child' does not begin with an uppercase letter. Route aliases should be CamelCase like 'Child'.`); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                      return null; | 
					
						
							|  |  |  |                    })})); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'hello-cmp'}) | 
					
						
							|  |  |  | @View({template: 'hello'}) | 
					
						
							|  |  |  | class HelloCmp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @RouteConfig([{path: '/before', redirectTo: '/after'}, {path: '/after', component: HelloCmp}]) | 
					
						
							|  |  |  | class RedirectAppCmp { | 
					
						
							|  |  |  |   constructor(public router: Router, public location: LocationStrategy) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function HelloLoader(): Promise<any> { | 
					
						
							|  |  |  |   return Promise.resolve(HelloCmp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @RouteConfig([ | 
					
						
							|  |  |  |   {path: '/hello', component: {type: 'loader', loader: HelloLoader}}, | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | class AsyncAppCmp { | 
					
						
							|  |  |  |   constructor(public router: Router, public location: LocationStrategy) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 12:27:55 -07:00
										 |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							|  |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							|  |  |  | @RouteConfig([ | 
					
						
							|  |  |  |   {path: '/hello', loader: HelloLoader}, | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | class ConciseAsyncAppCmp { | 
					
						
							|  |  |  |   constructor(public router: Router, public location: LocationStrategy) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @RouteConfig([ | 
					
						
							|  |  |  |   {path: '/hello', component: {type: 'constructor', constructor: HelloCmp}}, | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | class ExplicitConstructorAppCmp { | 
					
						
							|  |  |  |   constructor(public router: Router, public location: LocationStrategy) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'parent-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `parent { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @RouteConfig([{path: '/child', component: HelloCmp}]) | 
					
						
							|  |  |  | class ParentCmp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | @RouteConfig([{path: '/parent/...', component: ParentCmp}]) | 
					
						
							|  |  |  | class HierarchyAppCmp { | 
					
						
							|  |  |  |   constructor(public router: Router, public location: LocationStrategy) {} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | @RouteConfig([{path: '/hello'}]) | 
					
						
							|  |  |  | class WrongConfigCmp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 16:01:09 -07:00
										 |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							|  |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							|  |  |  | @RouteConfig([{path: '/child', component: HelloCmp, as: 'child'}]) | 
					
						
							|  |  |  | class BadAliasCmp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | @Component({selector: 'app-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-18 14:46:35 -07:00
										 |  |  | @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES}) | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | @RouteConfig([ | 
					
						
							|  |  |  |   {path: '/hello', component: {type: 'intentionallyWrongComponentType', constructor: HelloCmp}}, | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | class WrongComponentTypeCmp { | 
					
						
							|  |  |  | } |