Project

General

Profile

1
/**
2
 * @license Angular v4.4.6
3
 * (c) 2010-2017 Google, Inc. https://angular.io/
4
 * License: MIT
5
 */
6
(function (global, factory) {
7
	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
8
	typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common'], factory) :
9
	(factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.testing = global.ng.common.testing || {}),global.ng.core,global.ng.common));
10
}(this, (function (exports,_angular_core,_angular_common) { 'use strict';
11

    
12
/*! *****************************************************************************
13
Copyright (c) Microsoft Corporation. All rights reserved.
14
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
15
this file except in compliance with the License. You may obtain a copy of the
16
License at http://www.apache.org/licenses/LICENSE-2.0
17

    
18
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
20
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
21
MERCHANTABLITY OR NON-INFRINGEMENT.
22

    
23
See the Apache Version 2.0 License for specific language governing permissions
24
and limitations under the License.
25
***************************************************************************** */
26
/* global Reflect, Promise */
27

    
28
var extendStatics = Object.setPrototypeOf ||
29
    ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
30
    function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
31

    
32
function __extends(d, b) {
33
    extendStatics(d, b);
34
    function __() { this.constructor = d; }
35
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
}
37

    
38
/**
39
 * @license Angular v4.4.6
40
 * (c) 2010-2017 Google, Inc. https://angular.io/
41
 * License: MIT
42
 */
43
/**
44
 * @license
45
 * Copyright Google Inc. All Rights Reserved.
46
 *
47
 * Use of this source code is governed by an MIT-style license that can be
48
 * found in the LICENSE file at https://angular.io/license
49
 */
50
/**
51
 * A spy for {@link Location} that allows tests to fire simulated location events.
52
 *
53
 * @experimental
54
 */
55
var SpyLocation = (function () {
56
    function SpyLocation() {
57
        this.urlChanges = [];
58
        this._history = [new LocationState('', '')];
59
        this._historyIndex = 0;
60
        /** @internal */
61
        this._subject = new _angular_core.EventEmitter();
62
        /** @internal */
63
        this._baseHref = '';
64
        /** @internal */
65
        this._platformStrategy = null;
66
    }
67
    SpyLocation.prototype.setInitialPath = function (url) { this._history[this._historyIndex].path = url; };
68
    SpyLocation.prototype.setBaseHref = function (url) { this._baseHref = url; };
69
    SpyLocation.prototype.path = function () { return this._history[this._historyIndex].path; };
70
    SpyLocation.prototype.isCurrentPathEqualTo = function (path, query) {
71
        if (query === void 0) { query = ''; }
72
        var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
73
        var currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
74
        return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
75
    };
76
    SpyLocation.prototype.simulateUrlPop = function (pathname) { this._subject.emit({ 'url': pathname, 'pop': true }); };
77
    SpyLocation.prototype.simulateHashChange = function (pathname) {
78
        // Because we don't prevent the native event, the browser will independently update the path
79
        this.setInitialPath(pathname);
80
        this.urlChanges.push('hash: ' + pathname);
81
        this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' });
82
    };
83
    SpyLocation.prototype.prepareExternalUrl = function (url) {
84
        if (url.length > 0 && !url.startsWith('/')) {
85
            url = '/' + url;
86
        }
87
        return this._baseHref + url;
88
    };
89
    SpyLocation.prototype.go = function (path, query) {
90
        if (query === void 0) { query = ''; }
91
        path = this.prepareExternalUrl(path);
92
        if (this._historyIndex > 0) {
93
            this._history.splice(this._historyIndex + 1);
94
        }
95
        this._history.push(new LocationState(path, query));
96
        this._historyIndex = this._history.length - 1;
97
        var locationState = this._history[this._historyIndex - 1];
98
        if (locationState.path == path && locationState.query == query) {
99
            return;
100
        }
101
        var url = path + (query.length > 0 ? ('?' + query) : '');
102
        this.urlChanges.push(url);
103
        this._subject.emit({ 'url': url, 'pop': false });
104
    };
105
    SpyLocation.prototype.replaceState = function (path, query) {
106
        if (query === void 0) { query = ''; }
107
        path = this.prepareExternalUrl(path);
108
        var history = this._history[this._historyIndex];
109
        if (history.path == path && history.query == query) {
110
            return;
111
        }
112
        history.path = path;
113
        history.query = query;
114
        var url = path + (query.length > 0 ? ('?' + query) : '');
115
        this.urlChanges.push('replace: ' + url);
116
    };
117
    SpyLocation.prototype.forward = function () {
118
        if (this._historyIndex < (this._history.length - 1)) {
119
            this._historyIndex++;
120
            this._subject.emit({ 'url': this.path(), 'pop': true });
121
        }
122
    };
123
    SpyLocation.prototype.back = function () {
124
        if (this._historyIndex > 0) {
125
            this._historyIndex--;
126
            this._subject.emit({ 'url': this.path(), 'pop': true });
127
        }
128
    };
129
    SpyLocation.prototype.subscribe = function (onNext, onThrow, onReturn) {
130
        return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
131
    };
132
    SpyLocation.prototype.normalize = function (url) { return null; };
133
    return SpyLocation;
134
}());
135
SpyLocation.decorators = [
136
    { type: _angular_core.Injectable },
137
];
138
/** @nocollapse */
139
SpyLocation.ctorParameters = function () { return []; };
140
var LocationState = (function () {
141
    function LocationState(path, query) {
142
        this.path = path;
143
        this.query = query;
144
    }
145
    return LocationState;
146
}());
147
/**
148
 * @license
149
 * Copyright Google Inc. All Rights Reserved.
150
 *
151
 * Use of this source code is governed by an MIT-style license that can be
152
 * found in the LICENSE file at https://angular.io/license
153
 */
154
/**
155
 * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated
156
 * location events.
157
 *
158
 * @stable
159
 */
160
var MockLocationStrategy = (function (_super) {
161
    __extends(MockLocationStrategy, _super);
162
    function MockLocationStrategy() {
163
        var _this = _super.call(this) || this;
164
        _this.internalBaseHref = '/';
165
        _this.internalPath = '/';
166
        _this.internalTitle = '';
167
        _this.urlChanges = [];
168
        /** @internal */
169
        _this._subject = new _angular_core.EventEmitter();
170
        return _this;
171
    }
172
    MockLocationStrategy.prototype.simulatePopState = function (url) {
173
        this.internalPath = url;
174
        this._subject.emit(new _MockPopStateEvent(this.path()));
175
    };
176
    MockLocationStrategy.prototype.path = function (includeHash) {
177
        if (includeHash === void 0) { includeHash = false; }
178
        return this.internalPath;
179
    };
180
    MockLocationStrategy.prototype.prepareExternalUrl = function (internal) {
181
        if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
182
            return this.internalBaseHref + internal.substring(1);
183
        }
184
        return this.internalBaseHref + internal;
185
    };
186
    MockLocationStrategy.prototype.pushState = function (ctx, title, path, query) {
187
        this.internalTitle = title;
188
        var url = path + (query.length > 0 ? ('?' + query) : '');
189
        this.internalPath = url;
190
        var externalUrl = this.prepareExternalUrl(url);
191
        this.urlChanges.push(externalUrl);
192
    };
193
    MockLocationStrategy.prototype.replaceState = function (ctx, title, path, query) {
194
        this.internalTitle = title;
195
        var url = path + (query.length > 0 ? ('?' + query) : '');
196
        this.internalPath = url;
197
        var externalUrl = this.prepareExternalUrl(url);
198
        this.urlChanges.push('replace: ' + externalUrl);
199
    };
200
    MockLocationStrategy.prototype.onPopState = function (fn) { this._subject.subscribe({ next: fn }); };
201
    MockLocationStrategy.prototype.getBaseHref = function () { return this.internalBaseHref; };
202
    MockLocationStrategy.prototype.back = function () {
203
        if (this.urlChanges.length > 0) {
204
            this.urlChanges.pop();
205
            var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
206
            this.simulatePopState(nextUrl);
207
        }
208
    };
209
    MockLocationStrategy.prototype.forward = function () { throw 'not implemented'; };
210
    return MockLocationStrategy;
211
}(_angular_common.LocationStrategy));
212
MockLocationStrategy.decorators = [
213
    { type: _angular_core.Injectable },
214
];
215
/** @nocollapse */
216
MockLocationStrategy.ctorParameters = function () { return []; };
217
var _MockPopStateEvent = (function () {
218
    function _MockPopStateEvent(newUrl) {
219
        this.newUrl = newUrl;
220
        this.pop = true;
221
        this.type = 'popstate';
222
    }
223
    return _MockPopStateEvent;
224
}());
225

    
226
exports.SpyLocation = SpyLocation;
227
exports.MockLocationStrategy = MockLocationStrategy;
228

    
229
Object.defineProperty(exports, '__esModule', { value: true });
230

    
231
})));
232
//# sourceMappingURL=common-testing.umd.js.map
(9-9/16)