mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added test for binding context reload (when navigating) issue.
This commit is contained in:
@@ -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" />
|
||||
|
||||
1581
CrossPlatformModules.csproj.bak
Normal file
1581
CrossPlatformModules.csproj.bak
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
16
apps/tests/ui/bindingContext_testPage1.ts
Normal file
16
apps/tests/ui/bindingContext_testPage1.ts
Normal 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;
|
||||
}
|
||||
7
apps/tests/ui/bindingContext_testPage1.xml
Normal file
7
apps/tests/ui/bindingContext_testPage1.xml
Normal 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>
|
||||
6
apps/tests/ui/bindingContext_testPage2.ts
Normal file
6
apps/tests/ui/bindingContext_testPage2.ts
Normal 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;
|
||||
}
|
||||
5
apps/tests/ui/bindingContext_testPage2.xml
Normal file
5
apps/tests/ui/bindingContext_testPage2.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<Page navigatedTo="pageNavigatedTo">
|
||||
<StackLayout>
|
||||
<TextField id="testTextField" text="{{ testProperty }}" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user