Skip to content

Commit e551df2

Browse files
Alexander VakrilovSvetoslavTsenov
Alexander Vakrilov
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
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

+1-1
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";

Diff for: tests/e2e/const.js

-4
This file was deleted.

Diff for: tests/e2e/helpers/image-helper.ts

-22
This file was deleted.

Diff for: tests/e2e/lazy-load-routing.ts

-40
This file was deleted.

Diff for: tests/e2e/multi-page-routing.ts

-29
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Diff for: tests/e2e/setup.ts

-20
This file was deleted.

Diff for: tests/e2e/single-page-routing.ts

-42
This file was deleted.

Diff for: tests/e2e/tsconfig.json

-19
This file was deleted.

Diff for: tests/hooks/before-prepare/nativescript-dev-typescript.js

-1
This file was deleted.

Diff for: tests/hooks/before-watch/nativescript-dev-typescript.js

-1
This file was deleted.

Diff for: tests/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = function(config) {
4949

5050

5151
// enable / disable watching file and executing tests whenever any file changes
52-
autoWatch: true,
52+
autoWatch: false,
5353

5454

5555
// start these browsers

Diff for: tests/package.json

+12-22
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,26 @@
4242
"zone.js": "^0.8.4"
4343
},
4444
"devDependencies": {
45-
"@types/chai": "^4.0.2",
46-
"@types/mocha": "^2.2.41",
47-
"@types/node": "^7.0.5",
45+
"@types/chai": "^4.1.4",
46+
"@types/mocha": "^5.2.4",
47+
"chai": "4.1.2",
48+
"karma": "2.0.4",
49+
"karma-chai": "0.1.0",
50+
"karma-mocha": "1.3.0",
51+
"karma-mocha-reporter": "2.2.5",
52+
"karma-nativescript-launcher": "0.4.0",
53+
"mocha": "5.2.0",
54+
"nativescript-dev-typescript": "~0.7.0",
4855
"babel-traverse": "6.8.0",
4956
"babel-types": "6.8.1",
5057
"babylon": "6.8.0",
51-
"chai": "^3.5.0",
52-
"chai-as-promised": "^5.3.0",
53-
"filewalker": "0.1.2",
54-
"grunt-cli": "^1.2.0",
55-
"karma": "^0.13.19",
56-
"karma-chai": "^0.1.0",
57-
"karma-mocha": "^0.2.1",
58-
"karma-mocha-reporter": "^1.2.0",
59-
"karma-nativescript-launcher": "^0.4.0",
6058
"lazy": "1.0.11",
61-
"mocha-junit-reporter": "^1.13.0",
62-
"mocha-multi": "^0.11.0",
63-
"nativescript-dev-appium": "next",
64-
"nativescript-dev-typescript": "^0.4.0",
65-
"socket.io": "1.4.8",
66-
"socket.io-client": "1.4.8",
67-
"tslib": "^1.7.1",
6859
"tslint": "^4.5.1",
69-
"typescript": "~2.7.2",
70-
"mocha": "~3.5.0"
60+
"typescript": "~2.7.2"
7161
},
7262
"scripts": {
7363
"e2e": "tsc -p e2e && mocha --opts ../e2e/config/mocha.opts --recursive e2e --appiumCapsLocation ../e2e/config/appium.capabilities.json",
7464
"compile-tests-w": "tsc -p e2e --watch",
7565
"update-app-ng-deps": "update-app-ng-deps"
7666
}
77-
}
67+
}

Diff for: tests/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"*": [
1717
"./node_modules/tns-core-modules/*",
1818
"./node_modules/*"
19+
],
20+
"~/*": [
21+
"app/*"
1922
]
2023
}
2124
},

0 commit comments

Comments
 (0)