Skip to content

Commit 5996d3f

Browse files
committed
Revert "refactor(router): Update integration tests to cover navigation and history API (angular#53799)" (angular#53860)
This reverts commit eb2e879. PR Close angular#53860
1 parent acf1793 commit 5996d3f

File tree

7 files changed

+5892
-6024
lines changed

7 files changed

+5892
-6024
lines changed

packages/common/src/private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
*/
88

99
export {DomAdapter as ɵDomAdapter, getDOM as ɵgetDOM, setRootDomAdapter as ɵsetRootDomAdapter} from './dom_adapter';
10-
export {PlatformNavigation as ɵPlatformNavigation} from './navigation/platform_navigation';

packages/common/testing/src/mock_platform_location.ts

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

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';
1111
import {Subject} from 'rxjs';
1212

13-
import {FakeNavigation} from './navigation/fake_navigation';
14-
1513
/**
1614
* Parser from https://tools.ietf.org/html/rfc3986#appendix-B
1715
* ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
@@ -252,82 +250,3 @@ export class MockPlatformLocation implements PlatformLocation {
252250
}
253251
}
254252
}
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-
}

packages/common/testing/src/navigation/fake_navigation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
// Prevents deletion of `Event` from `globalThis` during module loading.
10+
const Event = globalThis.Event;
11+
912
/**
1013
* Fake implementation of user agent history and navigation behavior. This is a
1114
* high-fidelity implementation of browser behavior that attempts to emulate

packages/common/testing/src/navigation/provide_fake_platform_navigation.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,25 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {DOCUMENT, PlatformLocation} from '@angular/common';
10-
import {inject, Provider} from '@angular/core';
9+
import {Provider} from '@angular/core';
1110

1211
// @ng_package: ignore-cross-repo-import
1312
import {PlatformNavigation} from '../../../src/navigation/platform_navigation';
14-
import {FakeNavigationPlatformLocation, MOCK_PLATFORM_LOCATION_CONFIG} from '../mock_platform_location';
1513

1614
import {FakeNavigation} from './fake_navigation';
1715

1816
/**
1917
* Return a provider for the `FakeNavigation` in place of the real Navigation API.
18+
*
19+
* @internal
2020
*/
2121
export function provideFakePlatformNavigation(): Provider[] {
2222
return [
2323
{
2424
provide: PlatformNavigation,
2525
useFactory: () => {
26-
const config = inject(MOCK_PLATFORM_LOCATION_CONFIG, {optional: true});
27-
return new FakeNavigation(
28-
inject(DOCUMENT).defaultView!,
29-
config?.startUrl as `http${string}` ?? 'http://_empty_/');
26+
return new FakeNavigation(window, 'https://test.com');
3027
}
3128
},
32-
{provide: PlatformLocation, useClass: FakeNavigationPlatformLocation},
3329
];
3430
}

packages/common/testing/src/private_export.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/common/testing/src/testing.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
* @description
1212
* Entry point for all public APIs of the common/testing package.
1313
*/
14-
15-
export * from './private_export';
1614
export {SpyLocation} from './location_mock';
1715
export {MockLocationStrategy} from './mock_location_strategy';
1816
export {MOCK_PLATFORM_LOCATION_CONFIG, MockPlatformLocation, MockPlatformLocationConfig} from './mock_platform_location';

0 commit comments

Comments
 (0)