@@ -39,6 +39,7 @@ describe('IOSDevice', () => {
3939 longPress : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4040 swipe : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4141 pinch : vi . fn ( ) . mockResolvedValue ( undefined ) ,
42+ pasteText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4243 typeText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4344 clearActiveElement : vi . fn ( ) . mockResolvedValue ( true ) ,
4445 pressKey : vi . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -248,31 +249,42 @@ describe('IOSDevice', () => {
248249 expect ( mockWdaClient . tap ) . toHaveBeenNthCalledWith ( 1 , 10 , 20 ) ;
249250 expect ( mockWdaClient . tap ) . toHaveBeenNthCalledWith ( 2 , 30 , 40 ) ;
250251 expect ( mockWdaClient . clearActiveElement ) . toHaveBeenCalledTimes ( 2 ) ;
251- expect ( mockWdaClient . typeText ) . toHaveBeenNthCalledWith ( 1 , 'from action' , {
252- delayMs : 80 ,
253- } ) ;
254- expect ( mockWdaClient . typeText ) . toHaveBeenNthCalledWith (
252+ expect ( mockWdaClient . pasteText ) . toHaveBeenNthCalledWith ( 1 , 'from action' ) ;
253+ expect ( mockWdaClient . pasteText ) . toHaveBeenNthCalledWith (
255254 2 ,
256255 'from pointer' ,
257- { delayMs : 80 } ,
258256 ) ;
257+ expect ( mockWdaClient . typeText ) . not . toHaveBeenCalled ( ) ;
259258 } ) ;
260259
261- it ( 'forwards keyboardTypeDelay from per-call options to the WDA backend' , async ( ) => {
262- await device . inputPrimitives . keyboard . typeText ( 'per call' , {
263- autoDismissKeyboard : false ,
264- keyboardTypeDelay : 25 ,
265- } as any ) ;
260+ it ( 'forwards keyboardTypeDelay from per-call options when using type strategy' , async ( ) => {
261+ const deviceWithTypeStrategy = new IOSDevice ( {
262+ wdaPort : DEFAULT_WDA_PORT ,
263+ wdaHost : 'localhost' ,
264+ keyboardInputStrategy : 'type' ,
265+ } ) ;
266+
267+ await deviceWithTypeStrategy . inputPrimitives . keyboard . typeText (
268+ 'per call' ,
269+ {
270+ autoDismissKeyboard : false ,
271+ keyboardTypeDelay : 25 ,
272+ } as any ,
273+ ) ;
266274
267275 expect ( mockWdaClient . typeText ) . toHaveBeenLastCalledWith ( 'per call' , {
268276 delayMs : 25 ,
269277 } ) ;
278+ expect ( mockWdaClient . pasteText ) . not . toHaveBeenCalled ( ) ;
279+
280+ await deviceWithTypeStrategy . destroy ( ) ;
270281 } ) ;
271282
272- it ( 'falls back to device-level keyboardTypeDelay when the call omits it ' , async ( ) => {
283+ it ( 'falls back to device-level keyboardTypeDelay when using type strategy ' , async ( ) => {
273284 const deviceWithDelay = new IOSDevice ( {
274285 wdaPort : DEFAULT_WDA_PORT ,
275286 wdaHost : 'localhost' ,
287+ keyboardInputStrategy : 'type' ,
276288 keyboardTypeDelay : 0 ,
277289 } ) ;
278290
@@ -286,6 +298,21 @@ describe('IOSDevice', () => {
286298
287299 await deviceWithDelay . destroy ( ) ;
288300 } ) ;
301+
302+ it ( 'falls back to WDA typing when paste input is unavailable' , async ( ) => {
303+ mockWdaClient . pasteText = vi
304+ . fn ( )
305+ . mockRejectedValue ( new Error ( 'Paste not supported' ) ) ;
306+
307+ await device . inputPrimitives . keyboard . typeText ( 'fallback text' , {
308+ autoDismissKeyboard : false ,
309+ } as any ) ;
310+
311+ expect ( mockWdaClient . pasteText ) . toHaveBeenCalledWith ( 'fallback text' ) ;
312+ expect ( mockWdaClient . typeText ) . toHaveBeenLastCalledWith ( 'fallback text' , {
313+ delayMs : 80 ,
314+ } ) ;
315+ } ) ;
289316 } ) ;
290317
291318 describe ( 'Device Operations' , ( ) => {
@@ -427,13 +454,12 @@ describe('IOSDevice', () => {
427454 expect ( mockWdaClient . swipe ) . toHaveBeenCalledWith ( 100 , 200 , 300 , 400 , 500 ) ;
428455 } ) ;
429456
430- it ( 'should type text' , async ( ) => {
457+ it ( 'should paste text by default ' , async ( ) => {
431458 await device . connect ( ) ;
432459
433460 await getInternalTextInput ( device ) . typeText ( 'Hello World' ) ;
434- expect ( mockWdaClient . typeText ) . toHaveBeenCalledWith ( 'Hello World' , {
435- delayMs : 80 ,
436- } ) ;
461+ expect ( mockWdaClient . pasteText ) . toHaveBeenCalledWith ( 'Hello World' ) ;
462+ expect ( mockWdaClient . typeText ) . not . toHaveBeenCalled ( ) ;
437463 } ) ;
438464
439465 it ( 'should press home button' , async ( ) => {
@@ -566,6 +592,9 @@ describe('IOSDevice', () => {
566592
567593 it ( 'should handle text input failure' , async ( ) => {
568594 await device . connect ( ) ;
595+ mockWdaClient . pasteText = vi
596+ . fn ( )
597+ . mockRejectedValue ( new Error ( 'Paste text failed' ) ) ;
569598 mockWdaClient . typeText = vi
570599 . fn ( )
571600 . mockRejectedValue ( new Error ( 'Type text failed' ) ) ;
@@ -619,6 +648,7 @@ describe('IOSDevice', () => {
619648 const mockBackend = {
620649 ...mockWdaClient ,
621650 createSession : vi . fn ( ) . mockResolvedValue ( { sessionId : 'test-session' } ) ,
651+ pasteText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
622652 typeText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
623653 dismissKeyboard : vi
624654 . fn ( )
@@ -637,10 +667,9 @@ describe('IOSDevice', () => {
637667 await deviceWithAutoDismiss . connect ( ) ;
638668 await getInternalTextInput ( deviceWithAutoDismiss ) . typeText ( 'test text' ) ;
639669
640- // Should call typeText and swipe (for keyboard dismiss)
641- expect ( mockBackend . typeText ) . toHaveBeenCalledWith ( 'test text' , {
642- delayMs : 80 ,
643- } ) ;
670+ // Should call pasteText and swipe (for keyboard dismiss)
671+ expect ( mockBackend . pasteText ) . toHaveBeenCalledWith ( 'test text' ) ;
672+ expect ( mockBackend . typeText ) . not . toHaveBeenCalled ( ) ;
644673 expect ( mockBackend . swipe ) . toHaveBeenCalled ( ) ;
645674 } ) ;
646675 } ) ;
0 commit comments