Added test for binding context reload (when navigating) issue.

This commit is contained in:
Nedyalko Nikolov
2015-05-11 13:21:55 +03:00
parent a6d2fc6929
commit 0ef1e7a6ca
8 changed files with 1641 additions and 5 deletions

View File

@@ -140,6 +140,8 @@
<TypeScriptCompile Include="apps\tests\ui\bindingContext_testPage.ts">
<DependentUpon>bindingContext_testPage.xml</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="apps\tests\ui\bindingContext_testPage1.ts" />
<TypeScriptCompile Include="apps\tests\ui\bindingContext_testPage2.ts" />
<TypeScriptCompile Include="apps\tests\ui\time-picker\time-picker-tests-native.android.ts">
<DependentUpon>time-picker-tests-native.d.ts</DependentUpon>
</TypeScriptCompile>
@@ -597,6 +599,8 @@
<Content Include="apps\tests\app\location-example.xml" />
<Content Include="apps\tests\pages\page18.xml" />
<Content Include="apps\tests\ui\bindingContext_testPage.xml" />
<Content Include="apps\tests\ui\bindingContext_testPage1.xml" />
<Content Include="apps\tests\ui\bindingContext_testPage2.xml" />
<Content Include="apps\tests\ui\label\label-tests-wrong.css" />
<Content Include="apps\tests\pages\files\other.xml" />
<Content Include="apps\tests\pages\files\test.android.phone.xml" />

View File

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@ import pageModule = require("ui/page");
import stackLayoutModule = require("ui/layouts/stack-layout");
import bindingBuilder = require("ui/builder/binding-builder");
import labelModule = require("ui/label");
import textFieldModule = require("ui/text-field");
// <snippet module="ui/core/bindable" title="bindable">
// For information and examples how to use bindings please refer to special [**Data binding**](../../../../bindings.md) topic.
@@ -472,5 +473,21 @@ export var test_TwoElementsBindingToSameBindingContext = function () {
TKUnit.assertEqual(upperStackLabel.text, label2.text);
}
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage", testFunc);
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage", null, testFunc);
}
export var test_BindingContext_NavigatingForwardAndBack = function () {
var expectedValue = "Tralala";
var testFunc = function (page: pageModule.Page) {
var innerTestFunc = function (childPage: pageModule.Page) {
var testTextField: textFieldModule.TextField = <textFieldModule.TextField>(childPage.getViewById("testTextField"));
testTextField.text = expectedValue;
};
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage2", page.bindingContext, innerTestFunc);
var testLabel: labelModule.Label = <labelModule.Label>(page.getViewById("testLabel"));
TKUnit.assertEqual(testLabel.text, expectedValue);
}
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage1", null, testFunc);
}

View File

@@ -0,0 +1,16 @@
import frame = require("ui/frame");
import observable = require("data/observable");
import pageModule = require("ui/page");
function loadViewModel() {
viewModel.set("testProperty", "Alabala");
}
var viewModel = new observable.Observable();
loadViewModel();
export function pageLoaded(args: observable.EventData) {
var page = <pageModule.Page>args.object;
page.bindingContext = viewModel;
}

View File

@@ -0,0 +1,7 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<StackLayout>
<StackLayout>
<Label id="testLabel" text="{{ testProperty }}" />
</StackLayout>
</StackLayout>
</Page>

View File

@@ -0,0 +1,6 @@
import pageModule = require("ui/page");
export function pageNavigatedTo(args: pageModule.NavigatedData) {
var page = <pageModule.Page>args.object;
page.bindingContext = args.context;
}

View File

@@ -0,0 +1,5 @@
<Page navigatedTo="pageNavigatedTo">
<StackLayout>
<TextField id="testTextField" text="{{ testProperty }}" />
</StackLayout>
</Page>

View File

@@ -143,8 +143,8 @@ export function buildUIAndRunTest(controlToTest, testFunction, pageCss?) {
}
}
export function navigateToModuleAndRunTest(moduleName, testFunction) {
navigateToModule(moduleName);
export function navigateToModuleAndRunTest(moduleName, context, testFunction) {
navigateToModule(moduleName, context);
try {
testFunction(frame.topmost().currentPage);
}
@@ -201,9 +201,9 @@ export function navigate(pageFactory: () => page.Page) {
TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
}
export function navigateToModule(moduleName: string) {
export function navigateToModule(moduleName: string, context?: any) {
var currentPage = frame.topmost().currentPage;
frame.topmost().navigate({ moduleName: moduleName, animated: false });
frame.topmost().navigate({ moduleName: moduleName, context: context, animated: false });
TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
TKUnit.assert(frame.topmost().currentPage.isLoaded, "Current page should be loaded!");
}