2011-09-03 12:49:54 -04:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class InputTest < ActionView::TestCase
|
|
|
|
test 'input should generate css class based on default input type' do
|
|
|
|
with_input_for @user, :name, :string
|
|
|
|
assert_select 'input.string'
|
|
|
|
with_input_for @user, :description, :text
|
|
|
|
assert_select 'textarea.text'
|
|
|
|
with_input_for @user, :age, :integer
|
|
|
|
assert_select 'input.integer'
|
|
|
|
with_input_for @user, :born_at, :date
|
|
|
|
assert_select 'select.date'
|
|
|
|
with_input_for @user, :created_at, :datetime
|
|
|
|
assert_select 'select.datetime'
|
|
|
|
end
|
|
|
|
|
2012-09-07 02:21:19 -04:00
|
|
|
test 'string input should generate autofocus attribute when autofocus option is true' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :string, autofocus: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'input.string[autofocus]'
|
2012-09-07 02:21:19 -04:00
|
|
|
end
|
|
|
|
|
2013-08-16 07:11:31 -04:00
|
|
|
test 'input accepts input_class configuration' do
|
|
|
|
swap SimpleForm, input_class: :xlarge do
|
2011-09-26 22:13:06 -04:00
|
|
|
with_input_for @user, :name, :string
|
|
|
|
assert_select 'input.xlarge'
|
2013-08-16 07:11:31 -04:00
|
|
|
assert_no_select 'div.xlarge'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input does not add input_class when configured to not generate additional classes for input' do
|
|
|
|
swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
|
|
|
|
with_input_for @user, :name, :string
|
|
|
|
assert_select 'input'
|
|
|
|
assert_no_select '.xlarge'
|
2011-09-26 22:13:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-07 02:21:19 -04:00
|
|
|
test 'text input should generate autofocus attribute when autofocus option is true' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :text, autofocus: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'textarea.text[autofocus]'
|
2012-09-07 02:21:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'numeric input should generate autofocus attribute when autofocus option is true' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :integer, autofocus: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'input.integer[autofocus]'
|
2012-09-07 02:21:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'date input should generate autofocus attribute when autofocus option is true' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :born_at, :date, autofocus: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.date[autofocus]'
|
2012-09-07 02:21:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'datetime input should generate autofocus attribute when autofocus option is true' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :created_at, :datetime, autofocus: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.datetime[autofocus]'
|
2012-09-07 02:21:19 -04:00
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
|
2012-09-07 02:21:19 -04:00
|
|
|
test 'string input should generate autofocus attribute when autofocus option is false' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :string, autofocus: false
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'input.string[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'text input should generate autofocus attribute when autofocus option is false' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :text, autofocus: false
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'textarea.text[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'numeric input should generate autofocus attribute when autofocus option is false' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :integer, autofocus: false
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'input.integer[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'date input should generate autofocus attribute when autofocus option is false' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :born_at, :date, autofocus: false
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'select.date[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'datetime input should generate autofocus attribute when autofocus option is false' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :created_at, :datetime, autofocus: false
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'select.datetime[autofocus]'
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
|
2012-09-07 02:21:19 -04:00
|
|
|
test 'string input should generate autofocus attribute when autofocus option is not present' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :name, :string
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'input.string[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'text input should generate autofocus attribute when autofocus option is not present' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :description, :text
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'textarea.text[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'numeric input should generate autofocus attribute when autofocus option is not present' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :age, :integer
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'input.integer[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'date input should generate autofocus attribute when autofocus option is not present' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :born_at, :date
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'select.date[autofocus]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'datetime input should generate autofocus attribute when autofocus option is not present' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :created_at, :datetime
|
2012-09-07 02:21:19 -04:00
|
|
|
assert_no_select 'select.datetime[autofocus]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# With no object
|
|
|
|
test 'input should be generated properly when object is not present' do
|
|
|
|
with_input_for :project, :name, :string
|
|
|
|
assert_select 'input.string.required#project_name'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input as radio should be generated properly when object is not present ' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for :project, :name, :radio_buttons
|
|
|
|
assert_select 'input.radio_buttons#project_name_true'
|
|
|
|
assert_select 'input.radio_buttons#project_name_false'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'input as select with collection should be generated properly when object is not present' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.select#project_name'
|
|
|
|
end
|
2012-09-07 02:21:19 -04:00
|
|
|
|
2012-06-29 15:13:15 -04:00
|
|
|
test 'input should not generate empty css class' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
|
2012-06-29 15:13:15 -04:00
|
|
|
with_input_for :project, :name, :string
|
|
|
|
assert_no_select 'input#project_name[class]'
|
|
|
|
end
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|