| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   proxy, | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   SpyObject | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | import {IMPLEMENTS} from 'angular2/src/facade/lang'; | 
					
						
							|  |  |  | import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {BrowserLocation} from 'angular2/src/router/browser_location'; | 
					
						
							|  |  |  | import {Location} from 'angular2/src/router/location'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('Location', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var browserLocation, location; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       browserLocation = new DummyBrowserLocation(); | 
					
						
							|  |  |  |       browserLocation.spy('pushState'); | 
					
						
							|  |  |  |       browserLocation.baseHref = '/my/app'; | 
					
						
							|  |  |  |       location = new Location(browserLocation); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 14:49:55 -07:00
										 |  |  |     it('should normalize relative urls on navigate', () => { | 
					
						
							|  |  |  |       location.go('user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |       expect(browserLocation.spy('pushState')) | 
					
						
							|  |  |  |           .toHaveBeenCalledWith(null, '', '/my/app/user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-11 14:49:55 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not append urls with leading slash on navigate', () => { | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  |       location.go('/my/app/user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |       expect(browserLocation.spy('pushState')) | 
					
						
							|  |  |  |           .toHaveBeenCalledWith(null, '', '/my/app/user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should remove index.html from base href', () => { | 
					
						
							|  |  |  |       browserLocation.baseHref = '/my/app/index.html'; | 
					
						
							|  |  |  |       location = new Location(browserLocation); | 
					
						
							| 
									
										
										
										
											2015-05-11 14:49:55 -07:00
										 |  |  |       location.go('user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |       expect(browserLocation.spy('pushState')) | 
					
						
							|  |  |  |           .toHaveBeenCalledWith(null, '', '/my/app/user/btford'); | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |          browserLocation.simulatePopState('/my/app/user/btford'); | 
					
						
							|  |  |  |          location.subscribe((ev) => { | 
					
						
							|  |  |  |            expect(ev['url']).toEqual('/user/btford'); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }) | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should normalize location path', () => { | 
					
						
							|  |  |  |       browserLocation.internalPath = '/my/app/user/btford'; | 
					
						
							|  |  |  |       expect(location.path()).toEqual('/user/btford'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @proxy | 
					
						
							|  |  |  | @IMPLEMENTS(BrowserLocation) | 
					
						
							|  |  |  | class DummyBrowserLocation extends SpyObject { | 
					
						
							|  |  |  |   baseHref; | 
					
						
							|  |  |  |   internalPath; | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   _subject: EventEmitter; | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |     this.internalPath = '/'; | 
					
						
							|  |  |  |     this._subject = new EventEmitter(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   simulatePopState(url) { | 
					
						
							|  |  |  |     this.internalPath = url; | 
					
						
							|  |  |  |     ObservableWrapper.callNext(this._subject, null); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   path() { return this.internalPath; } | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   onPopState(fn) { ObservableWrapper.subscribe(this._subject, fn); } | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   getBaseHref() { return this.baseHref; } | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  |   noSuchMethod(m) { return super.noSuchMethod(m); } | 
					
						
							| 
									
										
										
										
											2015-05-06 18:28:24 -07:00
										 |  |  | } |