mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Tests.
This commit is contained in:
@@ -8,8 +8,8 @@ export function getNativeText(textView: textViewModule.TextView): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeHint(textView: textViewModule.TextView): string {
|
export function getNativeHint(textView: textViewModule.TextView): string {
|
||||||
// There is no native hint
|
// There is no native hint so we use a hack and sett 22% opaque text.
|
||||||
if (textView.hint !== "") {
|
if ((<any>textView.ios).isShowingHint) {
|
||||||
return textView.ios.text;
|
return textView.ios.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ export var testTextIsUpdatedWhenUserTypes = function () {
|
|||||||
export var testSetHint = function () {
|
export var testSetHint = function () {
|
||||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
var textView = <textViewModule.TextView>views[0];
|
var textView = <textViewModule.TextView>views[0];
|
||||||
|
textView.text = "";
|
||||||
|
|
||||||
// <snippet module="ui/text-view" title="TextView">
|
// <snippet module="ui/text-view" title="TextView">
|
||||||
// ### Setting the hint of a TextView
|
// ### Setting the hint of a TextView
|
||||||
@@ -155,6 +156,7 @@ export var testSetHint = function () {
|
|||||||
export var testBindHintDirectlyToModel = function () {
|
export var testBindHintDirectlyToModel = function () {
|
||||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
var textView = <textViewModule.TextView>views[0];
|
var textView = <textViewModule.TextView>views[0];
|
||||||
|
textView.text = "";
|
||||||
|
|
||||||
// <snippet module="ui/text-view" title="TextView">
|
// <snippet module="ui/text-view" title="TextView">
|
||||||
// ### Binding hint property directly to model
|
// ### Binding hint property directly to model
|
||||||
@@ -168,13 +170,13 @@ export var testBindHintDirectlyToModel = function () {
|
|||||||
textView.bind(options, model);
|
textView.bind(options, model);
|
||||||
//// TextView.hint is now "type your username here"
|
//// TextView.hint is now "type your username here"
|
||||||
// <hide>
|
// <hide>
|
||||||
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");
|
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your username here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your username here");
|
||||||
// </hide>
|
// </hide>
|
||||||
model.set("hint", "type your password here");
|
model.set("hint", "type your password here");
|
||||||
//// TextView.hint is now "type your password here"
|
//// TextView.hint is now "type your password here"
|
||||||
// <hide>
|
// <hide>
|
||||||
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");
|
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your password here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your password here");
|
||||||
// </hide>
|
// </hide>
|
||||||
// ```
|
// ```
|
||||||
@@ -185,6 +187,7 @@ export var testBindHintDirectlyToModel = function () {
|
|||||||
export var testBindHintToBindingConext = function () {
|
export var testBindHintToBindingConext = function () {
|
||||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
var textView = <textViewModule.TextView>views[0];
|
var textView = <textViewModule.TextView>views[0];
|
||||||
|
textView.text = "";
|
||||||
var page = <pagesModule.Page>views[1];
|
var page = <pagesModule.Page>views[1];
|
||||||
|
|
||||||
var model = new observable.Observable();
|
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");
|
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");
|
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");
|
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<viewModule.View>) {
|
||||||
|
var textView = <textViewModule.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<viewModule.View>) {
|
||||||
|
var textView = <textViewModule.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 () {
|
export var testSetEditable = function () {
|
||||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
var textView = <textViewModule.TextView>views[0];
|
var textView = <textViewModule.TextView>views[0];
|
||||||
@@ -413,4 +466,4 @@ export var testMemoryLeak = function () {
|
|||||||
helper.buildUIWithWeakRefAndInteract(_createTextViewFunc, function (textView) {
|
helper.buildUIWithWeakRefAndInteract(_createTextViewFunc, function (textView) {
|
||||||
textViewTestsNative.typeTextNatively(textView, "Hello, world!");
|
textViewTestsNative.typeTextNatively(textView, "Hello, world!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._owner.dismissSoftInput();
|
this._owner.dismissSoftInput();
|
||||||
this._owner._refreshHintState(this._owner.hint);
|
this._owner._refreshHintState(this._owner.hint, textView.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidChange(textView: UITextView) {
|
public textViewDidChange(textView: UITextView) {
|
||||||
@@ -77,16 +77,16 @@ export class TextView extends common.TextView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
this._refreshHintState(data.newValue);
|
this._refreshHintState(data.newValue, this.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
super._onTextPropertyChanged(data);
|
super._onTextPropertyChanged(data);
|
||||||
this._refreshHintState(this.hint);
|
this._refreshHintState(this.hint, data.newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _refreshHintState(hint: string) {
|
public _refreshHintState(hint: string, text: string) {
|
||||||
if (hint && !this.ios.text) {
|
if (hint && !text) {
|
||||||
this._showHint(hint);
|
this._showHint(hint);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user