1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { __values, __decorate, __metadata } from 'tslib';
|
8 | import { Location, LocationStrategy } from '@angular/common';
|
9 | import { SpyLocation, MockLocationStrategy } from '@angular/common/testing';
|
10 | import { Injectable, Compiler, NgModule, NgModuleFactoryLoader, Injector, Optional } from '@angular/core';
|
11 | import { Router, ɵflatten, provideRoutes, ROUTER_CONFIGURATION, RouterModule, ɵROUTER_PROVIDERS, UrlSerializer, ChildrenOutletContexts, ROUTES, UrlHandlingStrategy, PreloadingStrategy, NoPreloading } from '@angular/router';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | var SpyNgModuleFactoryLoader = (function () {
|
50 | function SpyNgModuleFactoryLoader(compiler) {
|
51 | this.compiler = compiler;
|
52 | |
53 |
|
54 |
|
55 | this._stubbedModules = {};
|
56 | }
|
57 | Object.defineProperty(SpyNgModuleFactoryLoader.prototype, "stubbedModules", {
|
58 | |
59 |
|
60 |
|
61 | get: function () { return this._stubbedModules; },
|
62 | |
63 |
|
64 |
|
65 | set: function (modules) {
|
66 | var e_1, _a;
|
67 | var res = {};
|
68 | try {
|
69 | for (var _b = __values(Object.keys(modules)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
70 | var t = _c.value;
|
71 | res[t] = this.compiler.compileModuleAsync(modules[t]);
|
72 | }
|
73 | }
|
74 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
75 | finally {
|
76 | try {
|
77 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
78 | }
|
79 | finally { if (e_1) throw e_1.error; }
|
80 | }
|
81 | this._stubbedModules = res;
|
82 | },
|
83 | enumerable: true,
|
84 | configurable: true
|
85 | });
|
86 | SpyNgModuleFactoryLoader.prototype.load = function (path) {
|
87 | if (this._stubbedModules[path]) {
|
88 | return this._stubbedModules[path];
|
89 | }
|
90 | else {
|
91 | return Promise.reject(new Error("Cannot find module " + path));
|
92 | }
|
93 | };
|
94 | SpyNgModuleFactoryLoader = __decorate([
|
95 | Injectable(),
|
96 | __metadata("design:paramtypes", [Compiler])
|
97 | ], SpyNgModuleFactoryLoader);
|
98 | return SpyNgModuleFactoryLoader;
|
99 | }());
|
100 | function isUrlHandlingStrategy(opts) {
|
101 |
|
102 |
|
103 | return 'shouldProcessUrl' in opts;
|
104 | }
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy) {
|
111 | var router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, ɵflatten(routes));
|
112 | if (opts) {
|
113 |
|
114 | if (isUrlHandlingStrategy(opts)) {
|
115 | router.urlHandlingStrategy = opts;
|
116 | }
|
117 | else {
|
118 |
|
119 | if (opts.malformedUriErrorHandler) {
|
120 | router.malformedUriErrorHandler = opts.malformedUriErrorHandler;
|
121 | }
|
122 | if (opts.paramsInheritanceStrategy) {
|
123 | router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
|
124 | }
|
125 | }
|
126 | }
|
127 | if (urlHandlingStrategy) {
|
128 | router.urlHandlingStrategy = urlHandlingStrategy;
|
129 | }
|
130 | return router;
|
131 | }
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | var RouterTestingModule = (function () {
|
159 | function RouterTestingModule() {
|
160 | }
|
161 | RouterTestingModule_1 = RouterTestingModule;
|
162 | RouterTestingModule.withRoutes = function (routes, config) {
|
163 | return {
|
164 | ngModule: RouterTestingModule_1,
|
165 | providers: [
|
166 | provideRoutes(routes),
|
167 | { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
|
168 | ]
|
169 | };
|
170 | };
|
171 | var RouterTestingModule_1;
|
172 | RouterTestingModule = RouterTestingModule_1 = __decorate([
|
173 | NgModule({
|
174 | exports: [RouterModule],
|
175 | providers: [
|
176 | ɵROUTER_PROVIDERS, { provide: Location, useClass: SpyLocation },
|
177 | { provide: LocationStrategy, useClass: MockLocationStrategy },
|
178 | { provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
|
179 | provide: Router,
|
180 | useFactory: setupTestingRouter,
|
181 | deps: [
|
182 | UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,
|
183 | ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()]
|
184 | ]
|
185 | },
|
186 | { provide: PreloadingStrategy, useExisting: NoPreloading }, provideRoutes([])
|
187 | ]
|
188 | })
|
189 | ], RouterTestingModule);
|
190 | return RouterTestingModule;
|
191 | }());
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | export { SpyNgModuleFactoryLoader, setupTestingRouter, RouterTestingModule };
|
223 |
|