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.2KB

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