2017-10-23 21:01:08 -04:00
|
|
|
# frozen_string_literal: true
|
2011-09-03 12:49:54 -04:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class TextInputTest < ActionView::TestCase
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a text area for text attributes' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :description, :text
|
|
|
|
assert_select 'textarea.text#user_description'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a text area for text attributes that accept placeholder' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
2014-09-08 16:19:40 -04:00
|
|
|
assert_select 'textarea.text[placeholder="Put in some text"]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2015-01-05 18:32:46 -05:00
|
|
|
test 'input generates a placeholder from the translations' do
|
|
|
|
store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
|
|
|
|
with_input_for @user, :name, :text
|
|
|
|
assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input gets maxlength from column definition for text attributes' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :description, :text
|
2014-09-08 16:19:40 -04:00
|
|
|
assert_select 'textarea.text[maxlength="200"]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input infers maxlength column definition from validation when present for text attributes' do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @validating_user, :description, :text
|
2014-09-08 16:19:40 -04:00
|
|
|
assert_select 'textarea.text[maxlength="50"]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
2016-08-21 22:36:45 -04:00
|
|
|
|
|
|
|
test 'input infers minlength column definition from validation when present for text attributes' do
|
|
|
|
with_input_for @validating_user, :description, :text
|
|
|
|
assert_select 'textarea.text[minlength="15"]'
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|