@@ -48,6 +48,68 @@ describe("Validation step tests", () => {
4848 } )
4949 } )
5050
51+ test ( "Submit data with a successful async return" , async ( ) => {
52+ const onSuccess = jest . fn ( )
53+ const onSubmit = jest . fn ( async ( ) : Promise < void > => {
54+ onSuccess ( )
55+ return Promise . resolve ( )
56+ } )
57+ const onClose = jest . fn ( )
58+ render (
59+ < Providers theme = { defaultTheme } rsiValues = { { ...mockValues , onSubmit, onClose } } >
60+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
61+ < ValidationStep initialData = { [ ] } file = { file } />
62+ </ ModalWrapper >
63+ </ Providers > ,
64+ )
65+
66+ const finishButton = screen . getByRole ( "button" , {
67+ name : "Confirm" ,
68+ } )
69+
70+ await userEvent . click ( finishButton )
71+
72+ await waitFor ( ( ) => {
73+ expect ( onSubmit ) . toBeCalledWith ( { all : [ ] , invalidData : [ ] , validData : [ ] } , file )
74+ } )
75+ await waitFor ( ( ) => {
76+ expect ( onSuccess ) . toBeCalled ( )
77+ expect ( onClose ) . toBeCalled ( )
78+ } )
79+ } )
80+
81+ test ( "Submit data with a unsuccessful async return" , async ( ) => {
82+ const onReject = jest . fn ( )
83+ const onSubmit = jest . fn ( async ( ) : Promise < void > => {
84+ onReject ( )
85+ return Promise . reject ( )
86+ } )
87+ const onClose = jest . fn ( )
88+ try {
89+ render (
90+ < Providers theme = { defaultTheme } rsiValues = { { ...mockValues , onSubmit, onClose } } >
91+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
92+ < ValidationStep initialData = { [ ] } file = { file } />
93+ </ ModalWrapper >
94+ </ Providers > ,
95+ )
96+
97+ const finishButton = screen . getByRole ( "button" , {
98+ name : "Confirm" ,
99+ } )
100+
101+ await userEvent . click ( finishButton )
102+
103+ await waitFor ( ( ) => {
104+ expect ( onSubmit ) . toBeCalledWith ( { all : [ ] , invalidData : [ ] , validData : [ ] } , file )
105+ } )
106+ } catch ( e ) { }
107+ await waitFor ( ( ) => {
108+ expect ( onReject ) . toBeCalled ( )
109+ expect ( onClose ) . not . toBeCalled ( )
110+ } )
111+ } )
112+
51113 test ( "Filters rows with required errors" , async ( ) => {
52114 const UNIQUE_NAME = "very unique name"
53115 const fields = [
0 commit comments