@@ -27,7 +27,8 @@ import {
27
27
RouteParams ,
28
28
Router ,
29
29
appBaseHrefToken ,
30
- routerDirectives
30
+ routerDirectives ,
31
+ HashLocationStrategy
31
32
} from 'angular2/router' ;
32
33
33
34
import { LocationStrategy } from 'angular2/src/router/location_strategy' ;
@@ -81,6 +82,57 @@ export function main() {
81
82
} ) ) ;
82
83
} ) ;
83
84
85
+ describe ( 'back button app' , ( ) => {
86
+ beforeEachBindings ( ( ) => { return [ bind ( appComponentTypeToken ) . toValue ( HierarchyAppCmp ) ] ; } ) ;
87
+
88
+ it ( 'should change the url without pushing a new history state for back navigations' ,
89
+ inject ( [ AsyncTestCompleter , TestComponentBuilder ] , ( async , tcb : TestComponentBuilder ) => {
90
+
91
+ tcb . createAsync ( HierarchyAppCmp )
92
+ . then ( ( rootTC ) => {
93
+ var router = rootTC . componentInstance . router ;
94
+ var position = 0 ;
95
+ var flipped = false ;
96
+ var history =
97
+ [
98
+ [ '/parent/child' , 'root { parent { hello } }' , '/super-parent/child' ] ,
99
+ [ '/super-parent/child' , 'root { super-parent { hello2 } }' , '/parent/child' ] ,
100
+ [ '/parent/child' , 'root { parent { hello } }' , false ]
101
+ ]
102
+
103
+ router . subscribe ( ( _ ) => {
104
+ var location = rootTC . componentInstance . location ;
105
+ var element = rootTC . nativeElement ;
106
+ var path = location . path ( ) ;
107
+
108
+ var entry = history [ position ] ;
109
+
110
+ expect ( path ) . toEqual ( entry [ 0 ] ) ;
111
+ expect ( element ) . toHaveText ( entry [ 1 ] ) ;
112
+
113
+ var nextUrl = entry [ 2 ] ;
114
+ if ( nextUrl == false ) {
115
+ flipped = true ;
116
+ }
117
+
118
+ if ( flipped && position == 0 ) {
119
+ async . done ( ) ;
120
+ return ;
121
+ }
122
+
123
+ position = position + ( flipped ? - 1 : 1 ) ;
124
+ if ( flipped ) {
125
+ location . back ( ) ;
126
+ } else {
127
+ router . navigate ( nextUrl ) ;
128
+ }
129
+ } ) ;
130
+
131
+ router . navigate ( history [ 0 ] [ 0 ] ) ;
132
+ } ) ;
133
+ } ) ) ;
134
+ } ) ;
135
+
84
136
describe ( 'hierarchical app' , ( ) => {
85
137
beforeEachBindings ( ( ) => { return [ bind ( appComponentTypeToken ) . toValue ( HierarchyAppCmp ) ] ; } ) ;
86
138
@@ -153,6 +205,11 @@ export function main() {
153
205
class HelloCmp {
154
206
}
155
207
208
+ @Component ( { selector : 'hello2-cmp' } )
209
+ @View ( { template : 'hello2' } )
210
+ class Hello2Cmp {
211
+ }
212
+
156
213
@Component ( { selector : 'app-cmp' } )
157
214
@View ( { template : "outer { <router-outlet></router-outlet> }" , directives : routerDirectives } )
158
215
@RouteConfig ( [ new Route ( { path : '/' , component : HelloCmp } ) ] )
@@ -166,9 +223,18 @@ class AppCmp {
166
223
class ParentCmp {
167
224
}
168
225
226
+ @Component ( { selector : 'super-parent-cmp' } )
227
+ @View ( { template : `super-parent { <router-outlet></router-outlet> }` , directives : routerDirectives } )
228
+ @RouteConfig ( [ new Route ( { path : '/child' , component : Hello2Cmp } ) ] )
229
+ class SuperParentCmp {
230
+ }
231
+
169
232
@Component ( { selector : 'app-cmp' } )
170
233
@View ( { template : `root { <router-outlet></router-outlet> }` , directives : routerDirectives } )
171
- @RouteConfig ( [ new Route ( { path : '/parent/...' , component : ParentCmp } ) ] )
234
+ @RouteConfig ( [
235
+ new Route ( { path : '/parent/...' , component : ParentCmp } ) ,
236
+ new Route ( { path : '/super-parent/...' , component : SuperParentCmp } )
237
+ ] )
172
238
class HierarchyAppCmp {
173
239
constructor ( public router : Router , public location : LocationStrategy ) { }
174
240
}
0 commit comments