1 line
35 KiB
Text
1 line
35 KiB
Text
|
{"version":3,"file":"testing.mjs","sources":["../../../../../../packages/common/testing/src/location_mock.ts","../../../../../../packages/common/testing/src/mock_location_strategy.ts","../../../../../../packages/common/testing/src/mock_platform_location.ts","../../../../../../packages/common/testing/src/provide_location_mocks.ts","../../../../../../packages/common/testing/src/testing.ts","../../../../../../packages/common/testing/public_api.ts","../../../../../../packages/common/testing/index.ts","../../../../../../packages/common/testing/testing.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {\n Location,\n LocationStrategy,\n ɵnormalizeQueryParams as normalizeQueryParams,\n} from '@angular/common';\nimport {EventEmitter, Injectable} from '@angular/core';\nimport {SubscriptionLike} from 'rxjs';\n\n/**\n * A spy for {@link Location} that allows tests to fire simulated location events.\n *\n * @publicApi\n */\n@Injectable()\nexport class SpyLocation implements Location {\n urlChanges: string[] = [];\n private _history: LocationState[] = [new LocationState('', '', null)];\n private _historyIndex: number = 0;\n /** @internal */\n _subject: EventEmitter<any> = new EventEmitter();\n /** @internal */\n _basePath: string = '';\n /** @internal */\n _locationStrategy: LocationStrategy = null!;\n /** @internal */\n _urlChangeListeners: ((url: string, state: unknown) => void)[] = [];\n /** @internal */\n _urlChangeSubscription: SubscriptionLike | null = null;\n\n /** @nodoc */\n ngOnDestroy(): void {\n this._urlChangeSubscription?.unsubscribe();\n this._urlChangeListeners = [];\n }\n\n setInitialPath(url: string) {\n this._history[this._historyIndex].path = url;\n }\n\n setBaseHref(url: string) {\n this._basePath = url;\n }\n\n path(): string {\n return this._history[this._historyIndex].path;\n }\n\n getState(): unknown {\n return this._history[this._historyIndex].state;\n }\n\n isCurrentPathEqualTo(path: string, query: string = ''): boolean {\n const givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;\n const currPath = this.path().endsWith('/')\n ? this.path().substring(0, this.path().length - 1)\n : this.path();\n\n return currPath == givenPath + (query.length > 0 ? '?' + query : '');\n }\n\n simulateUrlPop(pathname: string) {\n this._subject.emit({'url': pathname, 'pop': true, 'type': 'popstate'});\n }\n\n simulateHashChange(pathname: string) {\n const path = this.prepareExternalUrl(pathname);\n this.pushHistory(path, '', null);\n\n this.urlChanges.push('hash: ' + pathname);\n // the browser will automatically fire popstate event before each `hashchange` event, so we need\n // to simulate it.\n this._subject.emit({'url': pathname, 'pop': true, 'type': 'popstate'});\n this._subject.emit({'url': pathname, 'pop': true, 'type': 'hashchange'});\n }\n\n prepareExternalUrl(url: string): string {\n if (url.length > 0 && !url.startsWith('/')) {\n url = '/' + url;\n }\n return this._basePath + url;\n }\n\n go(path: string, query: string = '', state: any = null) {\n path = this.prepareExternalUrl(path);\n\n this.pushHistory(path, query, state);\n\n const locationState = this._history[this._historyIndex - 1];\n if (locationState.path == path && locationState.query == query) {\n return;\n }\n\n const url = path + (query.length > 0 ? '?' + query : '');\n this.urlChanges.push(url);\n this._notifyUrlChangeListeners(path + normalizeQueryParams(query), state);\n }\n\n replaceState(path: string, query: string = '', state: any = null) {\n path = this.prepareExternalUrl(path);\n\n const history = this._history[this._historyIndex];\n\n history.state = state;\n\n if (history.path == path && history.query == query) {\n return;\n }\n\n history.path = path;\n history.quer
|