Skip to content

Commit e551df2

Browse files
Alexander VakrilovSvetoslavTsenov
authored andcommitted
feat(test-bed): Run render fixtures in a full-page container (#1416)
* feat(test-bed): Run render fixtures in a full-page container
1 parent 8c4ad95 commit e551df2

34 files changed

+46
-212
lines changed
Lines changed: 2 additions & 7 deletions
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-

nativescript-angular/testing/src/util.ts

Lines changed: 27 additions & 3 deletions
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.

tests/app/tests/test-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(<any>global).mocha.setup({
2-
timeout: 20000,
2+
timeout: 20000
33
});
44

55
import * as chai from "chai";

tests/e2e/const.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/e2e/helpers/image-helper.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/e2e/lazy-load-routing.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/e2e/multi-page-routing.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.
-75.5 KB
Binary file not shown.
-32.8 KB
Binary file not shown.
-86.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)