|
1 | 1 | // make sure you import mocha-config before @angular/core
|
2 | 2 | import { assert } from "./test-config";
|
3 |
| -import { TestApp, bootstrapTestApp } from "./test-app"; |
4 |
| -import { Location, LocationStrategy } from "@angular/common"; |
5 |
| -import { Component, ViewContainerRef, NgModuleFactoryLoader, ModuleWithComponentFactories, ComponentFactory, Compiler, Injector, Optional } from "@angular/core"; |
6 |
| -import { NoPreloading, PreloadingStrategy, ROUTES, Route, Router, RouterModule, RouterOutletMap, Routes, UrlHandlingStrategy, UrlSerializer, provideRoutes, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS, ɵflatten as flatten } from '@angular/router'; |
7 |
| -import { BehaviorSubject } from "rxjs/BehaviorSubject"; |
| 3 | +import { TestApp } from "./test-app"; |
| 4 | +import { Component, ViewContainerRef } from "@angular/core"; |
8 | 5 | import { Page } from "ui/page";
|
9 | 6 | import { topmost } from "ui/frame";
|
10 | 7 | import { ModalDialogParams, ModalDialogService } from "nativescript-angular/directives/dialogs";
|
11 |
| -import { NSModuleFactoryLoader } from "nativescript-angular/router"; |
12 |
| -import { HOOKS_LOG } from "../base.component"; |
13 |
| -const lazyLoadHooksLog = new BehaviorSubject([]); |
14 |
| -const lazyLoadHooksLogProvider = { provide: HOOKS_LOG, useValue: lazyLoadHooksLog }; |
15 | 8 |
|
16 | 9 | import { device, platformNames } from "platform";
|
17 | 10 | const CLOSE_WAIT = (device.os === platformNames.ios) ? 1000 : 0;
|
@@ -40,41 +33,16 @@ export class FailComponent {
|
40 | 33 | }
|
41 | 34 | }
|
42 | 35 |
|
43 |
| -// TODO: this is done temporarily since the SecondModule is used to lazily load on demand here in the tests |
44 |
| -// could create module specificly to test this |
45 |
| -export function setupTestingRouter( |
46 |
| - urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, |
47 |
| - loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], |
48 |
| - urlHandlingStrategy?: UrlHandlingStrategy) { |
49 |
| - const router = new Router( |
50 |
| - null !, urlSerializer, outletMap, location, injector, loader, compiler, flatten(routes)); |
51 |
| - if (urlHandlingStrategy) { |
52 |
| - router.urlHandlingStrategy = urlHandlingStrategy; |
53 |
| - } |
54 |
| - return router; |
55 |
| -} |
56 |
| - |
57 | 36 | @Component({
|
58 | 37 | selector: "sucess-comp",
|
59 |
| - providers: [ |
60 |
| - ModalDialogService, |
61 |
| - { |
62 |
| - provide: Router, useFactory: setupTestingRouter, |
63 |
| - deps: [ |
64 |
| - UrlSerializer, RouterOutletMap, Location, NgModuleFactoryLoader, Compiler, Injector, ROUTES, |
65 |
| - [UrlHandlingStrategy, new Optional()] |
66 |
| - ] |
67 |
| - }, |
68 |
| - lazyLoadHooksLogProvider, |
69 |
| - { provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader } |
70 |
| - ], |
| 38 | + providers: [ModalDialogService], |
71 | 39 | template: `
|
72 | 40 | <GridLayout margin="20">
|
73 | 41 | <Label text="Modal dialogs"></Label>
|
74 | 42 | </GridLayout>`
|
75 | 43 | })
|
76 | 44 | export class SuccessComponent {
|
77 |
| - constructor(public service: ModalDialogService, public vcRef: ViewContainerRef, public moduleLoader: NgModuleFactoryLoader) { |
| 45 | + constructor(public service: ModalDialogService, public vcRef: ViewContainerRef) { |
78 | 46 | }
|
79 | 47 | }
|
80 | 48 |
|
@@ -141,36 +109,4 @@ describe("modal-dialog", () => {
|
141 | 109 | setTimeout(done, CLOSE_WAIT); // wait for the dialog to close in IOS
|
142 | 110 | }, err => done(err));
|
143 | 111 | });
|
144 |
| - |
145 |
| - it("showModal provides module reference option when opening modal component which comes from lazy loaded module", (done) => { |
146 |
| - const context = { property: "I was lazy loaded from another module on demand!" }; |
147 |
| - let service, comp; |
148 |
| - testApp.loadComponent(SuccessComponent) |
149 |
| - .then((ref) => { |
150 |
| - service = <ModalDialogService>ref.instance.service; |
151 |
| - comp = <SuccessComponent>ref.instance; |
152 |
| - return (<NSModuleFactoryLoader>comp.moduleLoader).loadAndCompileComponents("./lazy-loaded.module#SecondModule"); |
153 |
| - }).then((mod: any) => { |
154 |
| - const moduleRef = (<ModuleWithComponentFactories<any>>mod).ngModuleFactory.create(comp.vcRef.parentInjector); |
155 |
| - // find component factory to ref the correct componentType |
156 |
| - let lazyModalCmpFactory: ComponentFactory<any>; |
157 |
| - for (let cmp of mod.componentFactories) { |
158 |
| - if (cmp.selector === "modal-lazy-comp") { // find by selector |
159 |
| - lazyModalCmpFactory = cmp; |
160 |
| - break; |
161 |
| - } |
162 |
| - } |
163 |
| - |
164 |
| - return service.showModal(lazyModalCmpFactory.componentType, { |
165 |
| - moduleRef, |
166 |
| - viewContainerRef: comp.vcRef, |
167 |
| - context: context |
168 |
| - }); |
169 |
| - }) |
170 |
| - .then((res) => { |
171 |
| - assert.strictEqual(res, context); |
172 |
| - setTimeout(done, CLOSE_WAIT); // wait for the dialog to close in IOS |
173 |
| - }, err => done(err)); |
174 |
| - |
175 |
| - }); |
176 | 112 | });
|
0 commit comments