1+ require_relative "../../../../support/utils"
2+ require_relative "../../../../support/test_controller"
3+ require_relative "support/form_test_controller"
4+ require_relative "support/model_form_test_controller"
5+ include Utils
6+
7+ describe "form component" , type : :feature , js : true do
8+
9+ before :all do
10+ Rails . application . routes . append do
11+ scope "form_text_input_error_spec" do
12+ post '/input_error_failure_form_test/:id' , to : 'form_test#failure_submit' , as : 'input_error_failure_form_test'
13+ end
14+ end
15+ Rails . application . reload_routes!
16+ end
17+
18+ before :each do
19+ allow_any_instance_of ( FormTestController ) . to receive ( :expect_params )
20+ end
21+
22+ it "should work with partials" do
23+ class ExamplePage < Matestack ::Ui ::Page
24+ def response
25+ form form_config , :include do
26+ form_input id : "text-input" , key : :foo , type : :text
27+ input_partial
28+ form_submit do
29+ button text : "Submit me!"
30+ end
31+ end
32+ end
33+
34+ def input_partial
35+ form_input id : "input-partial" , key : :bar , type : :text
36+ inception
37+ end
38+
39+ def inception
40+ form_input id : "inception" , key : :baz , type : :text
41+ end
42+
43+ def form_config
44+ {
45+ for : :my_object ,
46+ method : :post ,
47+ path : :input_error_failure_form_test_path ,
48+ params : {
49+ id : 42
50+ }
51+ }
52+ end
53+ end
54+
55+ visit "/example"
56+ expect_any_instance_of ( FormTestController ) . to receive ( :expect_params )
57+ . with (
58+ hash_including ( my_object : {
59+ bar : 'from partial' ,
60+ baz : 'partial in partial' ,
61+ foo : 'text' ,
62+ }
63+ )
64+ )
65+ expect ( page ) . to have_selector ( '#text-input' )
66+ expect ( page ) . to have_selector ( '#input-partial' )
67+ expect ( page ) . to have_selector ( '#inception' )
68+ fill_in "text-input" , with : "text"
69+ fill_in "input-partial" , with : "from partial"
70+ fill_in "inception" , with : "partial in partial"
71+ click_button "Submit me!"
72+ end
73+
74+ end
0 commit comments