2015-04-21 14:23:23 -04:00
|
|
|
import {SpyObject, proxy} from 'angular2/test_lib';
|
|
|
|
|
2015-05-08 09:15:41 -04:00
|
|
|
import {IMPLEMENTS} from 'angular2/src/facade/lang';
|
2015-04-21 14:23:23 -04:00
|
|
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
import {Location} from 'angular2/src/router/location';
|
|
|
|
|
|
|
|
|
|
|
|
@proxy
|
|
|
|
@IMPLEMENTS(Location)
|
2015-05-01 18:43:54 -04:00
|
|
|
export class SpyLocation extends SpyObject {
|
2015-05-29 17:58:41 -04:00
|
|
|
urlChanges: List<string>;
|
|
|
|
_path: string;
|
|
|
|
_subject: EventEmitter;
|
|
|
|
_baseHref: string;
|
2015-04-21 14:23:23 -04:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2015-06-17 14:57:38 -04:00
|
|
|
this._path = '';
|
2015-06-17 14:17:21 -04:00
|
|
|
this.urlChanges = [];
|
2015-04-21 14:23:23 -04:00
|
|
|
this._subject = new EventEmitter();
|
2015-05-12 19:18:58 -04:00
|
|
|
this._baseHref = '';
|
2015-04-21 14:23:23 -04:00
|
|
|
}
|
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
setInitialPath(url: string) { this._path = url; }
|
2015-04-21 14:23:23 -04:00
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
setBaseHref(url: string) { this._baseHref = url; }
|
2015-05-12 19:18:58 -04:00
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
path(): string { return this._path; }
|
2015-04-21 14:23:23 -04:00
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
simulateUrlPop(pathname: string) { ObservableWrapper.callNext(this._subject, {'url': pathname}); }
|
2015-04-21 14:23:23 -04:00
|
|
|
|
2015-06-26 14:10:52 -04:00
|
|
|
normalizeAbsolutely(url): string { return this._baseHref + url; }
|
2015-05-12 19:18:58 -04:00
|
|
|
|
2015-05-29 17:58:41 -04:00
|
|
|
go(url: string) {
|
2015-05-20 02:14:10 -04:00
|
|
|
url = this.normalizeAbsolutely(url);
|
|
|
|
if (this._path == url) {
|
2015-04-21 14:23:23 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._path = url;
|
2015-06-17 14:17:21 -04:00
|
|
|
this.urlChanges.push(url);
|
2015-04-21 14:23:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
forward() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
back() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribe(onNext, onThrow = null, onReturn = null) {
|
|
|
|
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
|
|
|
|
}
|
|
|
|
|
2015-06-26 14:10:52 -04:00
|
|
|
noSuchMethod(m) { super.noSuchMethod(m); }
|
2015-04-21 14:23:23 -04:00
|
|
|
}
|