mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
ba05460415
This helps styling disabled elements inside the wrapper.
63 lines
1.7 KiB
Ruby
63 lines
1.7 KiB
Ruby
require 'test_helper'
|
|
|
|
class WrapperTest < ActionView::TestCase
|
|
def with_error_for(object, attribute_name, &block)
|
|
with_concat_form_for(object) do |f|
|
|
f.input attribute_name
|
|
end
|
|
end
|
|
|
|
def with_form_for(object, *args, &block)
|
|
with_concat_form_for(object) do |f|
|
|
f.input(*args, &block)
|
|
end
|
|
end
|
|
|
|
test 'wrapper should not have error class for attribute without errors' do
|
|
with_error_for @user, :active
|
|
assert_no_select 'div.field_with_errors'
|
|
end
|
|
|
|
test 'wrapper should not have error class when object is not present' do
|
|
with_error_for :project, :name
|
|
assert_no_select 'div.field_with_errors'
|
|
end
|
|
|
|
test 'wrapper should add error class for attribute with errors' do
|
|
with_error_for @user, :name
|
|
assert_select 'div.field_with_errors'
|
|
end
|
|
|
|
test 'wrapper should add chosen error class for attribute with errors' do
|
|
swap SimpleForm, :wrapper_error_class => "omgError" do
|
|
with_error_for @user, :name
|
|
assert_select 'div.omgError'
|
|
end
|
|
end
|
|
|
|
test 'wrapper should add chosen wrapper class' do
|
|
swap SimpleForm, :wrapper_class => "wrapper" do
|
|
with_form_for @user, :active
|
|
assert_select 'div.wrapper'
|
|
assert_no_select 'div.input'
|
|
|
|
with_form_for @user, :name
|
|
assert_select 'div.wrapper'
|
|
assert_no_select 'div.input'
|
|
|
|
with_form_for :project, :name
|
|
assert_select 'div.wrapper'
|
|
assert_no_select 'div.input'
|
|
end
|
|
end
|
|
|
|
test 'wrapper should not have disabled class by default' do
|
|
with_form_for @user, :active
|
|
assert_no_select 'div.disabled'
|
|
end
|
|
|
|
test 'wrapper should add disabled class when the input is disabled' do
|
|
with_form_for @user, :active, :disabled => true
|
|
assert_select 'div.disabled'
|
|
end
|
|
end
|