@@ -195,6 +195,51 @@ class BootstrapFormGroupTest < ActionView::TestCase
195
195
assert_equivalent_html expected , bootstrap_form_for ( @user ) { |f | f . text_field :email , prepend : "$" , append : ".00" }
196
196
end
197
197
198
+ test "file field with prepend text" do
199
+ expected = <<~HTML
200
+ < div class ="mb-3 ">
201
+ < label class ="form-label " for ="user_avatar "> Avatar</ label >
202
+ < div class ="input-group ">
203
+ < span class ="input-group-text "> before</ span >
204
+ < input class ="form-control " id ="user_avatar " name ="user[avatar] " type ="file " />
205
+ </ div >
206
+ </ div >
207
+ HTML
208
+ assert_equivalent_html expected , @builder . file_field ( :avatar , prepend : "before" )
209
+ end
210
+
211
+ test "file field with append text" do
212
+ expected = <<~HTML
213
+ < div class ="mb-3 ">
214
+ < label class ="form-label " for ="user_avatar "> Avatar</ label >
215
+ < div class ="input-group ">
216
+ < input class ="form-control " id ="user_avatar " name ="user[avatar] " type ="file " />
217
+ < span class ="input-group-text "> after</ span >
218
+ </ div >
219
+ </ div >
220
+ HTML
221
+ assert_equivalent_html expected , @builder . file_field ( :avatar , append : "after" )
222
+ end
223
+
224
+ test "file field with append and prepend button" do
225
+ prefix = '<div class="mb-3"><label class="form-label" for="user_avatar">Avatar</label><div class="input-group">'
226
+ field = <<~HTML
227
+ < input class ="form-control " id ="user_avatar " name ="user[avatar] " type ="file " />
228
+ HTML
229
+ button_src = link_to ( "Click" , "#" , class : "btn btn-secondary" )
230
+ button_prepend = button_src
231
+ button_append = button_src
232
+ suffix = "</div></div>"
233
+ after_button = prefix + field + button_append + suffix
234
+ before_button = prefix + button_prepend + field + suffix
235
+ both_button = prefix + button_prepend + field + button_append + suffix
236
+ multiple_button = prefix + button_prepend + button_prepend + field + button_append + button_append + suffix
237
+ assert_equivalent_html after_button , @builder . file_field ( :avatar , append : button_src )
238
+ assert_equivalent_html before_button , @builder . file_field ( :avatar , prepend : button_src )
239
+ assert_equivalent_html both_button , @builder . file_field ( :avatar , append : button_src , prepend : button_src )
240
+ assert_equivalent_html multiple_button , @builder . file_field ( :avatar , append : [ button_src ] * 2 , prepend : [ button_src ] * 2 )
241
+ end
242
+
198
243
test "help messages for default forms" do
199
244
expected = <<~HTML
200
245
< div class ="mb-3 ">
0 commit comments