mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #369 from NativeScript/nnikolov/BindingIssues
Introduced parent and parents keywords for binding.
This commit is contained in:
@@ -465,6 +465,39 @@ export var test_getBindableOptionsFromStringTwoParamsNamedFormat = function () {
|
||||
TKUnit.assert(bindOptions.twoWay === true, "Expected: true, Actual: " + bindOptions.twoWay);
|
||||
}
|
||||
|
||||
export var test_getBindingOptionsFromStringWithFunctionWitnMoreParams = function () {
|
||||
var bindingExpression = "bindProperty, converter(bindProperty, param1)";
|
||||
var bindOptions = bindingBuilder.getBindingOptions("targetBindProperty", bindingExpression);
|
||||
|
||||
TKUnit.assertEqual(bindOptions.sourceProperty, "bindProperty");
|
||||
TKUnit.assertEqual(bindOptions.targetProperty, "targetBindProperty");
|
||||
TKUnit.assertEqual(bindOptions.expression, "converter(bindProperty, param1)");
|
||||
TKUnit.assertEqual(bindOptions.twoWay, true);
|
||||
}
|
||||
|
||||
export var test_getBindingOptionsFromStringWithFunctionArrayParams = function () {
|
||||
var bindingExpression = "bindProperty, converter(bindProperty, [param1, param2])";
|
||||
var bindOptions = bindingBuilder.getBindingOptions("targetBindProperty", bindingExpression);
|
||||
|
||||
TKUnit.assertEqual(bindOptions.sourceProperty, "bindProperty");
|
||||
TKUnit.assertEqual(bindOptions.targetProperty, "targetBindProperty");
|
||||
TKUnit.assertEqual(bindOptions.expression, "converter(bindProperty, [param1, param2])");
|
||||
TKUnit.assertEqual(bindOptions.twoWay, true);
|
||||
}
|
||||
|
||||
export var test_bindingToNestedPropertyWithValueSyntax = function () {
|
||||
var bindingSource = new observable.Observable();
|
||||
bindingSource.set("testProperty", "testValue");
|
||||
|
||||
var testElement = new bindable.Bindable();
|
||||
testElement.bind({
|
||||
sourceProperty: "$value.testProperty",
|
||||
targetProperty: "targetPropertyName"
|
||||
}, bindingSource);
|
||||
|
||||
TKUnit.assertEqual(testElement.get("targetPropertyName"), "testValue");
|
||||
}
|
||||
|
||||
export var test_TwoElementsBindingToSameBindingContext = function () {
|
||||
var testFunc = function (page: pageModule.Page) {
|
||||
var upperStackLabel = <labelModule.Label>(page.getViewById("upperStackLabel"));
|
||||
|
||||
@@ -530,6 +530,56 @@ export function test_BindingListViewToASimpleArrayWithExpression() {
|
||||
helper.buildUIAndRunTest(listView, testAction);
|
||||
}
|
||||
|
||||
export function test_bindingToParentObject() {
|
||||
var listView = new listViewModule.ListView();
|
||||
var expectedValue = "parentTestValue";
|
||||
|
||||
function testAction(views: Array<viewModule.View>) {
|
||||
var listViewModel = new observable.Observable();
|
||||
listViewModel.set("items", [1, 2, 3]);
|
||||
listViewModel.set("parentTestProp", expectedValue);
|
||||
listView.bindingContext = listViewModel;
|
||||
listView.bind({ sourceProperty: "items", targetProperty: "items" });
|
||||
listView.itemTemplate = "<Label id=\"testLabel\" text=\"{{ sourceProperty = $parents[ListView].parentTestProp }}\" />";
|
||||
|
||||
TKUnit.wait(ASYNC);
|
||||
var firstNativeElementText = getTextFromNativeElementAt(listView, 0);
|
||||
var secondNativeElementText = getTextFromNativeElementAt(listView, 1);
|
||||
var thirdNativeElementText = getTextFromNativeElementAt(listView, 2);
|
||||
|
||||
TKUnit.assertEqual(firstNativeElementText, expectedValue, "first element text");
|
||||
TKUnit.assertEqual(secondNativeElementText, expectedValue, "second element text");
|
||||
TKUnit.assertEqual(thirdNativeElementText, expectedValue, "third element text");
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(listView, testAction);
|
||||
}
|
||||
|
||||
export function test_bindingToParentObjectWithSpacesInIndexer() {
|
||||
var listView = new listViewModule.ListView();
|
||||
var expectedValue = "parentTestValue";
|
||||
|
||||
function testAction(views: Array<viewModule.View>) {
|
||||
var listViewModel = new observable.Observable();
|
||||
listViewModel.set("items", [1, 2, 3]);
|
||||
listViewModel.set("parentTestProp", expectedValue);
|
||||
listView.bindingContext = listViewModel;
|
||||
listView.bind({ sourceProperty: "items", targetProperty: "items" });
|
||||
listView.itemTemplate = "<Label id=\"testLabel\" text=\"{{ sourceProperty = $parents[ ListView ].parentTestProp }}\" />";
|
||||
|
||||
TKUnit.wait(ASYNC);
|
||||
var firstNativeElementText = getTextFromNativeElementAt(listView, 0);
|
||||
var secondNativeElementText = getTextFromNativeElementAt(listView, 1);
|
||||
var thirdNativeElementText = getTextFromNativeElementAt(listView, 2);
|
||||
|
||||
TKUnit.assertEqual(firstNativeElementText, expectedValue, "first element text");
|
||||
TKUnit.assertEqual(secondNativeElementText, expectedValue, "second element text");
|
||||
TKUnit.assertEqual(thirdNativeElementText, expectedValue, "third element text");
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(listView, testAction);
|
||||
}
|
||||
|
||||
export function test_no_memory_leak_when_items_is_regular_array() {
|
||||
var createFunc = function (): listViewModule.ListView {
|
||||
var listView = new listViewModule.ListView();
|
||||
|
||||
Reference in New Issue
Block a user