2018-03-20 18:22:59 +02:00
|
|
|
import { BehaviorSubject } from 'rxjs';
|
2018-03-21 03:40:23 +02:00
|
|
|
import { map } from 'rxjs/operators';
|
2017-03-06 14:08:38 +00:00
|
|
|
|
|
|
|
export class MockLocationService {
|
|
|
|
urlSubject = new BehaviorSubject<string>(this.initialUrl);
|
2018-03-21 03:40:23 +02:00
|
|
|
currentUrl = this.urlSubject.asObservable().pipe(map(url => this.stripSlashes(url)));
|
2017-04-24 14:34:31 -07:00
|
|
|
// strip off query and hash
|
2021-04-03 09:52:53 -04:00
|
|
|
currentPath = this.currentUrl.pipe(map(url => url.match(/[^?#]*/)?.[0] || ''));
|
2017-03-13 19:58:31 +00:00
|
|
|
search = jasmine.createSpy('search').and.returnValue({});
|
|
|
|
setSearch = jasmine.createSpy('setSearch');
|
2020-11-11 19:49:58 +02:00
|
|
|
fullPageNavigationNeeded = jasmine.createSpy('Location.fullPageNavigationNeeded');
|
2017-04-11 16:08:53 -07:00
|
|
|
go = jasmine.createSpy('Location.go').and
|
|
|
|
.callFake((url: string) => this.urlSubject.next(url));
|
2017-04-25 14:48:01 -07:00
|
|
|
goExternal = jasmine.createSpy('Location.goExternal');
|
2017-07-26 18:30:38 +01:00
|
|
|
replace = jasmine.createSpy('Location.replace');
|
2020-11-12 17:43:51 +02:00
|
|
|
reloadPage = jasmine.createSpy('Location.reloadPage');
|
2017-03-13 21:06:15 +00:00
|
|
|
handleAnchorClick = jasmine.createSpy('Location.handleAnchorClick')
|
|
|
|
.and.returnValue(false); // prevent click from causing a browser navigation
|
2017-04-11 16:08:53 -07:00
|
|
|
|
2018-01-10 10:41:15 +00:00
|
|
|
constructor(private initialUrl: string) {}
|
2017-04-24 14:34:31 -07:00
|
|
|
|
|
|
|
private stripSlashes(url: string) {
|
|
|
|
return url.replace(/^\/+/, '').replace(/\/+(\?|#|$)/, '$1');
|
|
|
|
}
|
2017-03-06 14:08:38 +00:00
|
|
|
}
|