source: trip-planner-front/node_modules/@angular/common/bundles/common-testing.umd.js@ b738035

Last change on this file since b738035 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 35.1 KB
Line 
1/**
2 * @license Angular v12.2.13
3 * (c) 2010-2021 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs')) :
9 typeof define === 'function' && define.amd ? define('@angular/common/testing', ['exports', '@angular/core', '@angular/common', 'rxjs'], factory) :
10 (global = global || self, factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.testing = {}), global.ng.core, global.ng.common, global.rxjs));
11}(this, (function (exports, core, common, rxjs) { 'use strict';
12
13 /**
14 * @license
15 * Copyright Google LLC All Rights Reserved.
16 *
17 * Use of this source code is governed by an MIT-style license that can be
18 * found in the LICENSE file at https://angular.io/license
19 */
20 /**
21 * A spy for {@link Location} that allows tests to fire simulated location events.
22 *
23 * @publicApi
24 */
25 var SpyLocation = /** @class */ (function () {
26 function SpyLocation() {
27 this.urlChanges = [];
28 this._history = [new LocationState('', '', null)];
29 this._historyIndex = 0;
30 /** @internal */
31 this._subject = new core.EventEmitter();
32 /** @internal */
33 this._baseHref = '';
34 /** @internal */
35 this._platformStrategy = null;
36 /** @internal */
37 this._platformLocation = null;
38 /** @internal */
39 this._urlChangeListeners = [];
40 }
41 SpyLocation.prototype.setInitialPath = function (url) {
42 this._history[this._historyIndex].path = url;
43 };
44 SpyLocation.prototype.setBaseHref = function (url) {
45 this._baseHref = url;
46 };
47 SpyLocation.prototype.path = function () {
48 return this._history[this._historyIndex].path;
49 };
50 SpyLocation.prototype.getState = function () {
51 return this._history[this._historyIndex].state;
52 };
53 SpyLocation.prototype.isCurrentPathEqualTo = function (path, query) {
54 if (query === void 0) { query = ''; }
55 var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
56 var currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
57 return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
58 };
59 SpyLocation.prototype.simulateUrlPop = function (pathname) {
60 this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'popstate' });
61 };
62 SpyLocation.prototype.simulateHashChange = function (pathname) {
63 // Because we don't prevent the native event, the browser will independently update the path
64 this.setInitialPath(pathname);
65 this.urlChanges.push('hash: ' + pathname);
66 this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' });
67 };
68 SpyLocation.prototype.prepareExternalUrl = function (url) {
69 if (url.length > 0 && !url.startsWith('/')) {
70 url = '/' + url;
71 }
72 return this._baseHref + url;
73 };
74 SpyLocation.prototype.go = function (path, query, state) {
75 if (query === void 0) { query = ''; }
76 if (state === void 0) { state = null; }
77 path = this.prepareExternalUrl(path);
78 if (this._historyIndex > 0) {
79 this._history.splice(this._historyIndex + 1);
80 }
81 this._history.push(new LocationState(path, query, state));
82 this._historyIndex = this._history.length - 1;
83 var locationState = this._history[this._historyIndex - 1];
84 if (locationState.path == path && locationState.query == query) {
85 return;
86 }
87 var url = path + (query.length > 0 ? ('?' + query) : '');
88 this.urlChanges.push(url);
89 this._subject.emit({ 'url': url, 'pop': false });
90 };
91 SpyLocation.prototype.replaceState = function (path, query, state) {
92 if (query === void 0) { query = ''; }
93 if (state === void 0) { state = null; }
94 path = this.prepareExternalUrl(path);
95 var history = this._history[this._historyIndex];
96 if (history.path == path && history.query == query) {
97 return;
98 }
99 history.path = path;
100 history.query = query;
101 history.state = state;
102 var url = path + (query.length > 0 ? ('?' + query) : '');
103 this.urlChanges.push('replace: ' + url);
104 };
105 SpyLocation.prototype.forward = function () {
106 if (this._historyIndex < (this._history.length - 1)) {
107 this._historyIndex++;
108 this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
109 }
110 };
111 SpyLocation.prototype.back = function () {
112 if (this._historyIndex > 0) {
113 this._historyIndex--;
114 this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
115 }
116 };
117 SpyLocation.prototype.historyGo = function (relativePosition) {
118 if (relativePosition === void 0) { relativePosition = 0; }
119 var nextPageIndex = this._historyIndex + relativePosition;
120 if (nextPageIndex >= 0 && nextPageIndex < this._history.length) {
121 this._historyIndex = nextPageIndex;
122 this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true, 'type': 'popstate' });
123 }
124 };
125 SpyLocation.prototype.onUrlChange = function (fn) {
126 var _this = this;
127 this._urlChangeListeners.push(fn);
128 if (!this._urlChangeSubscription) {
129 this._urlChangeSubscription = this.subscribe(function (v) {
130 _this._notifyUrlChangeListeners(v.url, v.state);
131 });
132 }
133 };
134 /** @internal */
135 SpyLocation.prototype._notifyUrlChangeListeners = function (url, state) {
136 if (url === void 0) { url = ''; }
137 this._urlChangeListeners.forEach(function (fn) { return fn(url, state); });
138 };
139 SpyLocation.prototype.subscribe = function (onNext, onThrow, onReturn) {
140 return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
141 };
142 SpyLocation.prototype.normalize = function (url) {
143 return null;
144 };
145 return SpyLocation;
146 }());
147 SpyLocation.decorators = [
148 { type: core.Injectable }
149 ];
150 var LocationState = /** @class */ (function () {
151 function LocationState(path, query, state) {
152 this.path = path;
153 this.query = query;
154 this.state = state;
155 }
156 return LocationState;
157 }());
158
159 /*! *****************************************************************************
160 Copyright (c) Microsoft Corporation.
161
162 Permission to use, copy, modify, and/or distribute this software for any
163 purpose with or without fee is hereby granted.
164
165 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
166 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
167 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
168 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
169 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
170 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
171 PERFORMANCE OF THIS SOFTWARE.
172 ***************************************************************************** */
173 /* global Reflect, Promise */
174 var extendStatics = function (d, b) {
175 extendStatics = Object.setPrototypeOf ||
176 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
177 function (d, b) { for (var p in b)
178 if (Object.prototype.hasOwnProperty.call(b, p))
179 d[p] = b[p]; };
180 return extendStatics(d, b);
181 };
182 function __extends(d, b) {
183 if (typeof b !== "function" && b !== null)
184 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
185 extendStatics(d, b);
186 function __() { this.constructor = d; }
187 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
188 }
189 var __assign = function () {
190 __assign = Object.assign || function __assign(t) {
191 for (var s, i = 1, n = arguments.length; i < n; i++) {
192 s = arguments[i];
193 for (var p in s)
194 if (Object.prototype.hasOwnProperty.call(s, p))
195 t[p] = s[p];
196 }
197 return t;
198 };
199 return __assign.apply(this, arguments);
200 };
201 function __rest(s, e) {
202 var t = {};
203 for (var p in s)
204 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
205 t[p] = s[p];
206 if (s != null && typeof Object.getOwnPropertySymbols === "function")
207 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
208 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
209 t[p[i]] = s[p[i]];
210 }
211 return t;
212 }
213 function __decorate(decorators, target, key, desc) {
214 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
215 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
216 r = Reflect.decorate(decorators, target, key, desc);
217 else
218 for (var i = decorators.length - 1; i >= 0; i--)
219 if (d = decorators[i])
220 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
221 return c > 3 && r && Object.defineProperty(target, key, r), r;
222 }
223 function __param(paramIndex, decorator) {
224 return function (target, key) { decorator(target, key, paramIndex); };
225 }
226 function __metadata(metadataKey, metadataValue) {
227 if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
228 return Reflect.metadata(metadataKey, metadataValue);
229 }
230 function __awaiter(thisArg, _arguments, P, generator) {
231 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
232 return new (P || (P = Promise))(function (resolve, reject) {
233 function fulfilled(value) { try {
234 step(generator.next(value));
235 }
236 catch (e) {
237 reject(e);
238 } }
239 function rejected(value) { try {
240 step(generator["throw"](value));
241 }
242 catch (e) {
243 reject(e);
244 } }
245 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
246 step((generator = generator.apply(thisArg, _arguments || [])).next());
247 });
248 }
249 function __generator(thisArg, body) {
250 var _ = { label: 0, sent: function () { if (t[0] & 1)
251 throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
252 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
253 function verb(n) { return function (v) { return step([n, v]); }; }
254 function step(op) {
255 if (f)
256 throw new TypeError("Generator is already executing.");
257 while (_)
258 try {
259 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
260 return t;
261 if (y = 0, t)
262 op = [op[0] & 2, t.value];
263 switch (op[0]) {
264 case 0:
265 case 1:
266 t = op;
267 break;
268 case 4:
269 _.label++;
270 return { value: op[1], done: false };
271 case 5:
272 _.label++;
273 y = op[1];
274 op = [0];
275 continue;
276 case 7:
277 op = _.ops.pop();
278 _.trys.pop();
279 continue;
280 default:
281 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
282 _ = 0;
283 continue;
284 }
285 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
286 _.label = op[1];
287 break;
288 }
289 if (op[0] === 6 && _.label < t[1]) {
290 _.label = t[1];
291 t = op;
292 break;
293 }
294 if (t && _.label < t[2]) {
295 _.label = t[2];
296 _.ops.push(op);
297 break;
298 }
299 if (t[2])
300 _.ops.pop();
301 _.trys.pop();
302 continue;
303 }
304 op = body.call(thisArg, _);
305 }
306 catch (e) {
307 op = [6, e];
308 y = 0;
309 }
310 finally {
311 f = t = 0;
312 }
313 if (op[0] & 5)
314 throw op[1];
315 return { value: op[0] ? op[1] : void 0, done: true };
316 }
317 }
318 var __createBinding = Object.create ? (function (o, m, k, k2) {
319 if (k2 === undefined)
320 k2 = k;
321 Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
322 }) : (function (o, m, k, k2) {
323 if (k2 === undefined)
324 k2 = k;
325 o[k2] = m[k];
326 });
327 function __exportStar(m, o) {
328 for (var p in m)
329 if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
330 __createBinding(o, m, p);
331 }
332 function __values(o) {
333 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
334 if (m)
335 return m.call(o);
336 if (o && typeof o.length === "number")
337 return {
338 next: function () {
339 if (o && i >= o.length)
340 o = void 0;
341 return { value: o && o[i++], done: !o };
342 }
343 };
344 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
345 }
346 function __read(o, n) {
347 var m = typeof Symbol === "function" && o[Symbol.iterator];
348 if (!m)
349 return o;
350 var i = m.call(o), r, ar = [], e;
351 try {
352 while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
353 ar.push(r.value);
354 }
355 catch (error) {
356 e = { error: error };
357 }
358 finally {
359 try {
360 if (r && !r.done && (m = i["return"]))
361 m.call(i);
362 }
363 finally {
364 if (e)
365 throw e.error;
366 }
367 }
368 return ar;
369 }
370 /** @deprecated */
371 function __spread() {
372 for (var ar = [], i = 0; i < arguments.length; i++)
373 ar = ar.concat(__read(arguments[i]));
374 return ar;
375 }
376 /** @deprecated */
377 function __spreadArrays() {
378 for (var s = 0, i = 0, il = arguments.length; i < il; i++)
379 s += arguments[i].length;
380 for (var r = Array(s), k = 0, i = 0; i < il; i++)
381 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
382 r[k] = a[j];
383 return r;
384 }
385 function __spreadArray(to, from, pack) {
386 if (pack || arguments.length === 2)
387 for (var i = 0, l = from.length, ar; i < l; i++) {
388 if (ar || !(i in from)) {
389 if (!ar)
390 ar = Array.prototype.slice.call(from, 0, i);
391 ar[i] = from[i];
392 }
393 }
394 return to.concat(ar || Array.prototype.slice.call(from));
395 }
396 function __await(v) {
397 return this instanceof __await ? (this.v = v, this) : new __await(v);
398 }
399 function __asyncGenerator(thisArg, _arguments, generator) {
400 if (!Symbol.asyncIterator)
401 throw new TypeError("Symbol.asyncIterator is not defined.");
402 var g = generator.apply(thisArg, _arguments || []), i, q = [];
403 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
404 function verb(n) { if (g[n])
405 i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
406 function resume(n, v) { try {
407 step(g[n](v));
408 }
409 catch (e) {
410 settle(q[0][3], e);
411 } }
412 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
413 function fulfill(value) { resume("next", value); }
414 function reject(value) { resume("throw", value); }
415 function settle(f, v) { if (f(v), q.shift(), q.length)
416 resume(q[0][0], q[0][1]); }
417 }
418 function __asyncDelegator(o) {
419 var i, p;
420 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
421 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
422 }
423 function __asyncValues(o) {
424 if (!Symbol.asyncIterator)
425 throw new TypeError("Symbol.asyncIterator is not defined.");
426 var m = o[Symbol.asyncIterator], i;
427 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
428 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
429 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
430 }
431 function __makeTemplateObject(cooked, raw) {
432 if (Object.defineProperty) {
433 Object.defineProperty(cooked, "raw", { value: raw });
434 }
435 else {
436 cooked.raw = raw;
437 }
438 return cooked;
439 }
440 ;
441 var __setModuleDefault = Object.create ? (function (o, v) {
442 Object.defineProperty(o, "default", { enumerable: true, value: v });
443 }) : function (o, v) {
444 o["default"] = v;
445 };
446 function __importStar(mod) {
447 if (mod && mod.__esModule)
448 return mod;
449 var result = {};
450 if (mod != null)
451 for (var k in mod)
452 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
453 __createBinding(result, mod, k);
454 __setModuleDefault(result, mod);
455 return result;
456 }
457 function __importDefault(mod) {
458 return (mod && mod.__esModule) ? mod : { default: mod };
459 }
460 function __classPrivateFieldGet(receiver, state, kind, f) {
461 if (kind === "a" && !f)
462 throw new TypeError("Private accessor was defined without a getter");
463 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
464 throw new TypeError("Cannot read private member from an object whose class did not declare it");
465 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
466 }
467 function __classPrivateFieldSet(receiver, state, value, kind, f) {
468 if (kind === "m")
469 throw new TypeError("Private method is not writable");
470 if (kind === "a" && !f)
471 throw new TypeError("Private accessor was defined without a setter");
472 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
473 throw new TypeError("Cannot write private member to an object whose class did not declare it");
474 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
475 }
476
477 /**
478 * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated
479 * location events.
480 *
481 * @publicApi
482 */
483 var MockLocationStrategy = /** @class */ (function (_super) {
484 __extends(MockLocationStrategy, _super);
485 function MockLocationStrategy() {
486 var _this = _super.call(this) || this;
487 _this.internalBaseHref = '/';
488 _this.internalPath = '/';
489 _this.internalTitle = '';
490 _this.urlChanges = [];
491 /** @internal */
492 _this._subject = new core.EventEmitter();
493 _this.stateChanges = [];
494 return _this;
495 }
496 MockLocationStrategy.prototype.simulatePopState = function (url) {
497 this.internalPath = url;
498 this._subject.emit(new _MockPopStateEvent(this.path()));
499 };
500 MockLocationStrategy.prototype.path = function (includeHash) {
501 if (includeHash === void 0) { includeHash = false; }
502 return this.internalPath;
503 };
504 MockLocationStrategy.prototype.prepareExternalUrl = function (internal) {
505 if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
506 return this.internalBaseHref + internal.substring(1);
507 }
508 return this.internalBaseHref + internal;
509 };
510 MockLocationStrategy.prototype.pushState = function (ctx, title, path, query) {
511 // Add state change to changes array
512 this.stateChanges.push(ctx);
513 this.internalTitle = title;
514 var url = path + (query.length > 0 ? ('?' + query) : '');
515 this.internalPath = url;
516 var externalUrl = this.prepareExternalUrl(url);
517 this.urlChanges.push(externalUrl);
518 };
519 MockLocationStrategy.prototype.replaceState = function (ctx, title, path, query) {
520 // Reset the last index of stateChanges to the ctx (state) object
521 this.stateChanges[(this.stateChanges.length || 1) - 1] = ctx;
522 this.internalTitle = title;
523 var url = path + (query.length > 0 ? ('?' + query) : '');
524 this.internalPath = url;
525 var externalUrl = this.prepareExternalUrl(url);
526 this.urlChanges.push('replace: ' + externalUrl);
527 };
528 MockLocationStrategy.prototype.onPopState = function (fn) {
529 this._subject.subscribe({ next: fn });
530 };
531 MockLocationStrategy.prototype.getBaseHref = function () {
532 return this.internalBaseHref;
533 };
534 MockLocationStrategy.prototype.back = function () {
535 if (this.urlChanges.length > 0) {
536 this.urlChanges.pop();
537 this.stateChanges.pop();
538 var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
539 this.simulatePopState(nextUrl);
540 }
541 };
542 MockLocationStrategy.prototype.forward = function () {
543 throw 'not implemented';
544 };
545 MockLocationStrategy.prototype.getState = function () {
546 return this.stateChanges[(this.stateChanges.length || 1) - 1];
547 };
548 return MockLocationStrategy;
549 }(common.LocationStrategy));
550 MockLocationStrategy.decorators = [
551 { type: core.Injectable }
552 ];
553 MockLocationStrategy.ctorParameters = function () { return []; };
554 var _MockPopStateEvent = /** @class */ (function () {
555 function _MockPopStateEvent(newUrl) {
556 this.newUrl = newUrl;
557 this.pop = true;
558 this.type = 'popstate';
559 }
560 return _MockPopStateEvent;
561 }());
562
563 /**
564 * @license
565 * Copyright Google LLC All Rights Reserved.
566 *
567 * Use of this source code is governed by an MIT-style license that can be
568 * found in the LICENSE file at https://angular.io/license
569 */
570 /**
571 * Parser from https://tools.ietf.org/html/rfc3986#appendix-B
572 * ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
573 * 12 3 4 5 6 7 8 9
574 *
575 * Example: http://www.ics.uci.edu/pub/ietf/uri/#Related
576 *
577 * Results in:
578 *
579 * $1 = http:
580 * $2 = http
581 * $3 = //www.ics.uci.edu
582 * $4 = www.ics.uci.edu
583 * $5 = /pub/ietf/uri/
584 * $6 = <undefined>
585 * $7 = <undefined>
586 * $8 = #Related
587 * $9 = Related
588 */
589 var urlParse = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
590 function parseUrl(urlStr, baseHref) {
591 var verifyProtocol = /^((http[s]?|ftp):\/\/)/;
592 var serverBase;
593 // URL class requires full URL. If the URL string doesn't start with protocol, we need to add
594 // an arbitrary base URL which can be removed afterward.
595 if (!verifyProtocol.test(urlStr)) {
596 serverBase = 'http://empty.com/';
597 }
598 var parsedUrl;
599 try {
600 parsedUrl = new URL(urlStr, serverBase);
601 }
602 catch (e) {
603 var result = urlParse.exec(serverBase || '' + urlStr);
604 if (!result) {
605 throw new Error("Invalid URL: " + urlStr + " with base: " + baseHref);
606 }
607 var hostSplit = result[4].split(':');
608 parsedUrl = {
609 protocol: result[1],
610 hostname: hostSplit[0],
611 port: hostSplit[1] || '',
612 pathname: result[5],
613 search: result[6],
614 hash: result[8],
615 };
616 }
617 if (parsedUrl.pathname && parsedUrl.pathname.indexOf(baseHref) === 0) {
618 parsedUrl.pathname = parsedUrl.pathname.substring(baseHref.length);
619 }
620 return {
621 hostname: !serverBase && parsedUrl.hostname || '',
622 protocol: !serverBase && parsedUrl.protocol || '',
623 port: !serverBase && parsedUrl.port || '',
624 pathname: parsedUrl.pathname || '/',
625 search: parsedUrl.search || '',
626 hash: parsedUrl.hash || '',
627 };
628 }
629 /**
630 * Provider for mock platform location config
631 *
632 * @publicApi
633 */
634 var MOCK_PLATFORM_LOCATION_CONFIG = new core.InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
635 /**
636 * Mock implementation of URL state.
637 *
638 * @publicApi
639 */
640 var MockPlatformLocation = /** @class */ (function () {
641 function MockPlatformLocation(config) {
642 this.baseHref = '';
643 this.hashUpdate = new rxjs.Subject();
644 this.urlChangeIndex = 0;
645 this.urlChanges = [{ hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null }];
646 if (config) {
647 this.baseHref = config.appBaseHref || '';
648 var parsedChanges = this.parseChanges(null, config.startUrl || 'http://<empty>/', this.baseHref);
649 this.urlChanges[0] = Object.assign({}, parsedChanges);
650 }
651 }
652 Object.defineProperty(MockPlatformLocation.prototype, "hostname", {
653 get: function () {
654 return this.urlChanges[this.urlChangeIndex].hostname;
655 },
656 enumerable: false,
657 configurable: true
658 });
659 Object.defineProperty(MockPlatformLocation.prototype, "protocol", {
660 get: function () {
661 return this.urlChanges[this.urlChangeIndex].protocol;
662 },
663 enumerable: false,
664 configurable: true
665 });
666 Object.defineProperty(MockPlatformLocation.prototype, "port", {
667 get: function () {
668 return this.urlChanges[this.urlChangeIndex].port;
669 },
670 enumerable: false,
671 configurable: true
672 });
673 Object.defineProperty(MockPlatformLocation.prototype, "pathname", {
674 get: function () {
675 return this.urlChanges[this.urlChangeIndex].pathname;
676 },
677 enumerable: false,
678 configurable: true
679 });
680 Object.defineProperty(MockPlatformLocation.prototype, "search", {
681 get: function () {
682 return this.urlChanges[this.urlChangeIndex].search;
683 },
684 enumerable: false,
685 configurable: true
686 });
687 Object.defineProperty(MockPlatformLocation.prototype, "hash", {
688 get: function () {
689 return this.urlChanges[this.urlChangeIndex].hash;
690 },
691 enumerable: false,
692 configurable: true
693 });
694 Object.defineProperty(MockPlatformLocation.prototype, "state", {
695 get: function () {
696 return this.urlChanges[this.urlChangeIndex].state;
697 },
698 enumerable: false,
699 configurable: true
700 });
701 MockPlatformLocation.prototype.getBaseHrefFromDOM = function () {
702 return this.baseHref;
703 };
704 MockPlatformLocation.prototype.onPopState = function (fn) {
705 // No-op: a state stack is not implemented, so
706 // no events will ever come.
707 return function () { };
708 };
709 MockPlatformLocation.prototype.onHashChange = function (fn) {
710 var subscription = this.hashUpdate.subscribe(fn);
711 return function () { return subscription.unsubscribe(); };
712 };
713 Object.defineProperty(MockPlatformLocation.prototype, "href", {
714 get: function () {
715 var url = this.protocol + "//" + this.hostname + (this.port ? ':' + this.port : '');
716 url += "" + (this.pathname === '/' ? '' : this.pathname) + this.search + this.hash;
717 return url;
718 },
719 enumerable: false,
720 configurable: true
721 });
722 Object.defineProperty(MockPlatformLocation.prototype, "url", {
723 get: function () {
724 return "" + this.pathname + this.search + this.hash;
725 },
726 enumerable: false,
727 configurable: true
728 });
729 MockPlatformLocation.prototype.parseChanges = function (state, url, baseHref) {
730 if (baseHref === void 0) { baseHref = ''; }
731 // When the `history.state` value is stored, it is always copied.
732 state = JSON.parse(JSON.stringify(state));
733 return Object.assign(Object.assign({}, parseUrl(url, baseHref)), { state: state });
734 };
735 MockPlatformLocation.prototype.replaceState = function (state, title, newUrl) {
736 var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
737 this.urlChanges[this.urlChangeIndex] = Object.assign(Object.assign({}, this.urlChanges[this.urlChangeIndex]), { pathname: pathname, search: search, hash: hash, state: parsedState });
738 };
739 MockPlatformLocation.prototype.pushState = function (state, title, newUrl) {
740 var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
741 if (this.urlChangeIndex > 0) {
742 this.urlChanges.splice(this.urlChangeIndex + 1);
743 }
744 this.urlChanges.push(Object.assign(Object.assign({}, this.urlChanges[this.urlChangeIndex]), { pathname: pathname, search: search, hash: hash, state: parsedState }));
745 this.urlChangeIndex = this.urlChanges.length - 1;
746 };
747 MockPlatformLocation.prototype.forward = function () {
748 var oldUrl = this.url;
749 var oldHash = this.hash;
750 if (this.urlChangeIndex < this.urlChanges.length) {
751 this.urlChangeIndex++;
752 }
753 this.scheduleHashUpdate(oldHash, oldUrl);
754 };
755 MockPlatformLocation.prototype.back = function () {
756 var oldUrl = this.url;
757 var oldHash = this.hash;
758 if (this.urlChangeIndex > 0) {
759 this.urlChangeIndex--;
760 }
761 this.scheduleHashUpdate(oldHash, oldUrl);
762 };
763 MockPlatformLocation.prototype.historyGo = function (relativePosition) {
764 if (relativePosition === void 0) { relativePosition = 0; }
765 var oldUrl = this.url;
766 var oldHash = this.hash;
767 var nextPageIndex = this.urlChangeIndex + relativePosition;
768 if (nextPageIndex >= 0 && nextPageIndex < this.urlChanges.length) {
769 this.urlChangeIndex = nextPageIndex;
770 }
771 this.scheduleHashUpdate(oldHash, oldUrl);
772 };
773 MockPlatformLocation.prototype.getState = function () {
774 return this.state;
775 };
776 MockPlatformLocation.prototype.scheduleHashUpdate = function (oldHash, oldUrl) {
777 var _this = this;
778 if (oldHash !== this.hash) {
779 scheduleMicroTask(function () { return _this.hashUpdate.next({ type: 'hashchange', state: null, oldUrl: oldUrl, newUrl: _this.url }); });
780 }
781 };
782 return MockPlatformLocation;
783 }());
784 MockPlatformLocation.decorators = [
785 { type: core.Injectable }
786 ];
787 MockPlatformLocation.ctorParameters = function () { return [
788 { type: undefined, decorators: [{ type: core.Inject, args: [MOCK_PLATFORM_LOCATION_CONFIG,] }, { type: core.Optional }] }
789 ]; };
790 function scheduleMicroTask(cb) {
791 Promise.resolve(null).then(cb);
792 }
793
794 /**
795 * @license
796 * Copyright Google LLC All Rights Reserved.
797 *
798 * Use of this source code is governed by an MIT-style license that can be
799 * found in the LICENSE file at https://angular.io/license
800 */
801
802 /**
803 * @license
804 * Copyright Google LLC All Rights Reserved.
805 *
806 * Use of this source code is governed by an MIT-style license that can be
807 * found in the LICENSE file at https://angular.io/license
808 */
809 // This file only reexports content of the `src` folder. Keep it that way.
810
811 /**
812 * @license
813 * Copyright Google LLC All Rights Reserved.
814 *
815 * Use of this source code is governed by an MIT-style license that can be
816 * found in the LICENSE file at https://angular.io/license
817 */
818
819 /**
820 * Generated bundle index. Do not edit.
821 */
822
823 exports.MOCK_PLATFORM_LOCATION_CONFIG = MOCK_PLATFORM_LOCATION_CONFIG;
824 exports.MockLocationStrategy = MockLocationStrategy;
825 exports.MockPlatformLocation = MockPlatformLocation;
826 exports.SpyLocation = SpyLocation;
827
828 Object.defineProperty(exports, '__esModule', { value: true });
829
830})));
831//# sourceMappingURL=common-testing.umd.js.map
Note: See TracBrowser for help on using the repository browser.