@@ -296,6 +296,47 @@ describe("TextInput component tests", () => {
296296 userEvent . click ( getByRole ( "button" ) ) ;
297297 expect ( onClick ) . toHaveBeenCalled ( ) ;
298298 } ) ;
299+ test ( "Text input submit correctly value in form" , ( ) => {
300+ const onClick = jest . fn ( ) ;
301+ const action = {
302+ onClick : onClick ,
303+ icon : (
304+ < svg
305+ data-testid = "image"
306+ xmlns = "http://www.w3.org/2000/svg"
307+ height = "24px"
308+ viewBox = "0 0 24 24"
309+ width = "24px"
310+ fill = "currentColor"
311+ >
312+ < path d = "M0 0h24v24H0V0z" fill = "none" />
313+ < path d = "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
314+ </ svg >
315+ ) ,
316+ title : "Search" ,
317+ } ;
318+ const handlerOnSubmit = jest . fn ( ( e ) => {
319+ e . preventDefault ( ) ;
320+ const formData = new FormData ( e . target ) ;
321+ const formProps = Object . fromEntries ( formData ) ;
322+ expect ( formProps ) . toStrictEqual ( { data : "test" } ) ;
323+ } ) ;
324+ const { getByText, getAllByRole, getByRole } = render (
325+ < form onSubmit = { handlerOnSubmit } >
326+ < DxcTextInput label = "Input label" name = "data" action = { action } />
327+ < button type = "submit" > Submit</ button >
328+ </ form >
329+ ) ;
330+ const search = getAllByRole ( "button" ) [ 0 ] ;
331+ const submit = getByText ( "Submit" ) ;
332+ const input = getByRole ( "textbox" ) ;
333+ userEvent . type ( input , "test" ) ;
334+ expect ( input . value ) . toBe ( "test" ) ;
335+ userEvent . click ( search ) ;
336+ expect ( handlerOnSubmit ) . not . toHaveBeenCalled ( ) ;
337+ userEvent . click ( submit ) ;
338+ expect ( handlerOnSubmit ) . toHaveBeenCalled ( ) ;
339+ } ) ;
299340 test ( "Renders with correct prefix and suffix" , ( ) => {
300341 const { getByText } = render ( < DxcTextInput label = "Input label" prefix = "+34" suffix = "USD" /> ) ;
301342 expect ( getByText ( "+34" ) ) . toBeTruthy ( ) ;
0 commit comments