|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {DOCUMENT, LocationChangeEvent, LocationChangeListener, PlatformLocation, ɵPlatformNavigation as PlatformNavigation} from '@angular/common'; |
10 | | -import {Inject, inject, Injectable, InjectionToken, Optional} from '@angular/core'; |
| 9 | +import {LocationChangeEvent, LocationChangeListener, PlatformLocation} from '@angular/common'; |
| 10 | +import {Inject, Injectable, InjectionToken, Optional} from '@angular/core'; |
11 | 11 | import {Subject} from 'rxjs'; |
12 | 12 |
|
13 | | -import {FakeNavigation} from './navigation/fake_navigation'; |
14 | | - |
15 | 13 | /** |
16 | 14 | * Parser from https://tools.ietf.org/html/rfc3986#appendix-B |
17 | 15 | * ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? |
@@ -252,82 +250,3 @@ export class MockPlatformLocation implements PlatformLocation { |
252 | 250 | } |
253 | 251 | } |
254 | 252 | } |
255 | | - |
256 | | -/** |
257 | | - * Mock implementation of URL state. |
258 | | - */ |
259 | | -@Injectable() |
260 | | -export class FakeNavigationPlatformLocation implements PlatformLocation { |
261 | | - private _platformNavigation = inject(PlatformNavigation) as FakeNavigation; |
262 | | - private window = inject(DOCUMENT).defaultView!; |
263 | | - |
264 | | - constructor() { |
265 | | - if (!(this._platformNavigation instanceof FakeNavigation)) { |
266 | | - throw new Error( |
267 | | - 'FakePlatformNavigation cannot be used without FakeNavigation. Use ' + |
268 | | - '`provideFakeNavigation` to have all these services provided together.', |
269 | | - ); |
270 | | - } |
271 | | - } |
272 | | - |
273 | | - private config = inject(MOCK_PLATFORM_LOCATION_CONFIG, {optional: true}); |
274 | | - getBaseHrefFromDOM(): string { |
275 | | - return this.config?.appBaseHref ?? ''; |
276 | | - } |
277 | | - |
278 | | - onPopState(fn: LocationChangeListener): VoidFunction { |
279 | | - this.window.addEventListener('popstate', fn); |
280 | | - return () => this.window.removeEventListener('popstate', fn); |
281 | | - } |
282 | | - |
283 | | - onHashChange(fn: LocationChangeListener): VoidFunction { |
284 | | - this.window.addEventListener('hashchange', fn as any); |
285 | | - return () => this.window.removeEventListener('hashchange', fn as any); |
286 | | - } |
287 | | - |
288 | | - get href(): string { |
289 | | - return this._platformNavigation.currentEntry.url!; |
290 | | - } |
291 | | - get protocol(): string { |
292 | | - return new URL(this._platformNavigation.currentEntry.url!).protocol; |
293 | | - } |
294 | | - get hostname(): string { |
295 | | - return new URL(this._platformNavigation.currentEntry.url!).hostname; |
296 | | - } |
297 | | - get port(): string { |
298 | | - return new URL(this._platformNavigation.currentEntry.url!).port; |
299 | | - } |
300 | | - get pathname(): string { |
301 | | - return new URL(this._platformNavigation.currentEntry.url!).pathname; |
302 | | - } |
303 | | - get search(): string { |
304 | | - return new URL(this._platformNavigation.currentEntry.url!).search; |
305 | | - } |
306 | | - get hash(): string { |
307 | | - return new URL(this._platformNavigation.currentEntry.url!).hash; |
308 | | - } |
309 | | - |
310 | | - pushState(state: any, title: string, url: string): void { |
311 | | - this._platformNavigation.pushState(state, title, url); |
312 | | - } |
313 | | - |
314 | | - replaceState(state: any, title: string, url: string): void { |
315 | | - this._platformNavigation.replaceState(state, title, url); |
316 | | - } |
317 | | - |
318 | | - forward(): void { |
319 | | - this._platformNavigation.forward(); |
320 | | - } |
321 | | - |
322 | | - back(): void { |
323 | | - this._platformNavigation.back(); |
324 | | - } |
325 | | - |
326 | | - historyGo(relativePosition: number = 0): void { |
327 | | - this._platformNavigation.go(relativePosition); |
328 | | - } |
329 | | - |
330 | | - getState(): unknown { |
331 | | - return this._platformNavigation.currentEntry.getHistoryState(); |
332 | | - } |
333 | | -} |
0 commit comments