annotate .svn/pristine/08/081cb3c9d1cc0a40761d7f17097c046e4db924a7.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../base', __FILE__)
Chris@1494 19
Chris@1494 20 class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
Chris@1494 21 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1494 22 :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
Chris@1494 23 :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
Chris@1494 24 :watchers
Chris@1494 25
Chris@1494 26 def test_create_issue
Chris@1494 27 log_user('jsmith', 'jsmith')
Chris@1494 28 visit '/projects/ecookbook/issues/new'
Chris@1494 29 within('form#issue-form') do
Chris@1494 30 select 'Bug', :from => 'Tracker'
Chris@1494 31 select 'Low', :from => 'Priority'
Chris@1494 32 fill_in 'Subject', :with => 'new test issue'
Chris@1494 33 fill_in 'Description', :with => 'new issue'
Chris@1494 34 select '0 %', :from => 'Done'
Chris@1494 35 fill_in 'Due date', :with => ''
Chris@1494 36 fill_in 'Searchable field', :with => 'Value for field 2'
Chris@1494 37 # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
Chris@1494 38 find('input[name=commit]').click
Chris@1494 39 end
Chris@1494 40
Chris@1494 41 # find created issue
Chris@1494 42 issue = Issue.find_by_subject("new test issue")
Chris@1494 43 assert_kind_of Issue, issue
Chris@1494 44
Chris@1494 45 # check redirection
Chris@1494 46 find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created."
Chris@1494 47 assert_equal issue_path(:id => issue), current_path
Chris@1494 48
Chris@1494 49 # check issue attributes
Chris@1494 50 assert_equal 'jsmith', issue.author.login
Chris@1494 51 assert_equal 1, issue.project.id
Chris@1494 52 assert_equal IssueStatus.find_by_name('New'), issue.status
Chris@1494 53 assert_equal Tracker.find_by_name('Bug'), issue.tracker
Chris@1494 54 assert_equal IssuePriority.find_by_name('Low'), issue.priority
Chris@1494 55 assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
Chris@1494 56 end
Chris@1494 57
Chris@1494 58 def test_create_issue_with_form_update
Chris@1494 59 field1 = IssueCustomField.create!(
Chris@1494 60 :field_format => 'string',
Chris@1494 61 :name => 'Field1',
Chris@1494 62 :is_for_all => true,
Chris@1494 63 :trackers => Tracker.find_all_by_id([1, 2])
Chris@1494 64 )
Chris@1494 65 field2 = IssueCustomField.create!(
Chris@1494 66 :field_format => 'string',
Chris@1494 67 :name => 'Field2',
Chris@1494 68 :is_for_all => true,
Chris@1494 69 :trackers => Tracker.find_all_by_id(2)
Chris@1494 70 )
Chris@1494 71
Chris@1494 72 Role.non_member.add_permission! :add_issues
Chris@1494 73 Role.non_member.remove_permission! :edit_issues, :add_issue_notes
Chris@1494 74
Chris@1494 75 log_user('someone', 'foo')
Chris@1494 76 visit '/projects/ecookbook/issues/new'
Chris@1494 77 assert page.has_no_content?(field2.name)
Chris@1494 78 assert page.has_content?(field1.name)
Chris@1494 79
Chris@1494 80 fill_in 'Subject', :with => 'New test issue'
Chris@1494 81 fill_in 'Description', :with => 'New test issue description'
Chris@1494 82 fill_in field1.name, :with => 'CF1 value'
Chris@1494 83 select 'Low', :from => 'Priority'
Chris@1494 84
Chris@1494 85 # field2 should show up when changing tracker
Chris@1494 86 select 'Feature request', :from => 'Tracker'
Chris@1494 87 assert page.has_content?(field2.name)
Chris@1494 88 assert page.has_content?(field1.name)
Chris@1494 89
Chris@1494 90 fill_in field2.name, :with => 'CF2 value'
Chris@1494 91 assert_difference 'Issue.count' do
Chris@1494 92 page.first(:button, 'Create').click
Chris@1494 93 end
Chris@1494 94
Chris@1494 95 issue = Issue.order('id desc').first
Chris@1494 96 assert_equal 'New test issue', issue.subject
Chris@1494 97 assert_equal 'New test issue description', issue.description
Chris@1494 98 assert_equal 'Low', issue.priority.name
Chris@1494 99 assert_equal 'CF1 value', issue.custom_field_value(field1)
Chris@1494 100 assert_equal 'CF2 value', issue.custom_field_value(field2)
Chris@1494 101 end
Chris@1494 102
Chris@1494 103 def test_create_issue_with_watchers
Chris@1494 104 user = User.generate!(:firstname => 'Some', :lastname => 'Watcher')
Chris@1494 105 assert_equal 'Some Watcher', user.name
Chris@1494 106 log_user('jsmith', 'jsmith')
Chris@1494 107 visit '/projects/ecookbook/issues/new'
Chris@1494 108 fill_in 'Subject', :with => 'Issue with watchers'
Chris@1494 109 # Add a project member as watcher
Chris@1494 110 check 'Dave Lopper'
Chris@1494 111 # Search for another user
Chris@1494 112 assert page.has_no_css?('form#new-watcher-form')
Chris@1494 113 assert page.has_no_content?('Some Watcher')
Chris@1494 114 click_link 'Search for watchers to add'
Chris@1494 115 within('form#new-watcher-form') do
Chris@1494 116 assert page.has_content?('Some One')
Chris@1494 117 fill_in 'user_search', :with => 'watch'
Chris@1494 118 assert page.has_no_content?('Some One')
Chris@1494 119 check 'Some Watcher'
Chris@1494 120 click_button 'Add'
Chris@1494 121 end
Chris@1494 122 assert page.has_css?('form#issue-form')
Chris@1494 123 assert page.has_css?('p#watchers_form')
Chris@1494 124 using_wait_time(30) do
Chris@1494 125 within('span#watchers_inputs') do
Chris@1494 126 within("label#issue_watcher_user_ids_#{user.id}") do
Chris@1494 127 assert has_content?('Some Watcher'), "No watcher content"
Chris@1494 128 end
Chris@1494 129 end
Chris@1494 130 end
Chris@1494 131 assert_difference 'Issue.count' do
Chris@1494 132 find('input[name=commit]').click
Chris@1494 133 end
Chris@1494 134
Chris@1494 135 issue = Issue.order('id desc').first
Chris@1494 136 assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort
Chris@1494 137 end
Chris@1494 138
Chris@1494 139 def test_create_issue_start_due_date
Chris@1494 140 with_settings :default_issue_start_date_to_creation_date => 0 do
Chris@1494 141 log_user('jsmith', 'jsmith')
Chris@1494 142 visit '/projects/ecookbook/issues/new'
Chris@1494 143 assert_equal "", page.find('input#issue_start_date').value
Chris@1494 144 assert_equal "", page.find('input#issue_due_date').value
Chris@1494 145 page.first('p#start_date_area img').click
Chris@1494 146 page.first("td.ui-datepicker-days-cell-over a").click
Chris@1494 147 assert_equal Date.today.to_s, page.find('input#issue_start_date').value
Chris@1494 148 page.first('p#due_date_area img').click
Chris@1494 149 page.first("td.ui-datepicker-days-cell-over a").click
Chris@1494 150 assert_equal Date.today.to_s, page.find('input#issue_due_date').value
Chris@1494 151 end
Chris@1494 152 end
Chris@1494 153
Chris@1494 154 def test_create_issue_start_due_date_default
Chris@1494 155 log_user('jsmith', 'jsmith')
Chris@1494 156 visit '/projects/ecookbook/issues/new'
Chris@1494 157 fill_in 'Start date', :with => '2012-04-01'
Chris@1494 158 fill_in 'Due date', :with => ''
Chris@1494 159 page.first('p#due_date_area img').click
Chris@1494 160 page.first("td.ui-datepicker-days-cell-over a").click
Chris@1494 161 assert_equal '2012-04-01', page.find('input#issue_due_date').value
Chris@1494 162
Chris@1494 163 fill_in 'Start date', :with => ''
Chris@1494 164 fill_in 'Due date', :with => '2012-04-01'
Chris@1494 165 page.first('p#start_date_area img').click
Chris@1494 166 page.first("td.ui-datepicker-days-cell-over a").click
Chris@1494 167 assert_equal '2012-04-01', page.find('input#issue_start_date').value
Chris@1494 168 end
Chris@1494 169
Chris@1494 170 def test_preview_issue_description
Chris@1494 171 log_user('jsmith', 'jsmith')
Chris@1494 172 visit '/projects/ecookbook/issues/new'
Chris@1494 173 within('form#issue-form') do
Chris@1494 174 fill_in 'Subject', :with => 'new issue subject'
Chris@1494 175 fill_in 'Description', :with => 'new issue description'
Chris@1494 176 click_link 'Preview'
Chris@1494 177 end
Chris@1494 178 find 'div#preview fieldset', :visible => true, :text => 'new issue description'
Chris@1494 179 assert_difference 'Issue.count' do
Chris@1494 180 find('input[name=commit]').click
Chris@1494 181 end
Chris@1494 182
Chris@1494 183 issue = Issue.order('id desc').first
Chris@1494 184 assert_equal 'new issue description', issue.description
Chris@1494 185 end
Chris@1494 186
Chris@1494 187 def test_update_issue_with_form_update
Chris@1494 188 field = IssueCustomField.create!(
Chris@1494 189 :field_format => 'string',
Chris@1494 190 :name => 'Form update CF',
Chris@1494 191 :is_for_all => true,
Chris@1494 192 :trackers => Tracker.find_all_by_name('Feature request')
Chris@1494 193 )
Chris@1494 194
Chris@1494 195 Role.non_member.add_permission! :edit_issues
Chris@1494 196 Role.non_member.remove_permission! :add_issues, :add_issue_notes
Chris@1494 197
Chris@1494 198 log_user('someone', 'foo')
Chris@1494 199 visit '/issues/1'
Chris@1494 200 assert page.has_no_content?('Form update CF')
Chris@1494 201
Chris@1494 202 page.first(:link, 'Update').click
Chris@1494 203 # the custom field should show up when changing tracker
Chris@1494 204 select 'Feature request', :from => 'Tracker'
Chris@1494 205 assert page.has_content?('Form update CF')
Chris@1494 206
Chris@1494 207 fill_in 'Form update', :with => 'CF value'
Chris@1494 208 assert_no_difference 'Issue.count' do
Chris@1494 209 page.first(:button, 'Submit').click
Chris@1494 210 end
Chris@1494 211
Chris@1494 212 issue = Issue.find(1)
Chris@1494 213 assert_equal 'CF value', issue.custom_field_value(field)
Chris@1494 214 end
Chris@1494 215
Chris@1494 216 def test_remove_issue_watcher_from_sidebar
Chris@1494 217 user = User.find(3)
Chris@1494 218 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@1494 219
Chris@1494 220 log_user('jsmith', 'jsmith')
Chris@1494 221 visit '/issues/1'
Chris@1494 222 assert page.first('#sidebar').has_content?('Watchers (1)')
Chris@1494 223 assert page.first('#sidebar').has_content?(user.name)
Chris@1494 224 assert_difference 'Watcher.count', -1 do
Chris@1494 225 page.first('ul.watchers .user-3 a.delete').click
Chris@1494 226 assert page.first('#sidebar').has_content?('Watchers (0)')
Chris@1494 227 end
Chris@1494 228 assert page.first('#sidebar').has_no_content?(user.name)
Chris@1494 229 end
Chris@1494 230
Chris@1494 231 def test_watch_issue_via_context_menu
Chris@1494 232 log_user('jsmith', 'jsmith')
Chris@1494 233 visit '/issues'
Chris@1494 234 assert page.has_css?('tr#issue-1')
Chris@1494 235 find('tr#issue-1 td.updated_on').click
Chris@1494 236 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
Chris@1494 237 assert_difference 'Watcher.count' do
Chris@1494 238 within('#context-menu') do
Chris@1494 239 click_link 'Watch'
Chris@1494 240 end
Chris@1494 241 assert page.has_css?('tr#issue-1')
Chris@1494 242 end
Chris@1494 243 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
Chris@1494 244 end
Chris@1494 245
Chris@1494 246 def test_bulk_watch_issues_via_context_menu
Chris@1494 247 log_user('jsmith', 'jsmith')
Chris@1494 248 visit '/issues'
Chris@1494 249 assert page.has_css?('tr#issue-1')
Chris@1494 250 assert page.has_css?('tr#issue-4')
Chris@1494 251 find('tr#issue-1 input[type=checkbox]').click
Chris@1494 252 find('tr#issue-4 input[type=checkbox]').click
Chris@1494 253 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
Chris@1494 254 assert_difference 'Watcher.count', 2 do
Chris@1494 255 within('#context-menu') do
Chris@1494 256 click_link 'Watch'
Chris@1494 257 end
Chris@1494 258 assert page.has_css?('tr#issue-1')
Chris@1494 259 assert page.has_css?('tr#issue-4')
Chris@1494 260 end
Chris@1494 261 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
Chris@1494 262 assert Issue.find(4).watched_by?(User.find_by_login('jsmith'))
Chris@1494 263 end
Chris@1494 264 end