@@ -17,12 +17,11 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
1717import { bind } from 'angular2/di' ;
1818import { DOCUMENT_TOKEN } from 'angular2/src/render/dom/dom_renderer' ;
1919import { RouteConfig } from 'angular2/src/router/route_config_decorator' ;
20- import { routerInjectables , Router } from 'angular2/router' ;
21- import { RouterOutlet } from 'angular2/src/router/router_outlet' ;
22- import { SpyLocation } from 'angular2/src/mock/location_mock' ;
23- import { Location } from 'angular2/src/router/location' ;
2420import { PromiseWrapper } from 'angular2/src/facade/async' ;
2521import { BaseException } from 'angular2/src/facade/lang' ;
22+ import { routerInjectables , Router , appBaseHrefToken , routerDirectives } from 'angular2/router' ;
23+ import { BrowserLocation } from 'angular2/src/router/browser_location' ;
24+ import { DummyBrowserLocation } from 'angular2/src/mock/browser_location_mock' ;
2625
2726export function main ( ) {
2827 describe ( 'router injectables' , ( ) => {
@@ -33,17 +32,23 @@ export function main() {
3332 DOM . appendChild ( fakeDoc . body , el ) ;
3433 testBindings = [
3534 routerInjectables ,
36- bind ( Location ) . toClass ( SpyLocation ) ,
35+ bind ( BrowserLocation )
36+ . toFactory ( ( ) => {
37+ var browserLocation = new DummyBrowserLocation ( ) ;
38+ browserLocation . spy ( 'pushState' ) ;
39+ return browserLocation ;
40+ } ) ,
3741 bind ( DOCUMENT_TOKEN ) . toValue ( fakeDoc )
3842 ] ;
3943 } ) ;
4044
41- it ( 'should support bootstrap a simple app' , inject ( [ AsyncTestCompleter ] , ( async ) => {
45+ it ( 'should bootstrap a simple app' , inject ( [ AsyncTestCompleter ] , ( async ) => {
4246 bootstrap ( AppCmp , testBindings )
4347 . then ( ( applicationRef ) => {
4448 var router = applicationRef . hostComponent . router ;
4549 router . subscribe ( ( _ ) => {
4650 expect ( el ) . toHaveText ( 'outer { hello }' ) ;
51+ expect ( applicationRef . hostComponent . location . path ( ) ) . toEqual ( '/' ) ;
4752 async . done ( ) ;
4853 } ) ;
4954 } ) ;
@@ -62,22 +67,64 @@ export function main() {
6267 } ) ;
6368 } ) ) ;
6469
70+ it ( 'should bootstrap an app with a hierarchy' , inject ( [ AsyncTestCompleter ] , ( async ) => {
71+ bootstrap ( HierarchyAppCmp , testBindings )
72+ . then ( ( applicationRef ) => {
73+ var router = applicationRef . hostComponent . router ;
74+ router . subscribe ( ( _ ) => {
75+ expect ( el ) . toHaveText ( 'root { parent { hello } }' ) ;
76+ expect ( applicationRef . hostComponent . location . path ( ) ) . toEqual ( '/parent/child' ) ;
77+ async . done ( ) ;
78+ } ) ;
79+ router . navigate ( '/parent/child' ) ;
80+ } ) ;
81+ } ) ) ;
82+
83+ it ( 'should bootstrap an app with a custom app base href' ,
84+ inject ( [ AsyncTestCompleter ] , ( async ) => {
85+ bootstrap ( HierarchyAppCmp , [ testBindings , bind ( appBaseHrefToken ) . toValue ( '/my/app' ) ] )
86+ . then ( ( applicationRef ) => {
87+ var router = applicationRef . hostComponent . router ;
88+ router . subscribe ( ( _ ) => {
89+ expect ( el ) . toHaveText ( 'root { parent { hello } }' ) ;
90+ expect ( applicationRef . hostComponent . location . path ( ) )
91+ . toEqual ( '/my/app/parent/child' ) ;
92+ async . done ( ) ;
93+ } ) ;
94+ router . navigate ( '/parent/child' ) ;
95+ } ) ;
96+ } ) ) ;
97+
6598 // TODO: add a test in which the child component has bindings
6699 } ) ;
67100}
68101
69102
70103@Component ( { selector : 'hello-cmp' } )
71- @View ( { template : " hello" } )
104+ @View ( { template : ' hello' } )
72105class HelloCmp {
73106}
74107
75108@Component ( { selector : 'app-cmp' } )
76- @View ( { template : "outer { <router-outlet></router-outlet> }" , directives : [ RouterOutlet ] } )
109+ @View ( { template : "outer { <router-outlet></router-outlet> }" , directives : routerDirectives } )
77110@RouteConfig ( [ { path : '/' , component : HelloCmp } ] )
78111class AppCmp {
79- router : Router ;
80- constructor ( router : Router ) { this . router = router ; }
112+ constructor ( public router : Router , public location : BrowserLocation ) { }
113+ }
114+
115+
116+ @Component ( { selector : 'parent-cmp' } )
117+ @View ( { template : `parent { <router-outlet></router-outlet> }` , directives : routerDirectives } )
118+ @RouteConfig ( [ { path : '/child' , component : HelloCmp } ] )
119+ class ParentCmp {
120+ }
121+
122+
123+ @Component ( { selector : 'app-cmp' } )
124+ @View ( { template : `root { <router-outlet></router-outlet> }` , directives : routerDirectives } )
125+ @RouteConfig ( [ { path : '/parent' , component : ParentCmp } ] )
126+ class HierarchyAppCmp {
127+ constructor ( public router : Router , public location : BrowserLocation ) { }
81128}
82129
83130@Component ( { selector : 'oops-cmp' } )
@@ -87,9 +134,8 @@ class BrokenCmp {
87134}
88135
89136@Component ( { selector : 'app-cmp' } )
90- @View ( { template : "outer { <router-outlet></router-outlet> }" , directives : [ RouterOutlet ] } )
137+ @View ( { template : "outer { <router-outlet></router-outlet> }" , directives : routerDirectives } )
91138@RouteConfig ( [ { path : '/cause-error' , component : BrokenCmp } ] )
92139class BrokenAppCmp {
93- router : Router ;
94- constructor ( router : Router ) { this . router = router ; }
140+ constructor ( public router : Router , public location : BrowserLocation ) { }
95141}
0 commit comments