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 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../application_system_test_case'
  19. class IssuesSystemTest < ApplicationSystemTestCase
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  21. :trackers, :projects_trackers, :enabled_modules,
  22. :issue_statuses, :issues, :issue_categories,
  23. :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
  24. :watchers, :journals, :journal_details, :versions,
  25. :workflows
  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 'Searchable field', :with => 'Value for field 2'
  36. # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
  37. find('input[name=commit]').click
  38. end
  39. # find created issue
  40. issue = Issue.find_by_subject("new test issue")
  41. assert_kind_of Issue, issue
  42. # check redirection
  43. find 'div#flash_notice', :visible => true, :text => "Issue ##{issue.id} created."
  44. assert_equal issue_path(:id => issue), current_path
  45. # check issue attributes
  46. assert_equal 'jsmith', issue.author.login
  47. assert_equal 1, issue.project.id
  48. assert_equal IssueStatus.find_by_name('New'), issue.status
  49. assert_equal Tracker.find_by_name('Bug'), issue.tracker
  50. assert_equal IssuePriority.find_by_name('Low'), issue.priority
  51. assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
  52. end
  53. def test_create_issue_with_form_update
  54. field1 = IssueCustomField.create!(
  55. :field_format => 'string',
  56. :name => 'Field1',
  57. :is_for_all => true,
  58. :trackers => Tracker.where(:id => [1, 2])
  59. )
  60. field2 = IssueCustomField.create!(
  61. :field_format => 'string',
  62. :name => 'Field2',
  63. :is_for_all => true,
  64. :trackers => Tracker.where(:id => 2)
  65. )
  66. Role.non_member.add_permission! :add_issues
  67. Role.non_member.remove_permission! :edit_issues, :add_issue_notes
  68. log_user('someone', 'foo')
  69. visit '/projects/ecookbook/issues/new'
  70. assert page.has_no_content?(field2.name)
  71. assert page.has_content?(field1.name)
  72. fill_in 'Subject', :with => 'New test issue'
  73. fill_in 'Description', :with => 'New test issue description'
  74. fill_in field1.name, :with => 'CF1 value'
  75. select 'Low', :from => 'Priority'
  76. # field2 should show up when changing tracker
  77. select 'Feature request', :from => 'Tracker'
  78. assert page.has_content?(field2.name)
  79. assert page.has_content?(field1.name)
  80. fill_in field2.name, :with => 'CF2 value'
  81. assert_difference 'Issue.count' do
  82. page.first(:button, 'Create').click
  83. end
  84. issue = Issue.order('id desc').first
  85. assert_equal 'New test issue', issue.subject
  86. assert_equal 'New test issue description', issue.description
  87. assert_equal 'Low', issue.priority.name
  88. assert_equal 'CF1 value', issue.custom_field_value(field1)
  89. assert_equal 'CF2 value', issue.custom_field_value(field2)
  90. end
  91. def test_create_issue_with_watchers
  92. user = User.generate!(:firstname => 'Some', :lastname => 'Watcher')
  93. assert_equal 'Some Watcher', user.name
  94. log_user('jsmith', 'jsmith')
  95. visit '/projects/ecookbook/issues/new'
  96. fill_in 'Subject', :with => 'Issue with watchers'
  97. # Add a project member as watcher
  98. check 'Dave Lopper'
  99. # Search for another user
  100. assert page.has_no_css?('form#new-watcher-form')
  101. assert page.has_no_content?('Some Watcher')
  102. click_link 'Search for watchers to add'
  103. within('form#new-watcher-form') do
  104. fill_in 'user_search', :with => 'watch'
  105. assert page.has_content?('Some Watcher')
  106. check 'Some Watcher'
  107. click_button 'Add'
  108. end
  109. assert page.has_css?('form#issue-form')
  110. assert page.has_css?('p#watchers_form')
  111. using_wait_time(30) do
  112. within('span#watchers_inputs') do
  113. within("label#issue_watcher_user_ids_#{user.id}") do
  114. assert has_content?('Some Watcher'), "No watcher content"
  115. end
  116. end
  117. end
  118. assert_difference 'Issue.count' do
  119. find('input[name=commit]').click
  120. end
  121. issue = Issue.order('id desc').first
  122. assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort
  123. end
  124. def test_create_issue_with_attachment
  125. set_tmp_attachments_directory
  126. log_user('jsmith', 'jsmith')
  127. issue = new_record(Issue) do
  128. visit '/projects/ecookbook/issues/new'
  129. fill_in 'Subject', :with => 'Issue with attachment'
  130. attach_file 'attachments[dummy][file]', Rails.root.join('test/fixtures/files/testfile.txt')
  131. fill_in 'attachments[1][description]', :with => 'Some description'
  132. click_on 'Create'
  133. end
  134. assert_equal 1, issue.attachments.count
  135. assert_equal 'Some description', issue.attachments.first.description
  136. end
  137. def test_create_issue_with_attachment_when_user_is_not_a_member
  138. set_tmp_attachments_directory
  139. # Set no permission to non-member role
  140. non_member_role = Role.where(:builtin => Role::BUILTIN_NON_MEMBER).first
  141. non_member_role.permissions = []
  142. non_member_role.save
  143. # Set role "Reporter" to non-member users on project ecookbook
  144. membership = Member.find_or_create_by(user_id: Group.non_member.id, project_id: 1)
  145. membership.roles = [Role.find(3)] # Reporter
  146. membership.save
  147. log_user('someone', 'foo')
  148. issue = new_record(Issue) do
  149. visit '/projects/ecookbook/issues/new'
  150. fill_in 'Subject', :with => 'Issue with attachment'
  151. attach_file 'attachments[dummy][file]', Rails.root.join('test/fixtures/files/testfile.txt')
  152. fill_in 'attachments[1][description]', :with => 'Some description'
  153. click_on 'Create'
  154. end
  155. assert_equal 1, issue.attachments.count
  156. assert_equal 'Some description', issue.attachments.first.description
  157. end
  158. def test_create_issue_with_new_target_version
  159. log_user('jsmith', 'jsmith')
  160. assert_difference 'Issue.count' do
  161. assert_difference 'Version.count' do
  162. visit '/projects/ecookbook/issues/new'
  163. fill_in 'Subject', :with => 'With a new version'
  164. click_on 'New version'
  165. within '#ajax-modal' do
  166. fill_in 'Name', :with => '4.0'
  167. click_on 'Create'
  168. end
  169. click_on 'Create'
  170. end
  171. end
  172. issue = Issue.order('id desc').first
  173. assert_not_nil issue.fixed_version
  174. assert_equal '4.0', issue.fixed_version.name
  175. end
  176. def test_preview_issue_description
  177. log_user('jsmith', 'jsmith')
  178. visit '/projects/ecookbook/issues/new'
  179. within('form#issue-form') do
  180. fill_in 'Subject', :with => 'new issue subject'
  181. fill_in 'Description', :with => 'new issue description'
  182. click_link 'Preview'
  183. find 'div.wiki-preview', :visible => true, :text => 'new issue description'
  184. end
  185. assert_difference 'Issue.count' do
  186. click_button('Create')
  187. end
  188. issue = Issue.order('id desc').first
  189. assert_equal 'new issue description', issue.description
  190. end
  191. test "update issue with form update" do
  192. field = IssueCustomField.create!(
  193. :field_format => 'string',
  194. :name => 'Form update CF',
  195. :is_for_all => true,
  196. :trackers => Tracker.where(:name => 'Feature request')
  197. )
  198. Role.non_member.add_permission! :edit_issues, :add_issues
  199. Role.non_member.remove_permission! :add_issue_notes
  200. log_user('someone', 'foo')
  201. visit '/issues/1'
  202. assert page.has_no_content?('Form update CF')
  203. page.first(:link, 'Edit').click
  204. assert page.has_no_select?("issue_status_id")
  205. # the custom field should show up when changing tracker
  206. select 'Feature request', :from => 'Tracker'
  207. assert page.has_content?('Form update CF')
  208. fill_in 'Form update CF', :with => 'CF value'
  209. assert_no_difference 'Issue.count' do
  210. page.first(:button, 'Submit').click
  211. end
  212. assert page.has_css?('#flash_notice')
  213. issue = Issue.find(1)
  214. assert_equal 'CF value', issue.custom_field_value(field)
  215. end
  216. test "update issue status" do
  217. issue = Issue.generate!
  218. log_user('jsmith', 'jsmith')
  219. visit "/issues/#{issue.id}"
  220. page.first(:link, 'Edit').click
  221. assert page.has_select?("issue_status_id", selected: "New")
  222. page.find("#issue_status_id").select("Closed")
  223. assert_no_difference 'Issue.count' do
  224. page.first(:button, 'Submit').click
  225. end
  226. assert page.has_css?('#flash_notice')
  227. assert_equal 5, issue.reload.status.id
  228. end
  229. def test_update_issue_with_form_update_should_keep_newly_added_attachments
  230. set_tmp_attachments_directory
  231. log_user('jsmith', 'jsmith')
  232. visit '/issues/2'
  233. page.first(:link, 'Edit').click
  234. attach_file 'attachments[dummy][file]', Rails.root.join('test/fixtures/files/testfile.txt')
  235. assert page.has_css?('span#attachments_1')
  236. page.find("#issue_status_id").select("Closed")
  237. # check that attachment still exists on the page
  238. assert page.has_css?('span#attachments_1')
  239. click_on 'Submit'
  240. assert_equal 1, Issue.find(2).attachments.count
  241. end
  242. test "removing issue shows confirm dialog" do
  243. log_user('jsmith', 'jsmith')
  244. visit '/issues/1'
  245. page.accept_confirm /Are you sure/ do
  246. first('#content span.icon-actions').click
  247. first('#content a.icon-del').click
  248. end
  249. end
  250. def test_remove_issue_watcher_from_sidebar
  251. user = User.find(3)
  252. Watcher.create!(:watchable => Issue.find(1), :user => user)
  253. log_user('jsmith', 'jsmith')
  254. visit '/issues/1'
  255. assert page.first('#sidebar').has_content?('Watchers (1)')
  256. assert page.first('#sidebar').has_content?(user.name)
  257. assert_difference 'Watcher.count', -1 do
  258. page.first('ul.watchers .user-3 a.delete').click
  259. assert page.first('#sidebar').has_content?('Watchers (0)')
  260. end
  261. assert page.first('#sidebar').has_no_content?(user.name)
  262. end
  263. def test_watch_should_update_watchers_list
  264. user = User.find(2)
  265. log_user('jsmith', 'jsmith')
  266. visit '/issues/1'
  267. assert page.first('#sidebar').has_content?('Watchers (0)')
  268. page.first('a.issue-1-watcher').click
  269. assert page.first('#sidebar').has_content?('Watchers (1)')
  270. assert page.first('#sidebar').has_content?(user.name)
  271. end
  272. def test_watch_issue_via_context_menu
  273. log_user('jsmith', 'jsmith')
  274. visit '/issues'
  275. jsmith = User.find_by_login('jsmith')
  276. issue1 = Issue.find(1)
  277. assert_not issue1.reload.watched_by?(jsmith)
  278. assert page.has_css?('tr#issue-1')
  279. find('tr#issue-1 td.updated_on').click
  280. find('tr#issue-1 td.updated_on').right_click
  281. assert page.has_css?('#context-menu .issue-1-watcher.icon-fav-off')
  282. assert_difference 'Watcher.count' do
  283. within('#context-menu') do
  284. click_link 'Watch'
  285. end
  286. # wait for ajax response
  287. assert page.has_css?('#context-menu .issue-1-watcher.icon-fav')
  288. assert page.has_css?('tr#issue-1')
  289. end
  290. assert issue1.reload.watched_by?(jsmith)
  291. end
  292. def test_change_watch_or_unwatch_icon_from_sidebar
  293. user = User.find(2)
  294. log_user('jsmith', 'jsmith')
  295. visit '/issues/1'
  296. assert page.has_css?('#content .contextual .issue-1-watcher.icon-fav-off')
  297. # add watcher 'jsmith' from sidebar
  298. page.find('#watchers .contextual a', :text => 'Add').click
  299. page.find('#users_for_watcher label', :text => 'John Smith').click
  300. page.find('#new-watcher-form p.buttons input[type=submit]').click
  301. assert page.has_css?('#content .contextual .issue-1-watcher.icon-fav')
  302. # remove watcher 'jsmith' from sidebar
  303. page.find('#watchers ul li.user-2 a.delete').click
  304. assert page.has_css?('#content .contextual .issue-1-watcher.icon-fav-off')
  305. end
  306. def test_bulk_watch_issues_via_context_menu
  307. log_user('jsmith', 'jsmith')
  308. visit '/issues'
  309. jsmith = User.find_by_login('jsmith')
  310. issue1 = Issue.find(1)
  311. issue4 = Issue.find(4)
  312. assert_not issue1.reload.watched_by?(jsmith)
  313. assert_not issue4.reload.watched_by?(jsmith)
  314. assert page.has_css?('tr#issue-1')
  315. assert page.has_css?('tr#issue-4')
  316. find('tr#issue-1 input[type=checkbox]').click
  317. find('tr#issue-4 input[type=checkbox]').click
  318. find('tr#issue-1 td.updated_on').right_click
  319. assert page.has_css?('#context-menu .issue-bulk-watcher.icon-fav-off')
  320. assert_difference 'Watcher.count', 2 do
  321. within('#context-menu') do
  322. find_link('Watch').hover.click
  323. end
  324. # wait for ajax response
  325. assert page.has_css?('#context-menu .issue-bulk-watcher.icon-fav')
  326. assert page.has_css?('tr#issue-1')
  327. assert page.has_css?('tr#issue-4')
  328. end
  329. assert issue1.reload.watched_by?(jsmith)
  330. assert issue4.reload.watched_by?(jsmith)
  331. end
  332. def test_bulk_update_issues
  333. log_user('jsmith', 'jsmith')
  334. visit '/issues'
  335. issue1 = Issue.find(1)
  336. issue4 = Issue.find(4)
  337. assert_equal 1, issue1.reload.status.id
  338. assert_equal 1, issue4.reload.status.id
  339. assert page.has_css?('tr#issue-1')
  340. assert page.has_css?('tr#issue-4')
  341. find('tr#issue-1 input[type=checkbox]').click
  342. find('tr#issue-4 input[type=checkbox]').click
  343. find('tr#issue-1 td.updated_on').right_click
  344. within('#context-menu') do
  345. click_link 'Status'
  346. click_link 'Closed'
  347. end
  348. assert page.has_css?('#flash_notice')
  349. assert_equal 5, issue1.reload.status.id
  350. assert_equal 5, issue4.reload.status.id
  351. end
  352. def test_bulk_edit
  353. log_user('jsmith', 'jsmith')
  354. visit '/issues'
  355. issue1 = Issue.find(1)
  356. issue4 = Issue.find(4)
  357. assert_equal 1, issue1.reload.status.id
  358. assert_equal 1, issue4.reload.status.id
  359. assert page.has_css?('tr#issue-1')
  360. assert page.has_css?('tr#issue-4')
  361. find('tr#issue-1 input[type=checkbox]').click
  362. find('tr#issue-4 input[type=checkbox]').click
  363. find('tr#issue-1 td.updated_on').right_click
  364. within('#context-menu') do
  365. click_link 'Bulk edit'
  366. end
  367. assert_current_path '/issues/bulk_edit', :ignore_query => true
  368. submit_buttons = page.all('input[type=submit]')
  369. assert_equal 1, submit_buttons.size
  370. assert_equal 'Submit', submit_buttons[0].value
  371. page.find('#issue_status_id').select('Assigned')
  372. assert_no_difference 'Issue.count' do
  373. click_button('commit')
  374. # wait for ajax response
  375. assert page.has_css?('#flash_notice')
  376. assert_current_path '/issues', :ignore_query => true
  377. end
  378. assert_equal 2, issue1.reload.status.id
  379. assert_equal 2, issue4.reload.status.id
  380. assert page.has_css?('tr#issue-1')
  381. assert page.has_css?('tr#issue-4')
  382. find('tr#issue-1 input[type=checkbox]').click
  383. find('tr#issue-4 input[type=checkbox]').click
  384. find('tr#issue-1 td.updated_on').right_click
  385. within('#context-menu') do
  386. click_link 'Bulk edit'
  387. end
  388. assert_current_path '/issues/bulk_edit', :ignore_query => true
  389. submit_buttons = page.all('input[type=submit]')
  390. assert_equal 1, submit_buttons.size
  391. assert_equal 'Submit', submit_buttons[0].value
  392. page.find('#issue_project_id').select('OnlineStore')
  393. # wait for ajax response
  394. assert page.has_select?('issue_project_id', selected: 'OnlineStore')
  395. assert_selector 'input[type=submit]', count: 2
  396. submit_buttons = page.all('input[type=submit]')
  397. assert_equal 'Move', submit_buttons[0].value
  398. assert_equal 'Move and follow', submit_buttons[1].value
  399. page.find('#issue_status_id').select('Feedback')
  400. assert_no_difference 'Issue.count' do
  401. click_button('follow')
  402. # wait for ajax response
  403. assert page.has_css?('#flash_notice')
  404. assert_current_path '/projects/onlinestore/issues', :ignore_query => true
  405. end
  406. issue1.reload
  407. issue4.reload
  408. assert_equal 2, issue1.project.id
  409. assert_equal 4, issue1.status.id
  410. assert_equal 2, issue4.project.id
  411. assert_equal 4, issue4.status.id
  412. end
  413. def test_bulk_copy
  414. log_user('jsmith', 'jsmith')
  415. visit '/issues'
  416. assert page.has_css?('tr#issue-1')
  417. assert page.has_css?('tr#issue-4')
  418. find('tr#issue-1 input[type=checkbox]').click
  419. find('tr#issue-4 input[type=checkbox]').click
  420. find('tr#issue-1 td.updated_on').right_click
  421. within('#context-menu') do
  422. click_link 'Copy'
  423. end
  424. assert_current_path '/issues/bulk_edit', :ignore_query => true
  425. submit_buttons = page.all('input[type=submit]')
  426. assert_equal 'Copy', submit_buttons[0].value
  427. page.find('#issue_priority_id').select('Low')
  428. assert_difference 'Issue.count', 2 do
  429. submit_buttons[0].click
  430. # wait for ajax response
  431. assert page.has_css?('#flash_notice')
  432. assert_current_path '/issues', :ignore_query => true
  433. end
  434. copies = Issue.order('id DESC').limit(2)
  435. assert_equal 4, copies[0].priority.id
  436. assert_equal 4, copies[1].priority.id
  437. assert page.has_css?('tr#issue-1')
  438. assert page.has_css?('tr#issue-4')
  439. find('tr#issue-1 input[type=checkbox]').click
  440. find('tr#issue-4 input[type=checkbox]').click
  441. find('tr#issue-1 td.updated_on').right_click
  442. within('#context-menu') do
  443. click_link 'Copy'
  444. end
  445. assert_current_path '/issues/bulk_edit', :ignore_query => true
  446. submit_buttons = page.all('input[type=submit]')
  447. assert_equal 'Copy', submit_buttons[0].value
  448. page.find('#issue_project_id').select('OnlineStore')
  449. # wait for ajax response
  450. assert page.has_select?('issue_project_id', selected: 'OnlineStore')
  451. assert_selector 'input[type=submit]', count: 2
  452. submit_buttons = page.all('input[type=submit]')
  453. assert_equal 'Copy', submit_buttons[0].value
  454. assert_equal 'Copy and follow', submit_buttons[1].value
  455. page.find('#issue_priority_id').select('High')
  456. assert_difference 'Issue.count', 2 do
  457. submit_buttons[1].click
  458. # wait for ajax response
  459. assert page.has_css?('#flash_notice')
  460. assert_current_path '/projects/onlinestore/issues', :ignore_query => true
  461. end
  462. copies = Issue.order('id DESC').limit(2)
  463. assert_equal 2, copies[0].project.id
  464. assert_equal 6, copies[0].priority.id
  465. assert_equal 2, copies[1].project.id
  466. assert_equal 6, copies[1].priority.id
  467. end
  468. def test_issue_list_with_default_totalable_columns
  469. log_user('admin', 'admin')
  470. with_settings :issue_list_default_totals => ['estimated_hours'] do
  471. visit '/projects/ecookbook/issues'
  472. # Check that the page shows the Estimated hours total
  473. assert page.has_css?('p.query-totals')
  474. assert page.has_css?('span.total-for-estimated-hours')
  475. # Open the Options of the form (necessary for having the totalable columns options clickable)
  476. page.all('legend')[1].click
  477. # Deselect the default totalable column (none should be left)
  478. page.first('input[name="t[]"][value="estimated_hours"]').click
  479. within('#query_form') do
  480. click_link 'Apply'
  481. end
  482. # Check that Totals are not present in the reloaded page
  483. assert !page.has_css?('p.query-totals')
  484. assert !page.has_css?('span.total-for-estimated-hours')
  485. end
  486. end
  487. def test_update_journal_notes_with_preview
  488. log_user('admin', 'admin')
  489. visit '/issues/1'
  490. assert page.first('#journal-2-notes').has_content?('Some notes with Redmine links')
  491. # Click on the edit button
  492. page.first('#change-2 a.icon-edit').click
  493. # Check that the textarea is displayed
  494. assert page.has_css?('#change-2 textarea')
  495. assert page.first('#change-2 textarea').has_content?('Some notes with Redmine links')
  496. # Update the notes
  497. fill_in 'Notes', :with => 'Updated notes'
  498. # Preview the change
  499. page.first('#change-2 a.tab-preview').click
  500. assert page.has_css?('#preview_journal_2_notes')
  501. assert page.first('#preview_journal_2_notes').has_content?('Updated notes')
  502. # Save
  503. click_on 'Save'
  504. assert page.first('#journal-2-notes').has_content?('Updated notes')
  505. assert_equal 'Updated notes', Journal.find(2).notes
  506. end
  507. def test_index_as_csv_should_reflect_sort
  508. log_user('admin', 'admin')
  509. visit '/issues'
  510. # Sort issues by subject
  511. click_on 'Subject'
  512. click_on 'CSV'
  513. click_on 'Export'
  514. csv = CSV.read(downloaded_file("issues.csv"))
  515. subject_index = csv.shift.index('Subject')
  516. subjects = csv.pluck(subject_index)
  517. assert_equal subjects.sort, subjects
  518. end
  519. def test_issue_trackers_description_should_select_tracker
  520. log_user('admin', 'admin')
  521. visit '/issues/1'
  522. page.driver.execute_script('$.fx.off = true;')
  523. page.first(:link, 'Edit').click
  524. page.click_link('View all trackers description')
  525. assert page.has_css?('#trackers_description')
  526. within('#trackers_description') do
  527. click_link('Feature')
  528. end
  529. assert !page.has_css?('#trackers_description')
  530. assert_equal "2", page.find('select#issue_tracker_id').value
  531. end
  532. def test_edit_should_allow_adding_multiple_relations_from_autocomplete
  533. log_user('admin', 'admin')
  534. visit '/issues/1'
  535. page.find('#relations .contextual a').click
  536. page.fill_in 'relation[issue_to_id]', :with => 'issue'
  537. within('ul.ui-autocomplete') do
  538. assert page.has_text? 'Bug #12: Closed issue on a locked version'
  539. assert page.has_text? 'Bug #11: Closed issue on a closed version'
  540. first('li.ui-menu-item').click
  541. end
  542. assert_equal '12, ', find('#relation_issue_to_id').value
  543. find('#relation_issue_to_id').click.send_keys('issue due')
  544. within('ul.ui-autocomplete') do
  545. assert page.has_text? 'Bug #7: Issue due today'
  546. find('li.ui-menu-item').click
  547. end
  548. assert_equal '12, 7, ', find('#relation_issue_to_id').value
  549. find('#relations').click_button('Add')
  550. within('#relations table.issues') do
  551. assert page.has_text? 'Related to Bug #12'
  552. assert page.has_text? 'Related to Bug #7'
  553. end
  554. end
  555. def test_update_issue_form_should_include_time_entry_form_only_for_users_with_permission
  556. log_user('jsmith', 'jsmith')
  557. visit '/issues/2'
  558. page.first(:link, 'Edit').click
  559. # assert log time form exits for user with required permissions on the current project
  560. assert page.has_css?('#log_time')
  561. # Change project to trigger an update on issue form
  562. page.find('#issue_project_id').select('» Private child of eCookbook')
  563. wait_for_ajax
  564. # assert log time form does not exist anymore for user without required permissions on the new project
  565. assert page.has_no_css?('#log_time')
  566. end
  567. def test_update_issue_form_should_include_add_notes_form_only_for_users_with_permission
  568. log_user('jsmith', 'jsmith')
  569. visit '/issues/2'
  570. page.first(:link, 'Edit').click
  571. # assert add notes form exits for user with required permissions on the current project
  572. assert page.has_css?('#add_notes')
  573. # remove add issue notes permission from Manager role
  574. Role.find_by_name('Manager').remove_permission! :add_issue_notes
  575. # Change project to trigger an update on issue form
  576. page.find('#issue_project_id').select('» Private child of eCookbook')
  577. wait_for_ajax
  578. # assert add notes form does not exist anymore for user without required permissions on the new project
  579. assert page.has_no_css?('#add_notes')
  580. end
  581. end