@@ -292,6 +292,72 @@ def form_config
292292
293293 end
294294
295+ it "gets properly resetted when form is successfully submitted" do
296+
297+ class ExamplePage < Matestack ::Ui ::Page
298+
299+ def response
300+ components {
301+ form form_config , :include do
302+ form_input key : :title , type : :text , placeholder : "title" , id : "title-input"
303+ br
304+ form_input key : :file_1 , type : :file , id : "file-1-input"
305+ br
306+ form_input key : :files , type : :file , multiple : true , id : "files-input"
307+ br
308+ form_submit do
309+ button text : 'Submit me!'
310+ end
311+ end
312+ async show_on : "uploaded_successfully" , hide_on : "form_submitted" do
313+ plain "{{event.data.file_1.instance}}"
314+ plain "{{event.data.file_1.name}}"
315+ plain "{{event.data.files}}"
316+ end
317+ }
318+ end
319+
320+ def form_config
321+ return {
322+ for : :my_form ,
323+ method : :post ,
324+ multipart : true ,
325+ path : :form_input_file_upload_success_form_test_path ,
326+ emit : "form_submitted" ,
327+ success : {
328+ emit : "uploaded_successfully"
329+ }
330+ }
331+ end
332+
333+ end
334+
335+ visit '/example'
336+
337+ fill_in "title-input" , with : "bar"
338+ attach_file ( 'file-1-input' , "#{ File . dirname ( __FILE__ ) } /test_files/matestack-logo.png" )
339+ attach_file ( "files-input" , [ "#{ File . dirname ( __FILE__ ) } /test_files/matestack-logo.png" , "#{ File . dirname ( __FILE__ ) } /test_files/corgi.mp4" ] )
340+
341+ click_button "Submit me!"
342+
343+ expect ( page ) . to have_content ( "file_1 instance: #<ActionDispatch::Http::UploadedFile" )
344+ expect ( page ) . to have_content ( "file_1 with name: matestack-logo.png" )
345+ expect ( page ) . to have_content ( "files[0] instance: #<ActionDispatch::Http::UploadedFile" )
346+ expect ( page ) . to have_content ( "files[1] instance: #<ActionDispatch::Http::UploadedFile" )
347+ expect ( page ) . to have_content ( "files[0] with name: matestack-logo.png" )
348+ expect ( page ) . to have_content ( "files[1] with name: corgi.mp4" )
349+
350+ fill_in "title-input" , with : "bar"
351+ click_button "Submit me!"
352+
353+ expect ( page ) . to have_content ( "file_1 instance: nil" )
354+ expect ( page ) . to have_content ( "file_1 with name: nil" )
355+ expect ( page ) . to have_content ( "files[0] instance: nil" )
356+ expect ( page ) . to have_content ( "files[1] instance: nil" )
357+ expect ( page ) . to have_content ( "files[0] with name: nil" )
358+ expect ( page ) . to have_content ( "files[1] with name: nil" )
359+ end
360+
295361 end
296362
297363end
0 commit comments