@@ -45,9 +45,49 @@ def form_config
4545 expect ( page ) . to have_content ( 'seems to be invalid' , count : 2 )
4646 expect ( page ) . to have_selector ( '#text-input.error' )
4747 expect ( page ) . to have_selector ( '#textarea.error' )
48+ expect ( page ) . to have_selector ( "#text-input + .errors > .error" , text : "seems to be invalid" )
49+ expect ( page ) . to have_selector ( "#textarea + .errors > .error" , text : "seems to be invalid" )
4850 expect ( page ) . to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' , count : 2 )
4951 end
5052
53+ it "should reset error messages properly when missing data is provided" do
54+ class ExamplePage < Matestack ::Ui ::Page
55+ def response
56+ matestack_form form_config do
57+ form_input id : "text-input" , key : :foo , type : :text
58+ button "Submit me!"
59+ plain "Errors: {{errors}}"
60+ end
61+ end
62+
63+ def form_config
64+ {
65+ for : :my_object ,
66+ method : :post ,
67+ path : form_error_failure_form_test_path ( id : 42 ) ,
68+ }
69+ end
70+ end
71+
72+ visit "/example"
73+
74+ fill_in "text-input" , with : "text"
75+
76+ click_button "Submit me!"
77+
78+ expect ( page ) . to have_content ( 'Errors: { "foo": [ "seems to be invalid" ] }' )
79+
80+ fill_in "text-input" , with : "texttext"
81+
82+ page . find ( "#text-input" ) . native . send_keys :tab
83+
84+ expect ( page ) . to have_content ( 'Errors: {}' )
85+
86+ expect ( page ) . not_to have_content ( 'seems to be invalid' )
87+ expect ( page ) . not_to have_selector ( '#text-input.error' )
88+ expect ( page ) . not_to have_selector ( "#text-input + .errors > .error" , text : "seems to be invalid" )
89+ end
90+
5191 it "can turn off error messages with form config and turn explicit on" do
5292 class ExamplePage < Matestack ::Ui ::Page
5393 def response
@@ -67,7 +107,7 @@ def form_config
67107 }
68108 end
69109 end
70-
110+
71111 visit "/example"
72112 fill_in "text-input" , with : "text"
73113 fill_in "textarea" , with : "area"
@@ -78,7 +118,7 @@ def form_config
78118 expect ( page ) . not_to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' )
79119 expect ( page ) . to have_xpath ( '//span[@class="errors"]/span[@class="error" and contains(.,"seems to be invalid")]' )
80120 end
81-
121+
82122 it "lets you turn errors of component based" do
83123 class ExamplePage < Matestack ::Ui ::Page
84124 def response
@@ -112,7 +152,7 @@ def form_config
112152 expect ( page ) . not_to have_selector ( '#textarea.error' )
113153 expect ( page ) . to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' , count : 1 )
114154 end
115-
155+
116156 it "lets you customize errors and errors wrapper" do
117157 class ExamplePage < Matestack ::Ui ::Page
118158 def response
@@ -127,13 +167,13 @@ def form_config
127167 for : :my_object ,
128168 method : :post ,
129169 path : form_error_failure_form_test_path ( id : 42 ) ,
130- errors : {
131- wrapper : {
132- tag : :div ,
170+ errors : {
171+ wrapper : {
172+ tag : :div ,
133173 class : 'my-errors'
134- } ,
135- tag : :div ,
136- class : 'my-error'
174+ } ,
175+ tag : :div ,
176+ class : 'my-error'
137177 }
138178 }
139179 end
@@ -146,4 +186,4 @@ def form_config
146186 expect ( page ) . to have_xpath ( '//div[@class="my-errors"]/div[@class="my-error" and contains(.,"seems to be invalid")]' )
147187 end
148188
149- end
189+ end
0 commit comments