You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issues_test.rb 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 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. require File.expand_path('../base', __FILE__)
  18. class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
  19. fixtures :projects, :users, :roles, :members, :member_roles,
  20. :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
  21. :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
  22. :watchers
  23. def test_create_issue
  24. log_user('jsmith', 'jsmith')
  25. visit '/projects/ecookbook/issues/new'
  26. within('form#issue-form') do
  27. select 'Bug', :from => 'Tracker'
  28. select 'Low', :from => 'Priority'
  29. fill_in 'Subject', :with => 'new test issue'
  30. fill_in 'Description', :with => 'new issue'
  31. select '0 %', :from => 'Done'
  32. fill_in 'Due date', :with => ''
  33. fill_in 'Searchable field', :with => 'Value for field 2'
  34. # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
  35. find('input[name=commit]').click
  36. end
  37. # find created issue
  38. issue = Issue.find_by_subject("new test issue")
  39. assert_kind_of Issue, issue
  40. # check redirection
  41. find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created."
  42. assert_equal issue_path(:id => issue), current_path
  43. # check issue attributes
  44. assert_equal 'jsmith', issue.author.login
  45. assert_equal 1, issue.project.id
  46. assert_equal IssueStatus.find_by_name('New'), issue.status
  47. assert_equal Tracker.find_by_name('Bug'), issue.tracker
  48. assert_equal IssuePriority.find_by_name('Low'), issue.priority
  49. assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
  50. end
  51. def test_create_issue_with_form_update
  52. field1 = IssueCustomField.create!(
  53. :field_format => 'string',
  54. :name => 'Field1',
  55. :is_for_all => true,
  56. :trackers => Tracker.find_all_by_id([1, 2])
  57. )
  58. field2 = IssueCustomField.create!(
  59. :field_format => 'string',
  60. :name => 'Field2',
  61. :is_for_all => true,
  62. :trackers => Tracker.find_all_by_id(2)
  63. )
  64. Role.non_member.add_permission! :add_issues
  65. Role.non_member.remove_permission! :edit_issues, :add_issue_notes
  66. log_user('someone', 'foo')
  67. visit '/projects/ecookbook/issues/new'
  68. assert page.has_no_content?(field2.name)
  69. assert page.has_content?(field1.name)
  70. fill_in 'Subject', :with => 'New test issue'
  71. fill_in 'Description', :with => 'New test issue description'
  72. fill_in field1.name, :with => 'CF1 value'
  73. select 'Low', :from => 'Priority'
  74. # field2 should show up when changing tracker
  75. select 'Feature request', :from => 'Tracker'
  76. assert page.has_content?(field2.name)
  77. assert page.has_content?(field1.name)
  78. fill_in field2.name, :with => 'CF2 value'
  79. assert_difference 'Issue.count' do
  80. page.first(:button, 'Create').click
  81. end
  82. issue = Issue.order('id desc').first
  83. assert_equal 'New test issue', issue.subject
  84. assert_equal 'New test issue description', issue.description
  85. assert_equal 'Low', issue.priority.name
  86. assert_equal 'CF1 value', issue.custom_field_value(field1)
  87. assert_equal 'CF2 value', issue.custom_field_value(field2)
  88. end
  89. def test_create_issue_with_watchers
  90. user = User.generate!(:firstname => 'Some', :lastname => 'Watcher')
  91. assert_equal 'Some Watcher', user.name
  92. log_user('jsmith', 'jsmith')
  93. visit '/projects/ecookbook/issues/new'
  94. fill_in 'Subject', :with => 'Issue with watchers'
  95. # Add a project member as watcher
  96. check 'Dave Lopper'
  97. # Search for another user
  98. assert page.has_no_css?('form#new-watcher-form')
  99. assert page.has_no_content?('Some Watcher')
  100. click_link 'Search for watchers to add'
  101. within('form#new-watcher-form') do
  102. assert page.has_content?('Some One')
  103. fill_in 'user_search', :with => 'watch'
  104. assert page.has_no_content?('Some One')
  105. check 'Some Watcher'
  106. click_button 'Add'
  107. end
  108. assert page.has_css?('form#issue-form')
  109. assert page.has_css?('p#watchers_form')
  110. using_wait_time(30) do
  111. within('span#watchers_inputs') do
  112. within("label#issue_watcher_user_ids_#{user.id}") do
  113. assert has_content?('Some Watcher'), "No watcher content"
  114. end
  115. end
  116. end
  117. assert_difference 'Issue.count' do
  118. find('input[name=commit]').click
  119. end
  120. issue = Issue.order('id desc').first
  121. assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort
  122. end
  123. def test_create_issue_start_due_date
  124. with_settings :default_issue_start_date_to_creation_date => 0 do
  125. log_user('jsmith', 'jsmith')
  126. visit '/projects/ecookbook/issues/new'
  127. assert_equal "", page.find('input#issue_start_date').value
  128. assert_equal "", page.find('input#issue_due_date').value
  129. page.first('p#start_date_area img').click
  130. page.first("td.ui-datepicker-days-cell-over a").click
  131. assert_equal Date.today.to_s, page.find('input#issue_start_date').value
  132. page.first('p#due_date_area img').click
  133. page.first("td.ui-datepicker-days-cell-over a").click
  134. assert_equal Date.today.to_s, page.find('input#issue_due_date').value
  135. end
  136. end
  137. def test_create_issue_start_due_date_default
  138. log_user('jsmith', 'jsmith')
  139. visit '/projects/ecookbook/issues/new'
  140. fill_in 'Start date', :with => '2012-04-01'
  141. fill_in 'Due date', :with => ''
  142. page.first('p#due_date_area img').click
  143. page.first("td.ui-datepicker-days-cell-over a").click
  144. assert_equal '2012-04-01', page.find('input#issue_due_date').value
  145. fill_in 'Start date', :with => ''
  146. fill_in 'Due date', :with => '2012-04-01'
  147. page.first('p#start_date_area img').click
  148. page.first("td.ui-datepicker-days-cell-over a").click
  149. assert_equal '2012-04-01', page.find('input#issue_start_date').value
  150. end
  151. def test_preview_issue_description
  152. log_user('jsmith', 'jsmith')
  153. visit '/projects/ecookbook/issues/new'
  154. within('form#issue-form') do
  155. fill_in 'Subject', :with => 'new issue subject'
  156. fill_in 'Description', :with => 'new issue description'
  157. click_link 'Preview'
  158. end
  159. find 'div#preview fieldset', :visible => true, :text => 'new issue description'
  160. assert_difference 'Issue.count' do
  161. find('input[name=commit]').click
  162. end
  163. issue = Issue.order('id desc').first
  164. assert_equal 'new issue description', issue.description
  165. end
  166. def test_update_issue_with_form_update
  167. field = IssueCustomField.create!(
  168. :field_format => 'string',
  169. :name => 'Form update CF',
  170. :is_for_all => true,
  171. :trackers => Tracker.find_all_by_name('Feature request')
  172. )
  173. Role.non_member.add_permission! :edit_issues
  174. Role.non_member.remove_permission! :add_issues, :add_issue_notes
  175. log_user('someone', 'foo')
  176. visit '/issues/1'
  177. assert page.has_no_content?('Form update CF')
  178. page.first(:link, 'Update').click
  179. # the custom field should show up when changing tracker
  180. select 'Feature request', :from => 'Tracker'
  181. assert page.has_content?('Form update CF')
  182. fill_in 'Form update', :with => 'CF value'
  183. assert_no_difference 'Issue.count' do
  184. page.first(:button, 'Submit').click
  185. end
  186. issue = Issue.find(1)
  187. assert_equal 'CF value', issue.custom_field_value(field)
  188. end
  189. def test_remove_issue_watcher_from_sidebar
  190. user = User.find(3)
  191. Watcher.create!(:watchable => Issue.find(1), :user => user)
  192. log_user('jsmith', 'jsmith')
  193. visit '/issues/1'
  194. assert page.first('#sidebar').has_content?('Watchers (1)')
  195. assert page.first('#sidebar').has_content?(user.name)
  196. assert_difference 'Watcher.count', -1 do
  197. page.first('ul.watchers .user-3 a.delete').click
  198. assert page.first('#sidebar').has_content?('Watchers (0)')
  199. end
  200. assert page.first('#sidebar').has_no_content?(user.name)
  201. end
  202. def test_watch_issue_via_context_menu
  203. log_user('jsmith', 'jsmith')
  204. visit '/issues'
  205. assert page.has_css?('tr#issue-1')
  206. find('tr#issue-1 td.updated_on').click
  207. page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
  208. assert_difference 'Watcher.count' do
  209. within('#context-menu') do
  210. click_link 'Watch'
  211. end
  212. assert page.has_css?('tr#issue-1')
  213. end
  214. assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
  215. end
  216. def test_bulk_watch_issues_via_context_menu
  217. log_user('jsmith', 'jsmith')
  218. visit '/issues'
  219. assert page.has_css?('tr#issue-1')
  220. assert page.has_css?('tr#issue-4')
  221. find('tr#issue-1 input[type=checkbox]').click
  222. find('tr#issue-4 input[type=checkbox]').click
  223. page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
  224. assert_difference 'Watcher.count', 2 do
  225. within('#context-menu') do
  226. click_link 'Watch'
  227. end
  228. assert page.has_css?('tr#issue-1')
  229. assert page.has_css?('tr#issue-4')
  230. end
  231. assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
  232. assert Issue.find(4).watched_by?(User.find_by_login('jsmith'))
  233. end
  234. end