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