diff --git a/tests/app/ui/bindable-tests.ts b/tests/app/ui/bindable-tests.ts index 6c0d12ae1..cb6ec7398 100644 --- a/tests/app/ui/bindable-tests.ts +++ b/tests/app/ui/bindable-tests.ts @@ -1,20 +1,21 @@ -import * as observable from "data/observable"; -import * as bindable from "ui/core/bindable"; -import * as dependencyObservableModule from "ui/core/dependency-observable"; +import { Observable, fromObjectRecursive } from "data/observable"; +import { ViewBase } from "ui/core/view-base"; +import { BindingOptions } from "ui/core/bindable"; + import * as TKUnit from "../TKUnit"; import * as types from "utils/types"; import * as helper from "../ui/helper"; -import * as viewModule from "ui/core/view"; -import * as buttonModule from "ui/button"; import * as utils from "utils/utils"; -import * as pageModule from "ui/page"; -import * as stackLayoutModule from "ui/layouts/stack-layout"; import * as bindingBuilder from "ui/builder/binding-builder"; -import * as labelModule from "ui/label"; -import * as textFieldModule from "ui/text-field"; import * as fs from "file-system"; import * as appModule from "application"; import * as trace from "trace"; +import { View } from "ui/core/view"; +import { Button } from "ui/button"; +import { Page } from "ui/page"; +import { StackLayout } from "ui/layouts/stack-layout"; +import { Label } from "ui/label"; +import { TextField } from "ui/text-field"; // // For information and examples how to use bindings please refer to special [**Data binding**](../../../../bindings.md) topic. @@ -24,22 +25,22 @@ import * as trace from "trace"; // For information and example how to use weak event listeners please refer to special [**Events**](../../../../events.md) topic which has a dedicated part about weak event listeners. // -export var test_Bindable_Members = function () { - var obj = new bindable.Bindable(); +export function test_Bindable_Members() { + const obj = new ViewBase(); TKUnit.assert(types.isDefined(obj.bind), "Bindable.bind not defined"); TKUnit.assert(types.isDefined(obj.unbind), "Bindable.unbind not defined"); -} +}; -export var test_Bindable_Bind_ToTarget_OneWay = function () { - var model = new observable.Observable(); +export function test_Bindable_Bind_ToTarget_OneWay() { + const model = new Observable(); model.set("name", "John"); - var options: bindable.BindingOptions = { + const options: BindingOptions = { sourceProperty: "name", targetProperty: "test" - } + }; - var obj = new bindable.Bindable(); + const obj = new ViewBase(); obj.bind(options, model); TKUnit.assert(obj.get("test") === "John", "Expected result after binding is [test value] === 'John'"); @@ -47,78 +48,78 @@ export var test_Bindable_Bind_ToTarget_OneWay = function () { model.set("name", "Changed"); TKUnit.assert(obj.get("test") === "Changed", "Expected result after binding is [test value] === 'Changed'"); -} +}; -export var test_Bindable_Bind_ToTarget_TwoWay = function () { - var model = new observable.Observable(); +export function test_Bindable_Bind_ToTarget_TwoWay() { + const model = new Observable(); model.set("name", "John"); - var options: bindable.BindingOptions = { + const options: BindingOptions = { sourceProperty: "name", targetProperty: "test", twoWay: true - } + }; - var obj = new bindable.Bindable(); + const obj = new ViewBase(); obj.bind(options, model); obj.set("test", "Changed"); - TKUnit.assert(model.get("name") === "Changed", "Two-way binding not updating the source when target is changed."); + TKUnit.assertEqual(model.get("name"), "Changed", "Two-way binding not updating the source when target is changed."); model.set("name", "John"); - TKUnit.assert(obj.get("test") === "John", "Two-way binding not updating the target when source is changed."); -} + TKUnit.assertEqual(obj.get("test"), "John", "Two-way binding not updating the target when source is changed."); +}; -export var test_Bindable_Bind_ToBindingContext_OneWay = function () { - var model = new observable.Observable(); +export function test_Bindable_Bind_ToBindingContext_OneWay() { + const model = new Observable(); model.set("name", "John"); - var options: bindable.BindingOptions = { + const options: BindingOptions = { sourceProperty: "name", targetProperty: "test" - } + }; - var obj = new bindable.Bindable(); + const obj = new ViewBase(); obj.bind(options); obj.set("test", "local"); obj.bindingContext = model; TKUnit.assert(obj.get("test") === "John", "Binding to a context does not update the target property."); -} +}; -export var test_Bindable_Bind_ToBindingContext_TwoWay = function () { - var model = new observable.Observable(); +export function test_Bindable_Bind_ToBindingContext_TwoWay() { + const model = new Observable(); model.set("name", "John"); - var options: bindable.BindingOptions = { + const options: BindingOptions = { sourceProperty: "name", targetProperty: "test", twoWay: true - } + }; - var obj = new bindable.Bindable(); + const obj = new ViewBase(); obj.bind(options); obj.set("test", "local"); obj.bindingContext = model; - TKUnit.assert(obj.get("test") === "John", "Binding to a context does not update the target property."); + TKUnit.assertEqual(obj.get("test"), "John", "Binding to a context does not update the target property."); obj.set("test", "local"); - TKUnit.assert(model.get("name") === "local", "Two-way binding to a context does not update the source property."); -} + TKUnit.assertEqual(model.get("name"), "local", "Two-way binding to a context does not update the source property."); +}; -export var test_Bindable_Unbind = function () { - var model = new observable.Observable(); +export function test_Bindable_Unbind() { + const model = new Observable(); - var options: bindable.BindingOptions = { + const options: BindingOptions = { sourceProperty: "name", targetProperty: "test" - } + }; - var obj = new bindable.Bindable(); + const obj = new ViewBase(); obj.bind(options, model); model.set("name", "John"); @@ -126,50 +127,50 @@ export var test_Bindable_Unbind = function () { TKUnit.assert(obj.get("test") === "John", "Binding does not updates target property."); obj.unbind("test"); - model.set("name", "Chaged"); + model.set("name", "Changed"); TKUnit.assert(obj.get("test") === "John", "Unbind does not remove binding."); -} +}; -export var test_bind_NoSource_WillUse_BindingContext = function () { - var model = new observable.Observable(); +export function test_bind_NoSource_WillUse_BindingContext() { + const model = new Observable(); model.set("testProperty", "testValue"); - var test = function (views: Array) { + const test = function (views: Array) { views[0].bindingContext = model; views[1].bind({ sourceProperty: "testProperty", targetProperty: "text" }); - var button = views[1]; - TKUnit.assert(button.text === model.get("testProperty"), "Bind method not working when no source is passed but a valid bindingContext is present."); - } + const button =