Skip to content

Commit 9f3078b

Browse files
committed
add tests with buttons
1 parent b4dcd48 commit 9f3078b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/bootstrap_form_group_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,25 @@ class BootstrapFormGroupTest < ActionView::TestCase
221221
assert_equivalent_html expected, @builder.file_field(:avatar, append: "after")
222222
end
223223

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+
224243
test "help messages for default forms" do
225244
expected = <<~HTML
226245
<div class="mb-3">

0 commit comments

Comments
 (0)