Skip to content

Commit 96c638e

Browse files
committed
Tests added
1 parent eac9515 commit 96c638e

File tree

7 files changed

+169
-8
lines changed

7 files changed

+169
-8
lines changed

CrossPlatformModules.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<DependentUpon>modal-page.xml</DependentUpon>
9090
</TypeScriptCompile>
9191
<TypeScriptCompile Include="apps\tests\ui\placeholder\placeholder-tests.ts" />
92+
<TypeScriptCompile Include="apps\tests\ui\proxy-view-container\proxy-view-container-tests.ts" />
9293
<TypeScriptCompile Include="apps\tests\ui\tab-view\tab-view-navigation-tests.ts" />
9394
<TypeScriptCompile Include="apps\tests\xml-declaration\custom-code-file.ts" />
9495
<TypeScriptCompile Include="apps\transforms\app.ts" />
@@ -726,8 +727,8 @@
726727
<TypeScriptCompile Include="ui\builder\binding-builder.d.ts" />
727728
<TypeScriptCompile Include="ui\builder\special-properties.d.ts" />
728729
<TypeScriptCompile Include="ui\builder\special-properties.ts" />
729-
<TypeScriptCompile Include="ui\view-container\view-container.ts" />
730-
<TypeScriptCompile Include="ui\view-container\view-container.d.ts" />
730+
<TypeScriptCompile Include="ui\proxy-view-container\proxy-view-container.d.ts" />
731+
<TypeScriptCompile Include="ui\proxy-view-container\proxy-view-container.ts" />
731732
<TypeScriptCompile Include="ui\styling\background.android.d.ts" />
732733
<TypeScriptCompile Include="ui\styling\style-scope.d.ts" />
733734
<TypeScriptCompile Include="ui\styling\style.d.ts" />
@@ -2089,9 +2090,7 @@
20892090
</Content>
20902091
<Content Include="ui\package.json" />
20912092
<Content Include="tsconfig.json" />
2092-
<Content Include="ui\view-container\package.json">
2093-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2094-
</Content>
2093+
<Content Include="ui\proxy-view-container\package.json" />
20952094
</ItemGroup>
20962095
<ItemGroup>
20972096
<None Include="build\tslint.json" />
@@ -2154,7 +2153,7 @@
21542153
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
21552154
</WebProjectProperties>
21562155
</FlavorProperties>
2157-
<UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
2156+
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" />
21582157
</VisualStudio>
21592158
</ProjectExtensions>
21602159
</Project>

apps/tests/testRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function isRunningOnEmulator(): boolean {
2525
}
2626

2727
export var allTests = {};
28+
allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-tests")
2829
allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests");
2930
allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests");
3031
allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import TKUnit = require("../../TKUnit");
2+
import helper = require("../helper");
3+
import viewModule = require("ui/core/view");
4+
import observable = require("data/observable");
5+
import color = require("color");
6+
import platform = require("platform");
7+
8+
import {ProxyViewContainer} from "ui/proxy-view-container";
9+
import {View, Button, StackLayout} from "ui";
10+
11+
export function test_add_children_to_attached_proxy() {
12+
var outer = new StackLayout();
13+
var proxy = new ProxyViewContainer();
14+
15+
function testAction(views: Array<viewModule.View>) {
16+
outer.addChild(createBtn("1"));
17+
outer.addChild(proxy);
18+
proxy.addChild(createBtn("2"));
19+
proxy.addChild(createBtn("3"));
20+
proxy.addChild(createBtn("4"));
21+
22+
outer.addChild(createBtn("5"));
23+
24+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
25+
};
26+
27+
helper.buildUIAndRunTest(outer, testAction);
28+
}
29+
30+
export function test_add_children_to_detached_proxy() {
31+
var outer = new StackLayout();
32+
var proxy = new ProxyViewContainer();
33+
34+
function testAction(views: Array<viewModule.View>) {
35+
outer.addChild(createBtn("1"));
36+
37+
proxy.addChild(createBtn("2"));
38+
proxy.addChild(createBtn("3"));
39+
proxy.addChild(createBtn("4"));
40+
outer.addChild(proxy);
41+
42+
outer.addChild(createBtn("5"));
43+
44+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
45+
};
46+
47+
helper.buildUIAndRunTest(outer, testAction);
48+
}
49+
50+
export function test_remove_proxy() {
51+
var outer = new StackLayout();
52+
var proxy = new ProxyViewContainer();
53+
54+
outer.addChild(createBtn("1"));
55+
56+
outer.addChild(proxy);
57+
proxy.addChild(createBtn("2"));
58+
proxy.addChild(createBtn("3"));
59+
proxy.addChild(createBtn("4"));
60+
61+
outer.addChild(createBtn("5"));
62+
63+
function testAction(views: Array<viewModule.View>) {
64+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
65+
outer.removeChild(proxy);
66+
assertNativeChildren(outer, ["1", "5"]);
67+
};
68+
69+
helper.buildUIAndRunTest(outer, testAction);
70+
}
71+
72+
export function test_remove_child_of_attached_proxy() {
73+
var outer = new StackLayout();
74+
var proxy = new ProxyViewContainer();
75+
76+
outer.addChild(createBtn("1"));
77+
78+
outer.addChild(proxy);
79+
proxy.addChild(createBtn("2"));
80+
var testBtn = createBtn("3")
81+
proxy.addChild(testBtn);
82+
proxy.addChild(createBtn("4"));
83+
84+
outer.addChild(createBtn("5"));
85+
86+
function testAction(views: Array<viewModule.View>) {
87+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
88+
proxy.removeChild(testBtn);
89+
assertNativeChildren(outer, ["1", "2", "4", "5"]);
90+
};
91+
92+
helper.buildUIAndRunTest(outer, testAction);
93+
}
94+
95+
export function test_insert_inside_porxy() {
96+
var outer = new StackLayout();
97+
var proxy = new ProxyViewContainer();
98+
99+
outer.addChild(createBtn("1"));
100+
101+
outer.addChild(proxy);
102+
proxy.addChild(createBtn("2"));
103+
proxy.addChild(createBtn("4"));
104+
105+
outer.addChild(createBtn("5"));
106+
107+
function testAction(views: Array<viewModule.View>) {
108+
assertNativeChildren(outer, ["1", "2", "4", "5"]);
109+
proxy.insertChild(createBtn("3"), 1);
110+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
111+
};
112+
113+
helper.buildUIAndRunTest(outer, testAction);
114+
}
115+
116+
export function test_insert_after_porxy() {
117+
var outer = new StackLayout();
118+
var proxy = new ProxyViewContainer();
119+
120+
outer.addChild(createBtn("1"));
121+
122+
outer.addChild(proxy);
123+
proxy.addChild(createBtn("2"));
124+
proxy.addChild(createBtn("3"));
125+
proxy.addChild(createBtn("4"));
126+
127+
function testAction(views: Array<viewModule.View>) {
128+
assertNativeChildren(outer, ["1", "2", "3", "4"]);
129+
outer.insertChild(createBtn("5"), 2);
130+
assertNativeChildren(outer, ["1", "2", "3", "4", "5"]);
131+
};
132+
133+
helper.buildUIAndRunTest(outer, testAction);
134+
}
135+
136+
function createBtn(text: string): Button {
137+
var b = new Button();
138+
b.text = text;
139+
return b;
140+
}
141+
142+
function assertNativeChildren(stack: StackLayout, arr: Array<string>) {
143+
if (stack.android) {
144+
let android: org.nativescript.widgets.StackLayout = stack.android;
145+
TKUnit.assertEqual(android.getChildCount(), arr.length, "Native children");
146+
for (let i = 0; i < arr.length; i++) {
147+
let nativeBtn = <android.widget.Button>android.getChildAt(i);
148+
TKUnit.assertEqual(nativeBtn.getText(), arr[i]);
149+
}
150+
} else if (stack.ios) {
151+
let ios: UIView = stack.ios;
152+
TKUnit.assertEqual(ios.subviews.count, arr.length, "Native children");
153+
for (let i = 0; i < arr.length; i++) {
154+
let nativeBtn = <UIButton>ios.subviews[i];
155+
TKUnit.assertEqual(nativeBtn.titleLabel.text, arr[i]);
156+
}
157+
} else {
158+
TKUnit.assert(false, "No native view to assert");
159+
}
160+
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
"apps/tests/ui/page/test-page-module.ts",
266266
"apps/tests/ui/placeholder/placeholder-tests.ts",
267267
"apps/tests/ui/progress/progress-tests.ts",
268+
"apps/tests/ui/proxy-view-container/proxy-view-container-tests.ts",
268269
"apps/tests/ui/repeater/repeater-tests.ts",
269270
"apps/tests/ui/repeater/repeaterItems-bindingToGestures.ts",
270271
"apps/tests/ui/scroll-view/scroll-view-tests.ts",
@@ -594,6 +595,8 @@
594595
"ui/progress/progress.android.ts",
595596
"ui/progress/progress.d.ts",
596597
"ui/progress/progress.ios.ts",
598+
"ui/proxy-view-container/proxy-view-container.d.ts",
599+
"ui/proxy-view-container/proxy-view-container.ts",
597600
"ui/repeater/repeater.d.ts",
598601
"ui/repeater/repeater.ts",
599602
"ui/scroll-view/scroll-view-common.ts",
@@ -664,8 +667,6 @@
664667
"ui/ui.ts",
665668
"ui/utils.d.ts",
666669
"ui/utils.ios.ts",
667-
"ui/view-container/proxy-view-container.d.ts",
668-
"ui/view-container/proxy-view-container.ts",
669670
"ui/web-view/web-view-common.ts",
670671
"ui/web-view/web-view.android.ts",
671672
"ui/web-view/web-view.d.ts",
File renamed without changes.

0 commit comments

Comments
 (0)