2011-09-03 12:49:54 -04:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
2013-11-13 11:44:42 -05:00
|
|
|
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
|
|
|
class DateTimeInputWithHtml5Test < ActionView::TestCase
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :created_at, :datetime, html5: true
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'input[type="datetime"]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a datetime select for datetime attributes' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :created_at, :datetime
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'select.datetime'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enbled' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :born_at, :date, html5: true
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'input[type="date"]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a date select for date attributes' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :born_at, :date
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'select.date'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enbled' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :delivery_time, :time, html5: true
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'input[type="time"]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a time select for time attributes' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :delivery_time, :time
|
2013-11-13 11:44:42 -05:00
|
|
|
|
|
|
|
assert_select 'select.time'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates required html attribute' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
2013-11-13 11:44:42 -05:00
|
|
|
assert_select 'input.required'
|
|
|
|
assert_select 'input[required]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input has an aria-required html attribute' do
|
2013-11-15 23:25:24 -05:00
|
|
|
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
2013-11-13 11:44:42 -05:00
|
|
|
assert_select 'input[aria-required=true]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
|
|
|
class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a datetime select by default for datetime attributes' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :created_at, :datetime
|
|
|
|
1.upto(5) do |i|
|
|
|
|
assert_select "form select.datetime#user_created_at_#{i}i"
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input is able to pass options to datetime select' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for @user, :created_at, :datetime, html5: false,
|
2013-01-28 16:02:59 -05:00
|
|
|
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
2011-09-03 12:49:54 -04:00
|
|
|
|
|
|
|
assert_select 'select.datetime[disabled=disabled]'
|
|
|
|
assert_select 'select.datetime option', 'ano'
|
|
|
|
assert_select 'select.datetime option', 'mês'
|
|
|
|
assert_select 'select.datetime option', 'dia'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :created_at, :datetime, html5: true
|
|
|
|
|
|
|
|
assert_select 'input[type="datetime"]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a date select for date attributes' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :born_at, :date
|
|
|
|
assert_select 'select.date#user_born_at_1i'
|
|
|
|
assert_select 'select.date#user_born_at_2i'
|
|
|
|
assert_select 'select.date#user_born_at_3i'
|
|
|
|
assert_no_select 'select.date#user_born_at_4i'
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input is able to pass options to date select' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for @user, :born_at, :date, as: :date, html5: false,
|
2013-01-28 16:02:59 -05:00
|
|
|
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
2011-09-03 12:49:54 -04:00
|
|
|
|
|
|
|
assert_select 'select.date[disabled=disabled]'
|
|
|
|
assert_select 'select.date option', 'ano'
|
|
|
|
assert_select 'select.date option', 'mês'
|
|
|
|
assert_select 'select.date option', 'dia'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input is able to pass :default to date select' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for @user, :born_at, :date, default: Date.today, html5: false
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :born_at, :date, html5: true
|
|
|
|
|
|
|
|
assert_select 'input[type="date"]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a time select for time attributes' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :delivery_time, :time
|
|
|
|
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
|
|
|
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
|
|
|
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
|
|
|
assert_select 'select.time#user_delivery_time_4i'
|
|
|
|
assert_select 'select.time#user_delivery_time_5i'
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input is able to pass options to time select' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for @user, :delivery_time, :time, required: true, html5: false,
|
2013-01-28 16:02:59 -05:00
|
|
|
disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
|
2011-09-03 12:49:54 -04:00
|
|
|
|
|
|
|
assert_select 'select.time[disabled=disabled]'
|
|
|
|
assert_select 'select.time option', 'hora'
|
|
|
|
assert_select 'select.time option', 'minuto'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enabled' do
|
2013-11-13 11:44:42 -05:00
|
|
|
swap_wrapper do
|
|
|
|
with_input_for @user, :delivery_time, :time, html5: true
|
|
|
|
|
|
|
|
assert_select 'input[type="time"]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'label uses i18n to get target for date input type' do
|
2013-07-16 09:44:03 -04:00
|
|
|
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for :project, :created_at, :date, html5: false
|
2012-02-04 08:56:39 -05:00
|
|
|
assert_select 'label[for=project_created_at_2i]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'label uses i18n to get target for datetime input type' do
|
2013-07-16 09:44:03 -04:00
|
|
|
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for :project, :created_at, :datetime, html5: false
|
2012-02-04 08:56:39 -05:00
|
|
|
assert_select 'label[for=project_created_at_2i]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'label uses order to get target when date input type' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for :project, :created_at, :date, order: ['month', 'year', 'day'], html5: false
|
2012-02-04 08:56:39 -05:00
|
|
|
assert_select 'label[for=project_created_at_2i]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'label uses order to get target when datetime input type' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day'], html5: false
|
2012-02-04 08:56:39 -05:00
|
|
|
assert_select 'label[for=project_created_at_2i]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'label points to first option when time input type' do
|
2013-11-13 11:44:42 -05:00
|
|
|
with_input_for :project, :created_at, :time, html5: false
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'label[for=project_created_at_4i]'
|
|
|
|
end
|
|
|
|
end
|