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.

gantts_controller_test.rb 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 GanttsControllerTest < 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. :email_addresses
  29. def test_gantt_should_work
  30. i2 = Issue.find(2)
  31. i2.update_attribute(:due_date, 1.month.from_now)
  32. with_settings :gravatar_enabled => '1' do
  33. get(
  34. :show,
  35. :params => {
  36. :project_id => 1
  37. }
  38. )
  39. end
  40. assert_response :success
  41. # query form
  42. assert_select 'form#query_form' do
  43. assert_select 'div#query_form_with_buttons.hide-when-print' do
  44. assert_select 'div#query_form_content' do
  45. assert_select 'fieldset#filters.collapsible'
  46. assert_select 'fieldset#options'
  47. end
  48. assert_select 'p.contextual' do
  49. prev_month, next_month = User.current.today.prev_month, User.current.today.next_month
  50. assert_select(
  51. 'a[accesskey="p"][href=?]',
  52. project_gantt_path(:project_id => 1, :month => prev_month.month, :year => prev_month.year)
  53. )
  54. assert_select(
  55. 'a[accesskey="n"][href=?]',
  56. project_gantt_path(:project_id => 1, :month => next_month.month, :year => next_month.year)
  57. )
  58. end
  59. assert_select 'p.buttons'
  60. end
  61. end
  62. # Assert context menu on issues subject and gantt bar
  63. assert_select 'div[class=?]', 'issue-subject hascontextmenu'
  64. assert_select 'div.tooltip.hascontextmenu' do
  65. assert_select 'img[class="gravatar"]'
  66. end
  67. assert_select "form[data-cm-url=?]", '/issues/context_menu'
  68. # Issue with start and due dates
  69. i = Issue.find(1)
  70. assert_not_nil i.due_date
  71. assert_select "div a.issue", /##{i.id}/
  72. # Issue with on a targeted version should not be in the events but loaded in the html
  73. i = Issue.find(2)
  74. assert_select "div a.issue", /##{i.id}/
  75. end
  76. def test_gantt_at_minimal_zoom
  77. get(
  78. :show,
  79. :params => {
  80. :project_id => 1,
  81. :zoom => 1
  82. }
  83. )
  84. assert_response :success
  85. assert_select 'input[type=hidden][name=zoom][value=?]', '1'
  86. end
  87. def test_gantt_at_maximal_zoom
  88. get(
  89. :show,
  90. :params => {
  91. :project_id => 1,
  92. :zoom => 4
  93. }
  94. )
  95. assert_response :success
  96. assert_select 'input[type=hidden][name=zoom][value=?]', '4'
  97. end
  98. def test_gantt_should_work_without_issue_due_dates
  99. Issue.update_all("due_date = NULL")
  100. get(:show, :params => {:project_id => 1})
  101. assert_response :success
  102. end
  103. def test_gantt_should_work_without_issue_and_version_due_dates
  104. Issue.update_all("due_date = NULL")
  105. Version.update_all("effective_date = NULL")
  106. get(:show, :params => {:project_id => 1})
  107. assert_response :success
  108. end
  109. def test_gantt_should_work_cross_project
  110. get :show
  111. assert_response :success
  112. end
  113. def test_gantt_should_not_disclose_private_projects
  114. get :show
  115. assert_response :success
  116. assert_select 'a', :text => /eCookbook/
  117. # Root private project
  118. assert_select 'a', :text => /OnlineStore/, :count => 0
  119. # Private children of a public project
  120. assert_select 'a', :text => /Private child of eCookbook/, :count => 0
  121. end
  122. def test_gantt_should_display_relations
  123. IssueRelation.delete_all
  124. issue1 = Issue.generate!(:start_date => 1.day.from_now.to_date, :due_date => 3.day.from_now.to_date)
  125. issue2 = Issue.generate!(:start_date => 1.day.from_now.to_date, :due_date => 3.day.from_now.to_date)
  126. IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => 'precedes')
  127. get :show
  128. assert_response :success
  129. assert_select 'div.task_todo[id=?][data-rels*=?]', "task-todo-issue-#{issue1.id}", issue2.id.to_s
  130. assert_select 'div.task_todo[id=?]:not([data-rels])', "task-todo-issue-#{issue2.id}"
  131. end
  132. def test_gantt_should_export_to_pdf
  133. get(
  134. :show,
  135. :params => {
  136. :project_id => 1,
  137. :months => 1,
  138. :format => 'pdf'
  139. }
  140. )
  141. assert_response :success
  142. assert_equal 'application/pdf', @response.media_type
  143. assert @response.body.starts_with?('%PDF')
  144. end
  145. def test_gantt_should_export_to_pdf_cross_project
  146. get(:show, :params => {:format => 'pdf'})
  147. assert_response :success
  148. assert_equal 'application/pdf', @response.media_type
  149. assert @response.body.starts_with?('%PDF')
  150. end
  151. if Object.const_defined?(:MiniMagick) && convert_installed?
  152. def test_gantt_should_export_to_png
  153. get(
  154. :show,
  155. :params => {
  156. :project_id => 1,
  157. :zoom => 4,
  158. :format => 'png'
  159. }
  160. )
  161. assert_response :success
  162. assert_equal 'image/png', @response.media_type
  163. end
  164. end
  165. def test_gantt_should_respect_gantt_months_limit_setting
  166. with_settings :gantt_months_limit => '40' do
  167. # `months` parameter can be less than or equal to
  168. # `Setting.gantt_months_limit`
  169. get(
  170. :show,
  171. :params => {
  172. :project_id => 1,
  173. :zoom => 4,
  174. :months => 40
  175. }
  176. )
  177. assert_response :success
  178. assert_select 'div.gantt_hdr>a', :text => /^[\d-]+$/, :count => 40
  179. # Displays 6 months (the default value for `months`) if `months` exceeds
  180. # gant_months_limit
  181. get(
  182. :show,
  183. :params => {
  184. :project_id => 1,
  185. :zoom => 4,
  186. :months => 41
  187. }
  188. )
  189. assert_response :success
  190. assert_select 'div.gantt_hdr>a', :text => /^[\d-]+$/, :count => 6
  191. end
  192. end
  193. end