2017-10-24 01:01:08 +00:00
|
|
|
# frozen_string_literal: true
|
2011-09-03 16:49:54 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class PriorityInputTest < ActionView::TestCase
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'input generates a country select field' do
|
2011-09-03 16:49:54 +00:00
|
|
|
with_input_for @user, :country, :country
|
|
|
|
assert_select 'select#user_country'
|
2018-10-30 10:39:05 +00:00
|
|
|
assert_select 'select option[value=BR]', 'Brazil'
|
2014-09-08 20:19:40 +00:00
|
|
|
assert_no_select 'select option[value=""][disabled=disabled]'
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'input generates a country select with SimpleForm default' do
|
2013-01-28 21:02:59 +00:00
|
|
|
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
2011-09-03 16:49:54 +00:00
|
|
|
with_input_for @user, :country, :country
|
2018-10-30 10:39:05 +00:00
|
|
|
assert_select 'select option[value="---------------"][disabled=disabled]'
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'input generates a time zone select field' do
|
2011-09-03 16:49:54 +00:00
|
|
|
with_input_for @user, :time_zone, :time_zone
|
|
|
|
assert_select 'select#user_time_zone'
|
|
|
|
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
2014-09-08 20:19:40 +00:00
|
|
|
assert_no_select 'select option[value=""][disabled=disabled]'
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'input generates a time zone select field with default' do
|
2013-01-28 21:02:59 +00:00
|
|
|
with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
|
2011-09-03 16:49:54 +00:00
|
|
|
assert_select 'select option[value=Brasilia][selected=selected]'
|
2014-09-08 20:19:40 +00:00
|
|
|
assert_no_select 'select option[value=""]'
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'input generates a time zone select using options priority' do
|
2013-01-28 21:02:59 +00:00
|
|
|
with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
|
2014-09-08 20:19:40 +00:00
|
|
|
assert_select 'select option[value=""][disabled=disabled]'
|
|
|
|
assert_no_select 'select option[value=""]', /^$/
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'priority input does not generate invalid required html attribute' do
|
2011-09-03 16:49:54 +00:00
|
|
|
with_input_for @user, :country, :country
|
|
|
|
assert_select 'select.required'
|
|
|
|
assert_no_select 'select[required]'
|
|
|
|
end
|
2013-04-07 18:02:49 +00:00
|
|
|
|
2014-05-14 17:19:06 +00:00
|
|
|
test 'priority input does not generate invalid aria-required html attribute' do
|
2013-04-07 18:02:49 +00:00
|
|
|
with_input_for @user, :country, :country
|
|
|
|
assert_select 'select.required'
|
|
|
|
assert_no_select 'select[aria-required]'
|
|
|
|
end
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|