2015-08-20 14:28:25 -07:00
|
|
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
|
2015-08-28 11:29:19 -07:00
|
|
|
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
2015-04-21 11:23:23 -07:00
|
|
|
import {Location} from 'angular2/src/router/location';
|
|
|
|
|
2015-08-26 11:41:41 -07:00
|
|
|
export class SpyLocation implements Location {
|
2015-08-28 11:29:19 -07:00
|
|
|
urlChanges: string[] = [];
|
2015-10-09 17:21:25 -07:00
|
|
|
/** @internal */
|
2015-08-26 11:41:41 -07:00
|
|
|
_path: string = '';
|
2015-10-09 17:21:25 -07:00
|
|
|
/** @internal */
|
2015-09-23 00:10:26 -07:00
|
|
|
_query: string = '';
|
|
|
|
/** @internal */
|
2015-08-26 11:41:41 -07:00
|
|
|
_subject: EventEmitter = new EventEmitter();
|
2015-10-09 17:21:25 -07:00
|
|
|
/** @internal */
|
2015-08-26 11:41:41 -07:00
|
|
|
_baseHref: string = '';
|
2015-04-21 11:23:23 -07:00
|
|
|
|
2015-05-29 14:58:41 -07:00
|
|
|
setInitialPath(url: string) { this._path = url; }
|
2015-04-21 11:23:23 -07:00
|
|
|
|
2015-05-29 14:58:41 -07:00
|
|
|
setBaseHref(url: string) { this._baseHref = url; }
|
2015-05-12 16:18:58 -07:00
|
|
|
|
2015-05-29 14:58:41 -07:00
|
|
|
path(): string { return this._path; }
|
2015-04-21 11:23:23 -07:00
|
|
|
|
2015-05-29 14:58:41 -07:00
|
|
|
simulateUrlPop(pathname: string) { ObservableWrapper.callNext(this._subject, {'url': pathname}); }
|
2015-04-21 11:23:23 -07:00
|
|
|
|
2015-07-07 20:03:00 -07:00
|
|
|
normalizeAbsolutely(url: string): string { return this._baseHref + url; }
|
2015-05-12 16:18:58 -07:00
|
|
|
|
2015-09-23 00:10:26 -07:00
|
|
|
go(path: string, query: string = '') {
|
|
|
|
path = this.normalizeAbsolutely(path);
|
|
|
|
if (this._path == path && this._query == query) {
|
2015-04-21 11:23:23 -07:00
|
|
|
return;
|
|
|
|
}
|
2015-09-23 00:10:26 -07:00
|
|
|
this._path = path;
|
|
|
|
this._query = query;
|
|
|
|
|
|
|
|
var url = path + (query.length > 0 ? ('?' + query) : '');
|
2015-06-17 11:17:21 -07:00
|
|
|
this.urlChanges.push(url);
|
2015-04-21 11:23:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
forward() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
back() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:03:00 -07:00
|
|
|
subscribe(onNext: (value: any) => void, onThrow: (error: any) => void = null,
|
|
|
|
onReturn: () => void = null) {
|
2015-04-21 11:23:23 -07:00
|
|
|
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
|
|
|
|
}
|
|
|
|
|
2015-08-26 11:41:41 -07:00
|
|
|
// TODO: remove these once Location is an interface, and can be implemented cleanly
|
|
|
|
platformStrategy: any = null;
|
|
|
|
normalize(url: string): string { return null; }
|
2015-04-21 11:23:23 -07:00
|
|
|
}
|