1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { EventEmitter, Injectable } from '@angular/core';
|
---|
9 | /**
|
---|
10 | * A spy for {@link Location} that allows tests to fire simulated location events.
|
---|
11 | *
|
---|
12 | * @publicApi
|
---|
13 | */
|
---|
14 | export class SpyLocation {
|
---|
15 | constructor() {
|
---|
16 | this.urlChanges = [];
|
---|
17 | this._history = [new LocationState('', '', null)];
|
---|
18 | this._historyIndex = 0;
|
---|
19 | /** @internal */
|
---|
20 | this._subject = new EventEmitter();
|
---|
21 | /** @internal */
|
---|
22 | this._baseHref = '';
|
---|
23 | /** @internal */
|
---|
24 | this._platformStrategy = null;
|
---|
25 | /** @internal */
|
---|
26 | this._platformLocation = null;
|
---|
27 | /** @internal */
|
---|
28 | this._urlChangeListeners = [];
|
---|
29 | }
|
---|
30 | setInitialPath(url) {
|
---|
31 | this._history[this._historyIndex].path = url;
|
---|
32 | }
|
---|
33 | setBaseHref(url) {
|
---|
34 | this._baseHref = url;
|
---|
35 | }
|
---|
36 | path() {
|
---|
37 | return this._history[this._historyIndex].path;
|
---|
38 | }
|
---|
39 | getState() {
|
---|
40 | return this._history[this._historyIndex].state;
|
---|
41 | }
|
---|
42 | isCurrentPathEqualTo(path, query = '') {
|
---|
43 | const givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
|
---|
44 | const currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
|
---|
45 | return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
|
---|
46 | }
|
---|
47 | simulateUrlPop(pathname) {
|
---|
48 | this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'popstate' });
|
---|
49 | }
|
---|
50 | simulateHashChange(pathname) {
|
---|
51 | // Because we don't prevent the native event, the browser will independently update the path
|
---|
52 | this.setInitialPath(pathname);
|
---|
53 | this.urlChanges.push('hash: ' + pathname);
|
---|
54 | this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' });
|
---|
55 | }
|
---|
56 | prepareExternalUrl(url) {
|
---|
57 | if (url.length > 0 && !url.startsWith('/')) {
|
---|
58 | url = '/' + url;
|
---|
59 | }
|
---|
60 | return this._baseHref + url;
|
---|
61 | }
|
---|
62 | go(path, query = '', state = null) {
|
---|
63 | path = this.prepareExternalUrl(path);
|
---|
64 | if (this._historyIndex > 0) {
|
---|
65 | this._history.splice(this._historyIndex + 1);
|
---|
66 | }
|
---|
67 | this._history.push(new LocationState(path, query, state));
|
---|
68 | this._historyIndex = this._history.length - 1;
|
---|
69 | const locationState = this._history[this._historyIndex - 1];
|
---|
70 | if (locationState.path == path && locationState.query == query) {
|
---|
71 | return;
|
---|
72 | }
|
---|
73 | const url = path + (query.length > 0 ? ('?' + query) : '');
|
---|
74 | this.urlChanges.push(url);
|
---|
75 | this._subject.emit({ 'url': url, 'pop': false });
|
---|
76 | }
|
---|
77 | replaceState(path, query = '', state = null) {
|
---|
78 | path = this.prepareExternalUrl(path);
|
---|
79 | const history = this._history[this._historyIndex];
|
---|
80 | if (history.path == path && history.query == query) {
|
---|
81 | return;
|
---|
82 | }
|
---|
83 | history.path = path;
|
---|
84 | history.query = query;
|
---|
85 | history.state = state;
|
---|
86 | const url = path + (query.length > 0 ? ('?' + query) : '');
|
---|
87 | this.urlChanges.push('replace: ' + url);
|
---|
88 | }
|
---|
89 | forward() {
|
---|
90 | if (this._historyIndex < (this._history.length - 1)) {
|
---|
91 | this._historyIndex++;
|
---|
92 | this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
|
---|
93 | }
|
---|
94 | }
|
---|
95 | back() {
|
---|
96 | if (this._historyIndex > 0) {
|
---|
97 | this._historyIndex--;
|
---|
98 | this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
|
---|
99 | }
|
---|
100 | }
|
---|
101 | historyGo(relativePosition = 0) {
|
---|
102 | const nextPageIndex = this._historyIndex + relativePosition;
|
---|
103 | if (nextPageIndex >= 0 && nextPageIndex < this._history.length) {
|
---|
104 | this._historyIndex = nextPageIndex;
|
---|
105 | this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true, 'type': 'popstate' });
|
---|
106 | }
|
---|
107 | }
|
---|
108 | onUrlChange(fn) {
|
---|
109 | this._urlChangeListeners.push(fn);
|
---|
110 | if (!this._urlChangeSubscription) {
|
---|
111 | this._urlChangeSubscription = this.subscribe(v => {
|
---|
112 | this._notifyUrlChangeListeners(v.url, v.state);
|
---|
113 | });
|
---|
114 | }
|
---|
115 | }
|
---|
116 | /** @internal */
|
---|
117 | _notifyUrlChangeListeners(url = '', state) {
|
---|
118 | this._urlChangeListeners.forEach(fn => fn(url, state));
|
---|
119 | }
|
---|
120 | subscribe(onNext, onThrow, onReturn) {
|
---|
121 | return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
|
---|
122 | }
|
---|
123 | normalize(url) {
|
---|
124 | return null;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | SpyLocation.decorators = [
|
---|
128 | { type: Injectable }
|
---|
129 | ];
|
---|
130 | class LocationState {
|
---|
131 | constructor(path, query, state) {
|
---|
132 | this.path = path;
|
---|
133 | this.query = query;
|
---|
134 | this.state = state;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9jYXRpb25fbW9jay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbW1vbi90ZXN0aW5nL3NyYy9sb2NhdGlvbl9tb2NrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUdILE9BQU8sRUFBQyxZQUFZLEVBQUUsVUFBVSxFQUFDLE1BQU0s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