Testing Hidden Input Field Generation in SimpleForm
This test suite validates the behavior of hidden input fields in SimpleForm, ensuring proper HTML generation and attribute handling. It focuses on verifying hidden field rendering and confirming the absence of unnecessary UI elements.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
heartcombo/simple_form
test/inputs/hidden_input_test.rb
# frozen_string_literal: true
# encoding: UTF-8
require 'test_helper'
class HiddenInputTest < ActionView::TestCase
test 'input generates a hidden field' do
with_input_for @user, :name, :hidden
assert_no_select 'input[type=text]'
assert_select 'input#user_name[type=hidden]'
end
test 'hint does not be generated for hidden fields' do
store_translations(:en, simple_form: { hints: { user: { name: "text" } } }) do
with_input_for @user, :name, :hidden
assert_no_select 'span.hint'
end
end
test 'label does not be generated for hidden inputs' do
with_input_for @user, :name, :hidden
assert_no_select 'label'
end
test 'required/optional options does not be generated for hidden inputs' do
with_input_for @user, :name, :hidden
assert_no_select 'input.required'
assert_no_select 'input[required]'
assert_no_select 'input.optional'
assert_select 'input.hidden#user_name'
end
end