@@ -32,6 +32,7 @@ describe('IOSDevice', () => {
3232 longPress : vi . fn ( ) . mockResolvedValue ( undefined ) ,
3333 swipe : vi . fn ( ) . mockResolvedValue ( undefined ) ,
3434 pinch : vi . fn ( ) . mockResolvedValue ( undefined ) ,
35+ pasteText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
3536 typeText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
3637 clearActiveElement : vi . fn ( ) . mockResolvedValue ( true ) ,
3738 pressKey : vi . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -236,31 +237,42 @@ describe('IOSDevice', () => {
236237 expect ( mockWdaClient . tap ) . toHaveBeenNthCalledWith ( 1 , 10 , 20 ) ;
237238 expect ( mockWdaClient . tap ) . toHaveBeenNthCalledWith ( 2 , 30 , 40 ) ;
238239 expect ( mockWdaClient . clearActiveElement ) . toHaveBeenCalledTimes ( 2 ) ;
239- expect ( mockWdaClient . typeText ) . toHaveBeenNthCalledWith ( 1 , 'from action' , {
240- delayMs : 80 ,
241- } ) ;
242- expect ( mockWdaClient . typeText ) . toHaveBeenNthCalledWith (
240+ expect ( mockWdaClient . pasteText ) . toHaveBeenNthCalledWith ( 1 , 'from action' ) ;
241+ expect ( mockWdaClient . pasteText ) . toHaveBeenNthCalledWith (
243242 2 ,
244243 'from pointer' ,
245- { delayMs : 80 } ,
246244 ) ;
245+ expect ( mockWdaClient . typeText ) . not . toHaveBeenCalled ( ) ;
247246 } ) ;
248247
249- it ( 'forwards keyboardTypeDelay from per-call options to the WDA backend' , async ( ) => {
250- await device . inputPrimitives . keyboard . typeText ( 'per call' , {
251- autoDismissKeyboard : false ,
252- keyboardTypeDelay : 25 ,
253- } as any ) ;
248+ it ( 'forwards keyboardTypeDelay from per-call options when using type strategy' , async ( ) => {
249+ const deviceWithTypeStrategy = new IOSDevice ( {
250+ wdaPort : DEFAULT_WDA_PORT ,
251+ wdaHost : 'localhost' ,
252+ keyboardInputStrategy : 'type' ,
253+ } ) ;
254+
255+ await deviceWithTypeStrategy . inputPrimitives . keyboard . typeText (
256+ 'per call' ,
257+ {
258+ autoDismissKeyboard : false ,
259+ keyboardTypeDelay : 25 ,
260+ } as any ,
261+ ) ;
254262
255263 expect ( mockWdaClient . typeText ) . toHaveBeenLastCalledWith ( 'per call' , {
256264 delayMs : 25 ,
257265 } ) ;
266+ expect ( mockWdaClient . pasteText ) . not . toHaveBeenCalled ( ) ;
267+
268+ await deviceWithTypeStrategy . destroy ( ) ;
258269 } ) ;
259270
260- it ( 'falls back to device-level keyboardTypeDelay when the call omits it ' , async ( ) => {
271+ it ( 'falls back to device-level keyboardTypeDelay when using type strategy ' , async ( ) => {
261272 const deviceWithDelay = new IOSDevice ( {
262273 wdaPort : DEFAULT_WDA_PORT ,
263274 wdaHost : 'localhost' ,
275+ keyboardInputStrategy : 'type' ,
264276 keyboardTypeDelay : 0 ,
265277 } ) ;
266278
@@ -274,6 +286,21 @@ describe('IOSDevice', () => {
274286
275287 await deviceWithDelay . destroy ( ) ;
276288 } ) ;
289+
290+ it ( 'falls back to WDA typing when paste input is unavailable' , async ( ) => {
291+ mockWdaClient . pasteText = vi
292+ . fn ( )
293+ . mockRejectedValue ( new Error ( 'Paste not supported' ) ) ;
294+
295+ await device . inputPrimitives . keyboard . typeText ( 'fallback text' , {
296+ autoDismissKeyboard : false ,
297+ } as any ) ;
298+
299+ expect ( mockWdaClient . pasteText ) . toHaveBeenCalledWith ( 'fallback text' ) ;
300+ expect ( mockWdaClient . typeText ) . toHaveBeenLastCalledWith ( 'fallback text' , {
301+ delayMs : 80 ,
302+ } ) ;
303+ } ) ;
277304 } ) ;
278305
279306 describe ( 'Device Operations' , ( ) => {
@@ -415,13 +442,12 @@ describe('IOSDevice', () => {
415442 expect ( mockWdaClient . swipe ) . toHaveBeenCalledWith ( 100 , 200 , 300 , 400 , 500 ) ;
416443 } ) ;
417444
418- it ( 'should type text' , async ( ) => {
445+ it ( 'should paste text by default ' , async ( ) => {
419446 await device . connect ( ) ;
420447
421448 await ( device as any ) . typeText ( 'Hello World' ) ;
422- expect ( mockWdaClient . typeText ) . toHaveBeenCalledWith ( 'Hello World' , {
423- delayMs : 80 ,
424- } ) ;
449+ expect ( mockWdaClient . pasteText ) . toHaveBeenCalledWith ( 'Hello World' ) ;
450+ expect ( mockWdaClient . typeText ) . not . toHaveBeenCalled ( ) ;
425451 } ) ;
426452
427453 it ( 'should press home button' , async ( ) => {
@@ -554,6 +580,9 @@ describe('IOSDevice', () => {
554580
555581 it ( 'should handle text input failure' , async ( ) => {
556582 await device . connect ( ) ;
583+ mockWdaClient . pasteText = vi
584+ . fn ( )
585+ . mockRejectedValue ( new Error ( 'Paste text failed' ) ) ;
557586 mockWdaClient . typeText = vi
558587 . fn ( )
559588 . mockRejectedValue ( new Error ( 'Type text failed' ) ) ;
@@ -607,6 +636,7 @@ describe('IOSDevice', () => {
607636 const mockBackend = {
608637 ...mockWdaClient ,
609638 createSession : vi . fn ( ) . mockResolvedValue ( { sessionId : 'test-session' } ) ,
639+ pasteText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
610640 typeText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
611641 dismissKeyboard : vi
612642 . fn ( )
@@ -625,10 +655,9 @@ describe('IOSDevice', () => {
625655 await deviceWithAutoDismiss . connect ( ) ;
626656 await ( deviceWithAutoDismiss as any ) . typeText ( 'test text' ) ;
627657
628- // Should call typeText and swipe (for keyboard dismiss)
629- expect ( mockBackend . typeText ) . toHaveBeenCalledWith ( 'test text' , {
630- delayMs : 80 ,
631- } ) ;
658+ // Should call pasteText and swipe (for keyboard dismiss)
659+ expect ( mockBackend . pasteText ) . toHaveBeenCalledWith ( 'test text' ) ;
660+ expect ( mockBackend . typeText ) . not . toHaveBeenCalled ( ) ;
632661 expect ( mockBackend . swipe ) . toHaveBeenCalled ( ) ;
633662 } ) ;
634663 } ) ;
0 commit comments