Skip to content

Commit 4e9db8b

Browse files
vakrilovSvetoslavTsenov
vakrilov
authored andcommitted
feat(test-bed): Run render fixtures in a full-page container
1 parent 8c4ad95 commit 4e9db8b

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Injectable } from "@angular/core";
22
import { TestComponentRenderer } from "@angular/core/testing";
3-
import { topmost } from "tns-core-modules/ui/frame";
4-
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
53
import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container";
4+
import { testingRootView } from "./util";
65

76
/**
87
* A NativeScript based implementation of the TestComponentRenderer.
@@ -11,14 +10,10 @@ import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container";
1110
export class NativeScriptTestComponentRenderer extends TestComponentRenderer {
1211

1312
insertRootElement(rootElId: string) {
14-
const page = topmost().currentPage;
15-
1613
const layout = new ProxyViewContainer();
1714
layout.id = rootElId;
1815

19-
const rootLayout = page.layoutView as LayoutBase;
16+
const rootLayout = testingRootView();
2017
rootLayout.addChild(layout);
2118
}
22-
2319
}
24-

Diff for: nativescript-angular/testing/src/util.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@ import { platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic
99
import { NS_COMPILER_PROVIDERS } from "../../platform";
1010
import { NATIVESCRIPT_TESTING_PROVIDERS, NativeScriptTestingModule } from "../index";
1111
import { CommonModule } from "@angular/common";
12+
import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout";
13+
14+
const TESTING_ROOT_ID = "__testing_container";
15+
1216
/**
13-
* Get a reference to the root application view.
17+
* Get a reference to the fixtures container.
1418
*/
15-
export function testingRootView(): View {
16-
return topmost().currentPage.content;
19+
export function testingRootView(): LayoutBase {
20+
const rootPageLayout = topmost().currentPage.content as LayoutBase;
21+
22+
let testingRoot: LayoutBase;
23+
rootPageLayout.eachChild(child => {
24+
if (child.id === TESTING_ROOT_ID) {
25+
testingRoot = child as LayoutBase;
26+
return false;
27+
}
28+
return true;
29+
});
30+
31+
if (!testingRoot) {
32+
testingRoot = new GridLayout();
33+
testingRoot.id = TESTING_ROOT_ID;
34+
GridLayout.setColumnSpan(testingRoot, 100);
35+
GridLayout.setRowSpan(testingRoot, 100);
36+
rootPageLayout.addChild(testingRoot);
37+
}
38+
39+
return testingRoot;
1740
}
1841

42+
1943
/**
2044
* Declared test contexts. When the suite is done this map should be empty if all lifecycle
2145
* calls have happened as expected.

Diff for: tests/app/tests/test-config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(<any>global).mocha.setup({
2-
timeout: 20000,
3-
});
1+
(<any>global).mocha.setup(
2+
{ timeout: 20000 },
3+
{ exit: true });
44

55
import * as chai from "chai";
66
export let assert: typeof chai.assert = (<any>global).chai.assert;

0 commit comments

Comments
 (0)