@@ -309,6 +309,18 @@ test('Passes textAriaLabel to TextInput', () => {
309309 expect ( screen . getByRole ( 'textbox' ) ) . toHaveAccessibleName ( 'text label' ) ;
310310} ) ;
311311
312+ test ( 'Passes inputId to TextInput' , ( ) => {
313+ render ( < ClipboardCopy inputId = "custom-input-id" > { children } </ ClipboardCopy > ) ;
314+
315+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'id' , 'custom-input-id' ) ;
316+ } ) ;
317+
318+ test ( 'Passes inputName to TextInput' , ( ) => {
319+ render ( < ClipboardCopy inputName = "custom-input-name" > { children } </ ClipboardCopy > ) ;
320+
321+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute ( 'name' , 'custom-input-name' ) ;
322+ } ) ;
323+
312324test ( 'Calls onChange when ClipboardCopy textinput is typed in' , async ( ) => {
313325 const onChangeMock = jest . fn ( ) ;
314326 const user = userEvent . setup ( ) ;
@@ -338,6 +350,66 @@ test('Does not call onChange when ClipboardCopy textinput is not typed in', asyn
338350 expect ( onChangeMock ) . not . toHaveBeenCalled ( ) ;
339351} ) ;
340352
353+ test ( 'Calls onFocus when ClipboardCopy textinput is focused' , async ( ) => {
354+ const onFocusMock = jest . fn ( ) ;
355+ const user = userEvent . setup ( ) ;
356+
357+ render ( < ClipboardCopy onInputFocus = { onFocusMock } > { children } </ ClipboardCopy > ) ;
358+
359+ await user . click ( screen . getByRole ( 'textbox' ) ) ;
360+
361+ expect ( onFocusMock ) . toHaveBeenCalledTimes ( 1 ) ;
362+ } ) ;
363+
364+ test ( 'Does not call onFocus when ClipboardCopy textinput is not focused' , async ( ) => {
365+ const onFocusMock = jest . fn ( ) ;
366+ const user = userEvent . setup ( ) ;
367+
368+ render (
369+ < >
370+ < ClipboardCopy onInputFocus = { onFocusMock } > { children } </ ClipboardCopy >
371+ < input aria-label = "native input" />
372+ </ >
373+ ) ;
374+
375+ await user . click ( screen . getByRole ( 'textbox' , { name : 'native input' } ) ) ;
376+
377+ expect ( onFocusMock ) . not . toHaveBeenCalled ( ) ;
378+ } ) ;
379+
380+ test ( 'Calls onBlur when ClipboardCopy textinput loses focus' , async ( ) => {
381+ const onBlurMock = jest . fn ( ) ;
382+ const user = userEvent . setup ( ) ;
383+
384+ render (
385+ < >
386+ < ClipboardCopy onInputBlur = { onBlurMock } > { children } </ ClipboardCopy >
387+ < input aria-label = "native input" />
388+ </ >
389+ ) ;
390+
391+ await user . click ( screen . getByRole ( 'textbox' , { name : 'Copyable input' } ) ) ;
392+ await user . click ( screen . getByRole ( 'textbox' , { name : 'native input' } ) ) ;
393+
394+ expect ( onBlurMock ) . toHaveBeenCalledTimes ( 1 ) ;
395+ } ) ;
396+
397+ test ( 'Does not call onBlur when ClipboardCopy textinput does not lose focus' , async ( ) => {
398+ const onBlurMock = jest . fn ( ) ;
399+ const user = userEvent . setup ( ) ;
400+
401+ render (
402+ < >
403+ < ClipboardCopy onInputBlur = { onBlurMock } > { children } </ ClipboardCopy >
404+ < input aria-label = "native input" />
405+ </ >
406+ ) ;
407+
408+ await user . click ( screen . getByRole ( 'textbox' , { name : 'native input' } ) ) ;
409+
410+ expect ( onBlurMock ) . not . toHaveBeenCalled ( ) ;
411+ } ) ;
412+
341413test ( 'Calls onCopy when ClipboardCopyButton is clicked' , async ( ) => {
342414 const onCopyMock = jest . fn ( ) ;
343415 const user = userEvent . setup ( ) ;
0 commit comments