You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom_fields_helper_test.rb 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class CustomFieldsHelperTest < Redmine::HelperTest
  20. include ApplicationHelper
  21. include CustomFieldsHelper
  22. include ERB::Util
  23. def test_format_boolean_value
  24. I18n.locale = 'en'
  25. assert_equal 'Yes', format_value('1', CustomField.new(:field_format => 'bool'))
  26. assert_equal 'No', format_value('0', CustomField.new(:field_format => 'bool'))
  27. end
  28. def test_label_tag_should_include_description_as_span_title_if_present
  29. field = CustomField.new(:field_format => 'string', :description => 'This is the description')
  30. tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
  31. assert_select_in tag, 'label span[title=?]', 'This is the description'
  32. end
  33. def test_label_tag_should_not_include_title_if_description_is_blank
  34. field = CustomField.new(:field_format => 'string')
  35. tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
  36. assert_select_in tag, 'label span[title]', 0
  37. end
  38. def test_label_tag_should_include_for_attribute_for_select_tag
  39. field = CustomField.new(:name => 'Foo', :field_format => 'list')
  40. s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
  41. assert_select_in s, 'label[for]'
  42. end
  43. def test_label_tag_should_not_include_for_attribute_for_checkboxes
  44. field = CustomField.new(:name => 'Foo', :field_format => 'list', :edit_tag_style => 'check_box')
  45. s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
  46. assert_select_in s, 'label:not([for])'
  47. end
  48. def test_label_tag_should_include_for_attribute_for_bool_as_select_tag
  49. field = CustomField.new(:name => 'Foo', :field_format => 'bool')
  50. s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
  51. assert_select_in s, 'label[for]'
  52. end
  53. def test_label_tag_should_include_for_attribute_for_bool_as_checkbox
  54. field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'check_box')
  55. s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
  56. assert_select_in s, 'label[for]'
  57. end
  58. def test_label_tag_should_not_include_for_attribute_for_bool_as_radio
  59. field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'radio')
  60. s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
  61. assert_select_in s, 'label:not([for])'
  62. end
  63. def test_unknow_field_format_should_be_edited_as_string
  64. field = CustomField.new(:field_format => 'foo')
  65. value = CustomValue.new(:value => 'bar', :custom_field => field)
  66. field.id = 52
  67. assert_select_in custom_field_tag('object', value),
  68. 'input[type=text][value=bar][name=?]', 'object[custom_field_values][52]'
  69. end
  70. def test_unknow_field_format_should_be_bulk_edited_as_string
  71. field = CustomField.new(:field_format => 'foo')
  72. field.id = 52
  73. assert_select_in custom_field_tag_for_bulk_edit('object', field),
  74. 'input[type=text][value=""][name=?]', 'object[custom_field_values][52]'
  75. end
  76. def test_custom_field_tag_class_should_contain_wiki_edit_for_custom_fields_with_full_text_formatting
  77. field = IssueCustomField.create!(:name => 'Long text', :field_format => 'text', :text_formatting => 'full')
  78. value = CustomValue.new(:value => 'bar', :custom_field => field)
  79. assert_select_in custom_field_tag('object', value), 'textarea[class=?]', 'text_cf wiki-edit'
  80. end
  81. def test_select_type_radio_buttons
  82. result = select_type_radio_buttons('UserCustomField')
  83. assert_select_in result, 'input[type="radio"]', :count => 10
  84. assert_select_in result, 'input#type_UserCustomField[checked=?]', 'checked'
  85. result = select_type_radio_buttons(nil)
  86. assert_select_in result, 'input[type="radio"]', :count => 10
  87. assert_select_in result, 'input#type_IssueCustomField[checked=?]', 'checked'
  88. end
  89. end