annotate .svn/pristine/a1/a13b287b0ac6810b1dd4f043e22916c40ff94b84.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@1517 19 require 'redmine/field_format'
Chris@1517 20
Chris@1517 21 class Redmine::ListFieldFormatTest < ActionView::TestCase
Chris@1517 22 include ApplicationHelper
Chris@1517 23 include Redmine::I18n
Chris@1517 24
Chris@1517 25 def setup
Chris@1517 26 set_language_if_valid 'en'
Chris@1517 27 end
Chris@1517 28
Chris@1517 29 def test_possible_existing_value_should_be_valid
Chris@1517 30 field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar'])
Chris@1517 31 group = Group.new(:name => 'Group')
Chris@1517 32 group.custom_field_values = {field.id => 'Baz'}
Chris@1517 33 assert group.save(:validate => false)
Chris@1517 34
Chris@1517 35 group = Group.order('id DESC').first
Chris@1517 36 assert_equal ['Foo', 'Bar', 'Baz'], field.possible_custom_value_options(group.custom_value_for(field))
Chris@1517 37 assert group.valid?
Chris@1517 38 end
Chris@1517 39
Chris@1517 40 def test_edit_tag_should_have_id_and_name
Chris@1517 41 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
Chris@1517 42 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
Chris@1517 43
Chris@1517 44 tag = field.format.edit_tag(self, 'abc', 'xyz', value)
Chris@1517 45 assert_select_in tag, 'select[id=abc][name=xyz]'
Chris@1517 46 end
Chris@1517 47
Chris@1517 48 def test_edit_tag_should_contain_possible_values
Chris@1517 49 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
Chris@1517 50 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
Chris@1517 51
Chris@1517 52 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 53 assert_select_in tag, 'select' do
Chris@1517 54 assert_select 'option', 3
Chris@1517 55 assert_select 'option[value=]'
Chris@1517 56 assert_select 'option[value=Foo]', :text => 'Foo'
Chris@1517 57 assert_select 'option[value=Bar]', :text => 'Bar'
Chris@1517 58 end
Chris@1517 59 end
Chris@1517 60
Chris@1517 61 def test_edit_tag_should_select_current_value
Chris@1517 62 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
Chris@1517 63 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
Chris@1517 64
Chris@1517 65 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 66 assert_select_in tag, 'select' do
Chris@1517 67 assert_select 'option[selected=selected]', 1
Chris@1517 68 assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
Chris@1517 69 end
Chris@1517 70 end
Chris@1517 71
Chris@1517 72 def test_edit_tag_with_multiple_should_select_current_values
Chris@1517 73 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
Chris@1517 74 :multiple => true)
Chris@1517 75 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
Chris@1517 76
Chris@1517 77 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 78 assert_select_in tag, 'select[multiple=multiple]' do
Chris@1517 79 assert_select 'option[selected=selected]', 2
Chris@1517 80 assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
Chris@1517 81 assert_select 'option[value=Baz][selected=selected]', :text => 'Baz'
Chris@1517 82 end
Chris@1517 83 end
Chris@1517 84
Chris@1517 85 def test_edit_tag_with_check_box_style_should_contain_possible_values
Chris@1517 86 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
Chris@1517 87 :edit_tag_style => 'check_box')
Chris@1517 88 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
Chris@1517 89
Chris@1517 90 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 91 assert_select_in tag, 'span' do
Chris@1517 92 assert_select 'input[type=radio]', 3
Chris@1517 93 assert_select 'label', :text => '(none)' do
Chris@1517 94 assert_select 'input[value=]'
Chris@1517 95 end
Chris@1517 96 assert_select 'label', :text => 'Foo' do
Chris@1517 97 assert_select 'input[value=Foo]'
Chris@1517 98 end
Chris@1517 99 assert_select 'label', :text => 'Bar' do
Chris@1517 100 assert_select 'input[value=Bar]'
Chris@1517 101 end
Chris@1517 102 end
Chris@1517 103 end
Chris@1517 104
Chris@1517 105 def test_edit_tag_with_check_box_style_should_select_current_value
Chris@1517 106 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
Chris@1517 107 :edit_tag_style => 'check_box')
Chris@1517 108 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
Chris@1517 109
Chris@1517 110 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 111 assert_select_in tag, 'span' do
Chris@1517 112 assert_select 'input[type=radio][checked=checked]', 1
Chris@1517 113 assert_select 'label', :text => 'Bar' do
Chris@1517 114 assert_select 'input[value=Bar][checked=checked]'
Chris@1517 115 end
Chris@1517 116 end
Chris@1517 117 end
Chris@1517 118
Chris@1517 119 def test_edit_tag_with_check_box_style_and_multiple_values_should_contain_hidden_field_to_clear_value
Chris@1517 120 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
Chris@1517 121 :edit_tag_style => 'check_box', :multiple => true)
Chris@1517 122 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
Chris@1517 123
Chris@1517 124 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 125 assert_select_in tag, 'span' do
Chris@1517 126 assert_select 'input[type=checkbox]', 2
Chris@1517 127 assert_select 'input[type=hidden]', 1
Chris@1517 128 end
Chris@1517 129 end
Chris@1517 130
Chris@1517 131 def test_field_with_url_pattern_should_link_value
Chris@1517 132 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
Chris@1517 133 formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true)
Chris@1517 134 assert_equal '<a href="http://localhost/foo">foo</a>', formatted
Chris@1517 135 assert formatted.html_safe?
Chris@1517 136 end
Chris@1517 137
Chris@1517 138 def test_field_with_url_pattern_and_multiple_values_should_link_values
Chris@1517 139 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
Chris@1517 140 formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true)
Chris@1517 141 assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted
Chris@1517 142 assert formatted.html_safe?
Chris@1517 143 end
Chris@1517 144
Chris@1517 145 def test_field_with_url_pattern_should_not_link_blank_value
Chris@1517 146 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
Chris@1517 147 formatted = field.format.formatted_value(self, field, '', Issue.new, true)
Chris@1517 148 assert_equal '', formatted
Chris@1517 149 assert formatted.html_safe?
Chris@1517 150 end
Chris@1517 151
Chris@1517 152 def test_edit_tag_with_check_box_style_and_multiple_should_select_current_values
Chris@1517 153 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
Chris@1517 154 :multiple => true, :edit_tag_style => 'check_box')
Chris@1517 155 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
Chris@1517 156
Chris@1517 157 tag = field.format.edit_tag(self, 'id', 'name', value)
Chris@1517 158 assert_select_in tag, 'span' do
Chris@1517 159 assert_select 'input[type=checkbox][checked=checked]', 2
Chris@1517 160 assert_select 'label', :text => 'Bar' do
Chris@1517 161 assert_select 'input[value=Bar][checked=checked]'
Chris@1517 162 end
Chris@1517 163 assert_select 'label', :text => 'Baz' do
Chris@1517 164 assert_select 'input[value=Baz][checked=checked]'
Chris@1517 165 end
Chris@1517 166 end
Chris@1517 167 end
Chris@1517 168 end