From f6a92d85a4a3d1af0a74c965556e4b01f0a69374 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Wed, 20 May 2015 16:45:02 +0300 Subject: [PATCH] Tests. --- .../text-view/text-view-tests-native.ios.ts | 4 +- apps/tests/ui/text-view/text-view-tests.ts | 61 +++++++++++++++++-- ui/text-view/text-view.ios.ts | 10 +-- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/apps/tests/ui/text-view/text-view-tests-native.ios.ts b/apps/tests/ui/text-view/text-view-tests-native.ios.ts index e815afcc3..8393ddf81 100644 --- a/apps/tests/ui/text-view/text-view-tests-native.ios.ts +++ b/apps/tests/ui/text-view/text-view-tests-native.ios.ts @@ -8,8 +8,8 @@ export function getNativeText(textView: textViewModule.TextView): string { } export function getNativeHint(textView: textViewModule.TextView): string { - // There is no native hint - if (textView.hint !== "") { + // There is no native hint so we use a hack and sett 22% opaque text. + if ((textView.ios).isShowingHint) { return textView.ios.text; } diff --git a/apps/tests/ui/text-view/text-view-tests.ts b/apps/tests/ui/text-view/text-view-tests.ts index b47a412d1..6ee4b5957 100644 --- a/apps/tests/ui/text-view/text-view-tests.ts +++ b/apps/tests/ui/text-view/text-view-tests.ts @@ -138,6 +138,7 @@ export var testTextIsUpdatedWhenUserTypes = function () { export var testSetHint = function () { helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { var textView = views[0]; + textView.text = ""; // // ### Setting the hint of a TextView @@ -155,6 +156,7 @@ export var testSetHint = function () { export var testBindHintDirectlyToModel = function () { helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { var textView = views[0]; + textView.text = ""; // // ### Binding hint property directly to model @@ -168,13 +170,13 @@ export var testBindHintDirectlyToModel = function () { textView.bind(options, model); //// TextView.hint is now "type your username here" // - TKUnit.assert(textView.hint === "type your username here", "Actual: " + textView.text + "; Expected: " + "type your username here"); + TKUnit.assert(textView.hint === "type your username here", "Actual: " + textView.hint + "; Expected: " + "type your username here"); TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your username here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your username here"); // model.set("hint", "type your password here"); //// TextView.hint is now "type your password here" // - TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.text + "; Expected: " + "type your password here"); + TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.hint + "; Expected: " + "type your password here"); TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your password here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your password here"); // // ``` @@ -185,6 +187,7 @@ export var testBindHintDirectlyToModel = function () { export var testBindHintToBindingConext = function () { helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { var textView = views[0]; + textView.text = ""; var page = views[1]; var model = new observable.Observable(); @@ -201,11 +204,61 @@ export var testBindHintToBindingConext = function () { TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your username here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your username here"); model.set("hint", "type your password here"); - TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.text + "; Expected: " + "type your password here"); + TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.hint + "; Expected: " + "type your password here"); TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your password here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your password here"); }); } +export var testHintPlusTextiOS = function () { + helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { + var textView = views[0]; + if (!textView.ios) { + return; + } + + var expectedValue; + var actualValue; + + textView.hint = "hint"; + textView.text = "text"; + + expectedValue = "text"; + actualValue = textViewTestsNative.getNativeText(textView); + TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + + textView.text = ""; + expectedValue = "hint"; + actualValue = textViewTestsNative.getNativeText(textView); + TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + }); +} + +export var testHintColoriOS = function () { + helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { + var textView = views[0]; + if (!textView.ios) { + return; + } + + textView.text = ""; + textView.color = new colorModule.Color("red"); + textView.hint = "hint"; + + var expectedValue; + var actualValue; + + expectedValue = "#38.1999948ff0000"; // 22% red + actualValue = textViewTestsNative.getNativeColor(textView).hex; + TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + + textView.text = "text"; + + expectedValue = "#ffff0000"; // red + actualValue = textViewTestsNative.getNativeColor(textView).hex; + TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + }); +} + export var testSetEditable = function () { helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array) { var textView = views[0]; @@ -413,4 +466,4 @@ export var testMemoryLeak = function () { helper.buildUIWithWeakRefAndInteract(_createTextViewFunc, function (textView) { textViewTestsNative.typeTextNatively(textView, "Hello, world!"); }); -} +} \ No newline at end of file diff --git a/ui/text-view/text-view.ios.ts b/ui/text-view/text-view.ios.ts index cdae529ef..fbe5a59b5 100644 --- a/ui/text-view/text-view.ios.ts +++ b/ui/text-view/text-view.ios.ts @@ -32,7 +32,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate { } this._owner.dismissSoftInput(); - this._owner._refreshHintState(this._owner.hint); + this._owner._refreshHintState(this._owner.hint, textView.text); } public textViewDidChange(textView: UITextView) { @@ -77,16 +77,16 @@ export class TextView extends common.TextView { } public _onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) { - this._refreshHintState(data.newValue); + this._refreshHintState(data.newValue, this.text); } public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) { super._onTextPropertyChanged(data); - this._refreshHintState(this.hint); + this._refreshHintState(this.hint, data.newValue); } - public _refreshHintState(hint: string) { - if (hint && !this.ios.text) { + public _refreshHintState(hint: string, text: string) { + if (hint && !text) { this._showHint(hint); } else {