Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

reports_controller_test.rb 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 '../test_helper'
  19. class ReportsControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :versions,
  28. :workflows
  29. def test_get_issue_report
  30. get(
  31. :issue_report,
  32. :params => {
  33. :id => 1
  34. }
  35. )
  36. assert_response :success
  37. end
  38. def test_issue_report_with_subprojects_issues
  39. project = Project.find(1)
  40. tracker = project.trackers.find_by(:name => 'Support request')
  41. project.trackers.delete(tracker)
  42. with_settings :display_subprojects_issues => '1' do
  43. get(
  44. :issue_report,
  45. :params => {
  46. :id => 1
  47. }
  48. )
  49. assert_response :success
  50. # Count subprojects issues
  51. assert_select 'table.list tbody :nth-child(1):first' do
  52. assert_select 'td', :text => 'Bug'
  53. assert_select ':nth-child(2)', :text => '5' # open
  54. assert_select ':nth-child(3)', :text => '3' # closed
  55. assert_select ':nth-child(4)', :text => '8' # total
  56. end
  57. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 1
  58. end
  59. end
  60. def test_issue_report_without_subprojects_issues
  61. project = Project.find(1)
  62. tracker = project.trackers.find_by(:name => 'Support request')
  63. project.trackers.delete(tracker)
  64. with_settings :display_subprojects_issues => '0' do
  65. get(
  66. :issue_report,
  67. :params => {
  68. :id => 1
  69. }
  70. )
  71. assert_response :success
  72. # Do not count subprojects issues
  73. assert_select 'table.list tbody :nth-child(1):first' do
  74. assert_select 'td', :text => 'Bug'
  75. assert_select ':nth-child(2)', :text => '3' # open
  76. assert_select ':nth-child(3)', :text => '3' # closed
  77. assert_select ':nth-child(4)', :text => '6' # total
  78. end
  79. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 0
  80. end
  81. end
  82. def test_get_issue_report_details
  83. %w(tracker version priority category assigned_to author subproject).each do |detail|
  84. get(
  85. :issue_report_details,
  86. :params => {
  87. :id => 1,
  88. :detail => detail
  89. }
  90. )
  91. assert_response :success
  92. end
  93. end
  94. def test_get_issue_report_details_by_tracker_should_show_only_statuses_used_by_the_project
  95. WorkflowTransition.delete_all
  96. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
  97. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
  98. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 5)
  99. WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 6)
  100. with_settings :display_subprojects_issues => '0' do
  101. get(:issue_report_details, :params => {:id => 1, :detail => 'tracker'})
  102. end
  103. assert_response :success
  104. assert_select 'table.list tbody :nth-child(1)' do
  105. assert_select 'td', :text => 'Bug'
  106. assert_select ':nth-child(2)', :text => '3' # status:1
  107. assert_select ':nth-child(3)', :text => '-' # status:2
  108. assert_select ':nth-child(4)', :text => '-' # status:4
  109. assert_select ':nth-child(5)', :text => '3' # status:5
  110. assert_select ':nth-child(6)', :text => '-' # status:6
  111. assert_select ':nth-child(7)', :text => '3' # open
  112. assert_select ':nth-child(8)', :text => '3' # closed
  113. assert_select ':nth-child(9)', :text => '6' # total
  114. end
  115. end
  116. def test_get_issue_report_details_by_tracker_with_subprojects_issues
  117. project = Project.find(1)
  118. tracker = project.trackers.find_by(:name => 'Support request')
  119. project.trackers.delete(tracker)
  120. with_settings :display_subprojects_issues => '1' do
  121. get(
  122. :issue_report_details,
  123. :params => {
  124. :id => 1,
  125. :detail => 'tracker'
  126. }
  127. )
  128. assert_response :success
  129. # Count subprojects issues
  130. assert_select 'table.list tbody :nth-child(1)' do
  131. assert_select 'td', :text => 'Bug'
  132. assert_select ':nth-child(2)', :text => '5' # status:1
  133. assert_select ':nth-child(3)', :text => '-' # status:2
  134. assert_select ':nth-child(4)', :text => '-' # status:3
  135. assert_select ':nth-child(5)', :text => '-' # status:4
  136. assert_select ':nth-child(6)', :text => '3' # status:5
  137. assert_select ':nth-child(7)', :text => '-' # status:6
  138. assert_select ':nth-child(8)', :text => '5' # open
  139. assert_select ':nth-child(9)', :text => '3' # closed
  140. assert_select ':nth-child(10)', :text => '8' # total
  141. end
  142. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 1
  143. end
  144. end
  145. def test_get_issue_report_details_by_tracker_without_subprojects_issues
  146. project = Project.find(1)
  147. tracker = project.trackers.find_by(:name => 'Support request')
  148. project.trackers.delete(tracker)
  149. with_settings :display_subprojects_issues => '0' do
  150. get :issue_report_details, :params => {
  151. :id => 1,
  152. :detail => 'tracker'
  153. }
  154. assert_response :success
  155. # Do not count subprojects issues
  156. assert_select 'table.list tbody :nth-child(1)' do
  157. assert_select 'td', :text => 'Bug'
  158. assert_select ':nth-child(2)', :text => '3' # status:1
  159. assert_select ':nth-child(3)', :text => '-' # status:2
  160. assert_select ':nth-child(4)', :text => '-' # status:3
  161. assert_select ':nth-child(5)', :text => '-' # status:4
  162. assert_select ':nth-child(6)', :text => '3' # status:5
  163. assert_select ':nth-child(7)', :text => '-' # status:6
  164. assert_select ':nth-child(8)', :text => '3' # open
  165. assert_select ':nth-child(9)', :text => '3' # closed
  166. assert_select ':nth-child(10)', :text => '6' # total
  167. end
  168. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 0
  169. end
  170. end
  171. def test_get_issue_report_details_by_tracker_should_show_issue_count
  172. Issue.delete_all
  173. Issue.generate!(:tracker_id => 1)
  174. Issue.generate!(:tracker_id => 1)
  175. Issue.generate!(:tracker_id => 1, :status_id => 5)
  176. Issue.generate!(:tracker_id => 2)
  177. get(
  178. :issue_report_details,
  179. :params => {
  180. :id => 1,
  181. :detail => 'tracker'
  182. }
  183. )
  184. assert_select 'table.list tbody :nth-child(1)' do
  185. assert_select 'td', :text => 'Bug'
  186. assert_select ':nth-child(2)', :text => '2' # status:1
  187. assert_select ':nth-child(3)', :text => '-' # status:2
  188. assert_select ':nth-child(8)', :text => '2' # open
  189. assert_select ':nth-child(9)', :text => '1' # closed
  190. assert_select ':nth-child(10)', :text => '3' # total
  191. end
  192. end
  193. def test_get_issue_report_details_by_assignee_should_show_non_assigned_issue_count
  194. Issue.delete_all
  195. Issue.generate!
  196. Issue.generate!
  197. Issue.generate!(:status_id => 5)
  198. Issue.generate!(:assigned_to_id => 2)
  199. get(
  200. :issue_report_details,
  201. :params => {
  202. :id => 1,
  203. :detail => 'assigned_to'
  204. }
  205. )
  206. assert_select 'table.list tbody :last-child' do
  207. assert_select 'td', :text => "[#{I18n.t(:label_none)}]"
  208. assert_select ':nth-child(2)', :text => '2' # status:1
  209. assert_select ':nth-child(6)', :text => '1' # status:5
  210. assert_select ':nth-child(8)', :text => '2' # open
  211. assert_select ':nth-child(9)', :text => '1' # closed
  212. assert_select ':nth-child(10)', :text => '3' # total
  213. end
  214. end
  215. def test_get_issue_report_details_with_an_invalid_detail
  216. get(
  217. :issue_report_details,
  218. :params => {
  219. :id => 1,
  220. :detail => 'invalid'
  221. }
  222. )
  223. assert_response 404
  224. end
  225. def test_issue_report_details_should_csv_export
  226. %w(tracker version priority category assigned_to author subproject).each do |detail|
  227. get(
  228. :issue_report_details,
  229. params: {
  230. id: 1,
  231. detail: detail,
  232. format: 'csv'
  233. }
  234. )
  235. assert_response :success
  236. assert_equal 'text/csv; header=present', response.media_type
  237. end
  238. end
  239. def test_issue_report_details_with_tracker_detail_should_csv_export
  240. project = Project.find(1)
  241. tracker = project.trackers.find_by(:name => 'Support request')
  242. project.trackers.delete(tracker)
  243. with_settings :display_subprojects_issues => '1' do
  244. get(
  245. :issue_report_details,
  246. params: {
  247. id: 1,
  248. detail: 'tracker',
  249. format: 'csv'
  250. }
  251. )
  252. assert_response :success
  253. assert_equal 'text/csv; header=present', response.media_type
  254. lines = response.body.chomp.split("\n")
  255. # Number of lines
  256. rows = Project.find(1).rolled_up_trackers(true).visible
  257. assert_equal rows.size + 1, lines.size
  258. # Header
  259. assert_equal '"",New,Assigned,Resolved,Feedback,Closed,Rejected,open,closed,Total', lines.first
  260. # Details
  261. to_test = [
  262. 'Bug,5,0,0,0,3,0,5,3,8',
  263. 'Feature request,0,1,0,0,0,0,1,0,1',
  264. 'Support request,0,0,0,0,0,0,0,0,0'
  265. ]
  266. to_test.each do |expected|
  267. assert_includes lines, expected
  268. end
  269. end
  270. end
  271. def test_issue_report_details_with_assigned_to_detail_should_csv_export
  272. Issue.delete_all
  273. Issue.generate!
  274. Issue.generate!
  275. Issue.generate!(:status_id => 5)
  276. Issue.generate!(:assigned_to_id => 2)
  277. with_settings :issue_group_assignment => '1' do
  278. get(
  279. :issue_report_details,
  280. params: {
  281. id: 1,
  282. detail: 'assigned_to',
  283. format: 'csv'
  284. }
  285. )
  286. assert_response :success
  287. assert_equal 'text/csv; header=present', response.media_type
  288. lines = response.body.chomp.split("\n")
  289. # Number of lines
  290. rows = Project.find(1).principals.sorted + [I18n.t(:label_none)]
  291. assert_equal rows.size + 1, lines.size
  292. # Header
  293. assert_equal '"",New,Assigned,Resolved,Feedback,Closed,Rejected,open,closed,Total', lines.first
  294. # Details
  295. to_test = [
  296. 'Dave Lopper,0,0,0,0,0,0,0,0,0',
  297. 'John Smith,1,0,0,0,0,0,1,0,1',
  298. '[none] ,2,0,0,0,1,0,2,1,3'
  299. ]
  300. to_test.each do |expected|
  301. assert_includes lines, expected
  302. end
  303. end
  304. end
  305. end