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