@@ -504,6 +504,59 @@ describe('TextInput Tests', () => {
504
504
// Verify the textInput contents are cleared after regaining focus
505
505
expect ( await componentFocusTrue . getText ( ) ) . toBe ( '' ) ;
506
506
} ) ;
507
+ test ( 'TextInputs can select text on focus' , async ( ) => {
508
+ const component = await app . findElementByTestID ( 'select-text-on-focus' ) ;
509
+ await component . waitForDisplayed ( { timeout : 5000 } ) ;
510
+
511
+ await app . waitUntil (
512
+ async ( ) => {
513
+ await component . setValue ( 'Hello World' ) ;
514
+ return ( await component . getText ( ) ) === 'Hello World' ;
515
+ } ,
516
+ {
517
+ interval : 1500 ,
518
+ timeout : 5000 ,
519
+ timeoutMsg : `Unable to enter correct text.` ,
520
+ } ,
521
+ ) ;
522
+
523
+ // Check if the text is selected on focus.
524
+ await component . click ( ) ;
525
+
526
+ const dump = await dumpVisualTree ( 'select-text-on-focus' ) ;
527
+ expect ( dump ) . toMatchSnapshot ( ) ;
528
+ } ) ;
529
+ test ( 'TextInputs can clear text on focus even if selectTextOnFocus == true' , async ( ) => {
530
+ const targetComponent = await app . findElementByTestID (
531
+ 'select-text-on-focus-while-clear-text-on-focus' ,
532
+ ) ;
533
+ await targetComponent . waitForDisplayed ( { timeout : 5000 } ) ;
534
+
535
+ await app . waitUntil (
536
+ async ( ) => {
537
+ await targetComponent . setValue ( 'Hello World' ) ;
538
+ return ( await targetComponent . getText ( ) ) === 'Hello World' ;
539
+ } ,
540
+ {
541
+ interval : 1500 ,
542
+ timeout : 5000 ,
543
+ timeoutMsg : `Unable to enter correct text.` ,
544
+ } ,
545
+ ) ;
546
+
547
+ // Click on the previous textInput to move focus away from this TextInput
548
+ const anotherTextInput = await app . findElementByTestID (
549
+ 'select-text-on-focus' ,
550
+ ) ;
551
+ await anotherTextInput . waitForDisplayed ( { timeout : 5000 } ) ;
552
+ await anotherTextInput . click ( ) ;
553
+
554
+ // Now click on the tested component, make sure the text is cleared.
555
+ await targetComponent . click ( ) ;
556
+
557
+ // Verify the textInput contents are cleared after regaining focus
558
+ expect ( await targetComponent . getText ( ) ) . toBe ( '' ) ;
559
+ } ) ;
507
560
test ( 'TextInputs can have inline images' , async ( ) => {
508
561
const component = await app . findElementByTestID ( 'textinput-inline-images' ) ;
509
562
await component . waitForDisplayed ( { timeout : 5000 } ) ;
0 commit comments