@@ -45,9 +45,49 @@ def form_config
45
45
expect ( page ) . to have_content ( 'seems to be invalid' , count : 2 )
46
46
expect ( page ) . to have_selector ( '#text-input.error' )
47
47
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" )
48
50
expect ( page ) . to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' , count : 2 )
49
51
end
50
52
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
+
51
91
it "can turn off error messages with form config and turn explicit on" do
52
92
class ExamplePage < Matestack ::Ui ::Page
53
93
def response
@@ -67,7 +107,7 @@ def form_config
67
107
}
68
108
end
69
109
end
70
-
110
+
71
111
visit "/example"
72
112
fill_in "text-input" , with : "text"
73
113
fill_in "textarea" , with : "area"
@@ -78,7 +118,7 @@ def form_config
78
118
expect ( page ) . not_to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' )
79
119
expect ( page ) . to have_xpath ( '//span[@class="errors"]/span[@class="error" and contains(.,"seems to be invalid")]' )
80
120
end
81
-
121
+
82
122
it "lets you turn errors of component based" do
83
123
class ExamplePage < Matestack ::Ui ::Page
84
124
def response
@@ -112,7 +152,7 @@ def form_config
112
152
expect ( page ) . not_to have_selector ( '#textarea.error' )
113
153
expect ( page ) . to have_xpath ( '//div[@class="errors"]/div[@class="error" and contains(.,"seems to be invalid")]' , count : 1 )
114
154
end
115
-
155
+
116
156
it "lets you customize errors and errors wrapper" do
117
157
class ExamplePage < Matestack ::Ui ::Page
118
158
def response
@@ -127,13 +167,13 @@ def form_config
127
167
for : :my_object ,
128
168
method : :post ,
129
169
path : form_error_failure_form_test_path ( id : 42 ) ,
130
- errors : {
131
- wrapper : {
132
- tag : :div ,
170
+ errors : {
171
+ wrapper : {
172
+ tag : :div ,
133
173
class : 'my-errors'
134
- } ,
135
- tag : :div ,
136
- class : 'my-error'
174
+ } ,
175
+ tag : :div ,
176
+ class : 'my-error'
137
177
}
138
178
}
139
179
end
@@ -146,4 +186,4 @@ def form_config
146
186
expect ( page ) . to have_xpath ( '//div[@class="my-errors"]/div[@class="my-error" and contains(.,"seems to be invalid")]' )
147
187
end
148
188
149
- end
189
+ end
0 commit comments