# frozen_string_literal: true
require 'test_helper'
require_relative '../../app/helpers/shoelace/form_helper'
class FormHelperTest < ActionView::TestCase
include Shoelace::FormHelper
AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
test "#sl_text_field_tag with name and value" do
assert_dom_equal <<~HTML, sl_text_field_tag('name', 'Your name')
HTML
end
test "#sl_text_field_tag with class string" do
assert_dom_equal <<~HTML, sl_text_field_tag('name', 'Your name', class: "admin")
HTML
end
test "#sl_text_field_tag with params" do
assert_raises ActionController::UnfilteredParameters do
sl_text_field_tag('name', 'Your name', **ActionController::Parameters.new(key: "value"))
end
end
test "#sl_text_field_tag with disabled: true" do
assert_dom_equal <<~HTML, sl_text_field_tag('name', 'Your name', disabled: true)
HTML
end
test "#sl_submit_tag" do
assert_dom_equal <<~HTML, sl_submit_tag("Save")
Save
HTML
end
test "#sl_submit_tag with onclick" do
assert_dom_equal <<~HTML, sl_submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." })
Save
HTML
end
test "#sl_radio_button" do
assert_dom_equal(<<~HTML, sl_radio_button(:user, :name, 'userid-314', checked: true) { "Yuki Nishijima" })
Yuki Nishijima
HTML
end
test "#sl_form_with" do
assert_dom_equal(<<~HTML, sl_form_with(url: "/") {})