2015-08-20 17:28:25 -04:00
|
|
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
|
|
|
|
import {List} from 'angular2/src/core/facade/collection';
|
2015-06-22 15:14:19 -04:00
|
|
|
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
2015-06-15 18:41:09 -04:00
|
|
|
|
2015-06-22 15:14:19 -04:00
|
|
|
|
|
|
|
export class MockLocationStrategy extends LocationStrategy {
|
2015-06-15 18:41:09 -04:00
|
|
|
internalBaseHref: string = '/';
|
|
|
|
internalPath: string = '/';
|
|
|
|
internalTitle: string = '';
|
2015-06-17 14:17:21 -04:00
|
|
|
urlChanges: List<string> = [];
|
2015-06-15 18:41:09 -04:00
|
|
|
_subject: EventEmitter = new EventEmitter();
|
|
|
|
constructor() { super(); }
|
|
|
|
|
2015-07-07 23:03:00 -04:00
|
|
|
simulatePopState(url: string): void {
|
2015-06-15 18:41:09 -04:00
|
|
|
this.internalPath = url;
|
|
|
|
ObservableWrapper.callNext(this._subject, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
path(): string { return this.internalPath; }
|
|
|
|
|
|
|
|
simulateUrlPop(pathname: string): void {
|
|
|
|
ObservableWrapper.callNext(this._subject, {'url': pathname});
|
|
|
|
}
|
|
|
|
|
|
|
|
pushState(ctx: any, title: string, url: string): void {
|
|
|
|
this.internalTitle = title;
|
|
|
|
this.internalPath = url;
|
2015-06-17 14:17:21 -04:00
|
|
|
this.urlChanges.push(url);
|
2015-06-15 18:41:09 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 23:03:00 -04:00
|
|
|
onPopState(fn: (value: any) => void): void { ObservableWrapper.subscribe(this._subject, fn); }
|
2015-06-15 18:41:09 -04:00
|
|
|
|
|
|
|
getBaseHref(): string { return this.internalBaseHref; }
|
2015-07-28 23:19:56 -04:00
|
|
|
|
|
|
|
back(): void {
|
|
|
|
if (this.urlChanges.length > 0) {
|
|
|
|
this.urlChanges.pop();
|
|
|
|
var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
|
|
|
|
this.simulatePopState(nextUrl);
|
|
|
|
}
|
|
|
|
}
|
2015-06-15 18:41:09 -04:00
|
|
|
}
|