annotate test/ui/issues_test.rb @ 1298:4f746d8966dd redmine_2.3_integration

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