diff --git a/tests/app/snippets/navigation/page-outlet.ts b/tests/app/snippets/navigation/page-outlet.ts index 27ce9ee48..3e1e9fbf8 100644 --- a/tests/app/snippets/navigation/page-outlet.ts +++ b/tests/app/snippets/navigation/page-outlet.ts @@ -1,4 +1,3 @@ -import { registerTestApp } from "../../tests/test-app"; import { ApplicationRef } from "@angular/core"; import { Router, NavigationStart, NavigationEnd } from "@angular/router"; // >> page-outlet-example @@ -22,8 +21,6 @@ export class PageNavigationApp { public done: Promise; constructor(public router: Router, public appRef: ApplicationRef) { - registerTestApp(PageNavigationApp, this, appRef); - this.done = new Promise((resolve, reject) => { this.router.events.subscribe((e) => { if (e instanceof NavigationStart) { diff --git a/tests/app/snippets/navigation/router-outlet.ts b/tests/app/snippets/navigation/router-outlet.ts index bca549d74..df15730bf 100644 --- a/tests/app/snippets/navigation/router-outlet.ts +++ b/tests/app/snippets/navigation/router-outlet.ts @@ -1,4 +1,3 @@ -import {registerTestApp} from "../../tests/test-app"; import { ApplicationRef } from "@angular/core"; // >> router-outlet-example import { Component, NgModule } from "@angular/core"; @@ -6,7 +5,7 @@ import { platformNativeScriptDynamic } from "nativescript-angular/platform"; import { NativeScriptRouterModule } from "nativescript-angular/router"; import { Router, NavigationStart, NavigationEnd } from "@angular/router"; import { routes } from "./app.routes"; -import {FirstComponent, SecondComponent} from "./navigation-common"; +import { FirstComponent, SecondComponent } from "./navigation-common"; @Component({ selector: "navigation-test", @@ -30,8 +29,6 @@ export class NavigationApp { public done: Promise; constructor(public router: Router, public appRef: ApplicationRef) { - registerTestApp(NavigationApp, this, appRef); - this.done = new Promise((resolve, reject) => { this.router.events.subscribe((e) => { if (e instanceof NavigationStart) { @@ -55,13 +52,13 @@ export class NavigationApp { NativeScriptRouterModule.forRoot(routes) ] }) -export class NavigationAppModule {} +export class NavigationAppModule { } // >> (hide) function start_snippet() { -// << (hide) -platformNativeScriptDynamic().bootstrapModule(NavigationAppModule); -// >> (hide) + // << (hide) + platformNativeScriptDynamic().bootstrapModule(NavigationAppModule); + // >> (hide) } // << (hide) // << router-outlet-example diff --git a/tests/app/tests/renderer-tests.ts b/tests/app/tests/renderer-tests.ts index bd4b7402e..94c0a4e7e 100644 --- a/tests/app/tests/renderer-tests.ts +++ b/tests/app/tests/renderer-tests.ts @@ -5,7 +5,6 @@ import { Component, ComponentRef, ElementRef, NgZone, Renderer2, ViewChild } fro import { ProxyViewContainer } from "ui/proxy-view-container"; import { Red } from "color/known-colors"; import { dumpView } from "./test-utils"; -import { TestApp } from "./test-app"; import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base"; import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout"; import { ContentView } from "tns-core-modules/ui/content-view"; @@ -16,8 +15,7 @@ import { isIOS } from "tns-core-modules/platform"; import { View, fontInternalProperty, backgroundInternalProperty } from "tns-core-modules/ui/core/view" import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing"; import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { Observable } from "rxjs/Observable"; -import { ReplaySubject } from "rxjs/ReplaySubject"; +import { Observable, ReplaySubject } from "rxjs"; @Component({ template: `` diff --git a/tests/app/tests/snippets.ts b/tests/app/tests/snippets.ts index 72a4da8ab..793b33421 100644 --- a/tests/app/tests/snippets.ts +++ b/tests/app/tests/snippets.ts @@ -3,7 +3,6 @@ import { assert } from "./test-config"; import { NavigationEnd, NavigationStart } from "@angular/router"; import { Subscription } from "rxjs"; -import { bootstrapTestApp, destroyTestApp } from "./test-app"; import { GestureComponent } from "../snippets/gestures.component"; import { LayoutsComponent } from "../snippets/layouts.component"; @@ -56,97 +55,3 @@ describe("Snippets", () => { }); }); }); - -describe("Snippets Navigation", () => { - let runningApp: any; - let subscription: Subscription; - - const cleanup = () => { - if (subscription) { - subscription.unsubscribe(); - subscription = null; - } - if (runningApp) { - destroyTestApp(runningApp); - runningApp = null; - } - }; - - after(cleanup); - - it("router-outlet app", (done) => { - bootstrapTestApp(NavigationApp, [], routes, [ - NavigationApp, - FirstComponent, - SecondComponent - ]).then((app) => { - runningApp = app; - - return runningApp.done.then(() => { - assert(app.startEvent instanceof NavigationStart); - assert.equal("/", app.startEvent.url); - - assert(app.endEvent instanceof NavigationEnd); - assert.equal("/", app.endEvent.url); - assert.equal("/first", app.endEvent.urlAfterRedirects); - - cleanup(); - }).then(() => done(), err => done(err)); - }); - }); - - //TODO: Skip the page-router-outlet test as it causes a crash in android in the current test-runner setup - (isIOS ? it : it.skip)("page-router-outlet app", (done) => { - bootstrapTestApp(PageNavigationApp, [], routes, [ - PageNavigationApp, - FirstComponent, - SecondComponent - ]).then((app) => { - runningApp = app; - - return runningApp.done.then(() => { - assert(app.startEvent instanceof NavigationStart); - assert.equal("/", app.startEvent.url); - - assert(app.endEvent instanceof NavigationEnd); - assert.equal("/", app.endEvent.url); - assert.equal("/first", app.endEvent.urlAfterRedirects); - - cleanup(); - }).then(() => done(), err => done(err)); - }); - }); -}); - -describe("Snippets ListView", () => { - let runningApp: any; - - const cleanup = () => { - if (runningApp) { - destroyTestApp(runningApp); - runningApp = null; - } - }; - - after(cleanup); - - it("template selector", (done) => { - bootstrapTestApp( - ListTemplateSelectorTest, - [DataService], - null, - [ - HeaderComponent, - ItemComponent, - ListTemplateSelectorTest - ]) - .then((app) => { - setTimeout(() => { - cleanup(); - done(); - }, 100); - }) - .catch(err => done(err)); - }); -}); - diff --git a/tests/app/tests/test-app.ts b/tests/app/tests/test-app.ts deleted file mode 100644 index 6d9726f93..000000000 --- a/tests/app/tests/test-app.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { platformNativeScriptDynamic } from "nativescript-angular/platform"; -import { NativeScriptModule } from "nativescript-angular/nativescript.module"; -import { NativeScriptRouterModule } from "nativescript-angular/router"; -import { - Type, Component, ComponentRef, - ComponentFactoryResolver, ApplicationRef, Renderer2, - ViewContainerRef, NgZone, NgModule, -} from "@angular/core"; - -import { getRootView } from "tns-core-modules/application"; -import { Frame } from "tns-core-modules/ui/frame"; -import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout"; -import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base"; - -import { APP_ROOT_VIEW } from "nativescript-angular/platform-providers"; - -@Component({ - selector: "my-app", - template: `` -}) -export class TestApp { - private _pendingDispose: ComponentRef[] = []; - - constructor( - private resolver: ComponentFactoryResolver, - private containerRef: ViewContainerRef, - public appRef: ApplicationRef, - public renderer: Renderer2, - public zone: NgZone - ) { - - registerTestApp(TestApp, this, appRef); - } - - public loadComponent(componentType: Type): Promise> { - const factory = this.resolver.resolveComponentFactory(componentType); - const componentRef = this.containerRef.createComponent( - factory, this.containerRef.length, this.containerRef.parentInjector); - this._pendingDispose.push(componentRef); - - this.appRef.tick(); - return Promise.resolve(componentRef); - } - - public disposeComponents() { - while (this._pendingDispose.length > 0) { - const componentRef = this._pendingDispose.pop(); - componentRef.destroy(); - } - } - - public static create(providers?: any[], components: any[] = [], directives: any[] = []): Promise { - return bootstrapTestApp(TestApp, providers, [], components, directives); - } - - public dispose() { - this.disposeComponents(); - destroyTestApp(this); - } -} - -const runningApps = new Map(); -const platform = platformNativeScriptDynamic({bootInExistingPage: true}); - -export function registerTestApp(appType, appInstance, appRef) { - appType.moduleType.appInstance = appInstance; - runningApps.set(appInstance, { - container: appType.moduleType.container, - appRoot: appType.moduleType.viewRoot, - appRef: appRef, - }); -} - -export function bootstrapTestApp( - appComponentType: new (...args) => T, - providers: any[] = [], - routes: any[] = [], - components: any[] = [], - directives: any[] = [] -): Promise { - const page = (getRootView()).currentPage; - const rootLayout = page.content; - const viewRoot = new GridLayout(); - rootLayout.addChild(viewRoot); - (viewRoot.style).backgroundColor = "white"; - viewRoot.margin = "20"; - viewRoot.opacity = 0.7; - GridLayout.setRowSpan(rootLayout, 50); - GridLayout.setColumnSpan(rootLayout, 50); - - let imports: any[] = [ - NativeScriptModule, - NativeScriptRouterModule, - ]; - if (routes && routes.length > 0) { - imports.push(NativeScriptRouterModule.forRoot(routes)); - } - - const rootViewProvider = {provide: APP_ROOT_VIEW, useValue: viewRoot}; - - @NgModule({ - bootstrap: [ - appComponentType - ], - declarations: [ - appComponentType, - ...components, - ...directives, - ], - entryComponents: [ - ...components, - ], - imports: imports, - exports: [ - NativeScriptModule, - ...components, - ...directives, - ], - providers: [ - rootViewProvider, - ...providers, - ] - }) - class TestAppModule { - public static viewRoot = viewRoot; - public static container = rootLayout; - } - // app registers with the module type via static fields on start - (appComponentType).moduleType = TestAppModule; - - return platform.bootstrapModule(TestAppModule).then(moduleRef => { - // app component constructor has run and we should have a - // registered component instance. - return (TestAppModule).appInstance; - }); -} - -export function destroyTestApp(app: any) { - if (!runningApps.has(app)) { - throw new Error("Unable to cleanup app: " + app); - } - - const entry = runningApps.get(app); - entry.container.removeChild(entry.appRoot); - // TODO: App disposal not doing anything useful anymore. Get rid of it? - // entry.appRef.dispose(); - runningApps.delete(app); -}