@@ -5,9 +5,9 @@ import { Page } from "@nativescript/core/ui/page";
55import { StackLayout } from "@nativescript/core/ui/layouts/stack-layout" ;
66import { Color } from "@nativescript/core/color" ;
77import {
8- getNativeText , getNativeHint , typeTextNatively , getNativeSecure ,
8+ getNativeText , getNativeHint , typeTextNatively , typeTextNativelyWithReturn , getNativeSecure ,
99 getNativeFontSize , getNativeColor , getNativeBackgroundColor ,
10- getNativeTextAlignment , getNativePlaceholderColor
10+ getNativeTextAlignment , getNativePlaceholderColor , getNativeFocus
1111} from "./text-field-tests-native" ;
1212import { FormattedString } from "@nativescript/core/text/formatted-string" ;
1313import { Span } from "@nativescript/core/text/span" ;
@@ -400,6 +400,100 @@ export var testBindSecureToBindingConext = function () {
400400 } ) ;
401401} ;
402402
403+ // iOS only
404+ export var testBindCloseOnReturnToBindingConext = function ( ) {
405+ helper . buildUIAndRunTest ( _createTextFieldFunc ( ) , function ( views : Array < View > ) {
406+ if ( ! isIOS ) {
407+ TKUnit . assert ( true === true ) ;
408+
409+ return ;
410+ }
411+ var textField = < TextField > views [ 0 ] ;
412+ var page = < Page > views [ 1 ] ;
413+
414+ var model = new Observable ( ) ;
415+ model . set ( "closeOnReturn" , false ) ;
416+ page . bindingContext = model ;
417+
418+ var options : BindingOptions = {
419+ sourceProperty : "closeOnReturn" ,
420+ targetProperty : "closeOnReturn"
421+ } ;
422+
423+ textField . bind ( options ) ;
424+ TKUnit . assert ( textField . closeOnReturn === false , "Actual: " + textField . closeOnReturn + "; Expected: " + false ) ;
425+ typeTextNativelyWithReturn ( textField , "Should not close textfield" ) ;
426+ TKUnit . assert ( getNativeFocus ( textField ) === true , "Actual: " + getNativeFocus ( textField ) + "; Expected: " + true ) ;
427+
428+ model . set ( "closeOnReturn" , true ) ;
429+ TKUnit . assert ( textField . closeOnReturn === true , "Actual: " + textField . closeOnReturn + "; Expected: " + true ) ;
430+ typeTextNativelyWithReturn ( textField , "Should close textfield" ) ;
431+ TKUnit . assert ( getNativeFocus ( textField ) === false , "Actual: " + getNativeFocus ( textField ) + "; Expected: " + false ) ;
432+ } ) ;
433+ } ;
434+
435+ // iOS only
436+ export var testDontCloseOnReturn = function ( ) {
437+ helper . buildUIAndRunTest ( _createTextFieldFunc ( ) , function ( views : Array < View > ) {
438+ if ( ! isIOS ) {
439+ TKUnit . assert ( true === true ) ;
440+
441+ return ;
442+ }
443+ var textField = < TextField > views [ 0 ] ;
444+
445+ // >> setting-closeOnReturn-property
446+ textField . closeOnReturn = false ;
447+ // << setting-closeOnReturn-property
448+
449+ typeTextNativelyWithReturn ( textField , "Should not close textfield" ) ;
450+
451+ var expectedValue = true ;
452+ var actualValue = getNativeFocus ( textField ) ;
453+ TKUnit . assert ( actualValue === expectedValue , "Actual: " + actualValue + "; Expected: " + expectedValue ) ;
454+ } ) ;
455+ } ;
456+
457+ // iOS only
458+ export var testCloseOnReturn = function ( ) {
459+ helper . buildUIAndRunTest ( _createTextFieldFunc ( ) , function ( views : Array < View > ) {
460+ if ( ! isIOS ) {
461+ TKUnit . assert ( true === true ) ;
462+
463+ return ;
464+ }
465+ var textField = < TextField > views [ 0 ] ;
466+
467+ // >> setting-closeOnReturn-property
468+ textField . closeOnReturn = true ;
469+ // << setting-closeOnReturn-property
470+
471+ typeTextNativelyWithReturn ( textField , "Should close textfield" ) ;
472+
473+ var expectedValue = false ;
474+ var actualValue = getNativeFocus ( textField ) ;
475+ TKUnit . assert ( actualValue === expectedValue , "Actual: " + actualValue + "; Expected: " + expectedValue ) ;
476+ } ) ;
477+ } ;
478+
479+ // iOS only
480+ export var testCloseOnReturnByDefault = function ( ) {
481+ helper . buildUIAndRunTest ( _createTextFieldFunc ( ) , function ( views : Array < View > ) {
482+ if ( ! isIOS ) {
483+ TKUnit . assert ( true === true ) ;
484+
485+ return ;
486+ }
487+ var textField = < TextField > views [ 0 ] ;
488+
489+ typeTextNativelyWithReturn ( textField , "Should close textfield by default" ) ;
490+
491+ var expectedValue = false ;
492+ var actualValue = getNativeFocus ( textField ) ;
493+ TKUnit . assert ( actualValue === expectedValue , "Actual: " + actualValue + "; Expected: " + expectedValue ) ;
494+ } ) ;
495+ } ;
496+
403497var expectedFontSize = 42 ;
404498export var testLocalFontSizeFromCss = function ( ) {
405499 helper . buildUIAndRunTest ( _createTextFieldFunc ( ) , function ( views : Array < View > ) {
0 commit comments