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.

calendars_controller_test.rb 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 '../test_helper'
  19. class CalendarsControllerTest < Redmine::ControllerTest
  20. fixtures :projects,
  21. :trackers,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :issues,
  28. :issue_statuses,
  29. :issue_relations,
  30. :issue_categories,
  31. :enumerations,
  32. :queries,
  33. :users, :email_addresses,
  34. :versions
  35. def test_show
  36. # Ensure that an issue to which a user is assigned is in the current
  37. # month's calendar in order to test Gravatar
  38. travel_to issues(:issues_002).start_date
  39. with_settings :gravatar_enabled => '1' do
  40. get(
  41. :show,
  42. :params => {
  43. :project_id => 1
  44. }
  45. )
  46. end
  47. assert_response :success
  48. # query form
  49. assert_select 'form#query_form' do
  50. assert_select 'div#query_form_with_buttons.hide-when-print' do
  51. assert_select 'div#query_form_content' do
  52. assert_select 'fieldset#filters.collapsible'
  53. end
  54. assert_select 'span.contextual.pagination'
  55. assert_select 'p.buttons'
  56. end
  57. end
  58. # Assert context menu on issues
  59. assert_select 'form[data-cm-url=?]', '/issues/context_menu'
  60. assert_select 'ul.cal' do
  61. assert_select 'li' do
  62. assert_select(
  63. 'div.issue.hascontextmenu.tooltip.starting',
  64. :text => /Add ingredients categories/
  65. ) do
  66. assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
  67. assert_select 'span.tip' do
  68. assert_select 'img[class="gravatar"]'
  69. end
  70. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
  71. end
  72. end
  73. end
  74. end
  75. def test_show_issue_due_date
  76. travel_to issues(:issues_001).due_date
  77. get(:show, :params => {:project_id => 1})
  78. assert_response :success
  79. assert_select 'ul.cal' do
  80. assert_select 'li' do
  81. assert_select(
  82. 'div.issue.hascontextmenu.tooltip.ending',
  83. :text => /Cannot print recipes/
  84. ) do
  85. assert_select 'a.issue[href=?]', '/issues/1', :text => 'Bug #1'
  86. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '1'
  87. end
  88. end
  89. end
  90. end
  91. test "show issue of start and due dates are same" do
  92. subject = 'start and due dates are same'
  93. issue = Issue.generate!(:start_date => '2012-10-06',
  94. :due_date => '2012-10-06',
  95. :project_id => 1, :tracker_id => 1,
  96. :subject => subject)
  97. get(
  98. :show,
  99. :params => {
  100. :project_id => 1,
  101. :month => '10',
  102. :year => '2012'
  103. }
  104. )
  105. assert_response :success
  106. assert_select 'ul.cal' do
  107. assert_select 'li' do
  108. assert_select(
  109. 'div.issue.hascontextmenu.tooltip.starting.ending',
  110. :text => /#{subject}/
  111. ) do
  112. assert_select(
  113. 'a.issue[href=?]', "/issues/#{issue.id}",
  114. :text => "Bug ##{issue.id}"
  115. )
  116. assert_select(
  117. 'input[name=?][type=?][value=?]',
  118. 'ids[]',
  119. 'checkbox',
  120. issue.id.to_s
  121. )
  122. end
  123. end
  124. end
  125. end
  126. def test_show_version
  127. travel_to versions(:versions_002).effective_date
  128. get(:show, :params => {:project_id => 1})
  129. assert_response :success
  130. assert_select 'ul.cal' do
  131. assert_select 'li' do
  132. assert_select(
  133. 'span.icon.icon-package'
  134. ) do
  135. assert_select 'a[href=?]', '/versions/2', :text => '1.0'
  136. end
  137. end
  138. end
  139. end
  140. def test_show_should_run_custom_queries
  141. @query = IssueQuery.create!(:name => 'Calendar Query', :visibility => IssueQuery::VISIBILITY_PUBLIC)
  142. get(
  143. :show,
  144. :params => {
  145. :query_id => @query.id
  146. }
  147. )
  148. assert_response :success
  149. assert_select 'h2', :text => 'Calendar Query'
  150. end
  151. def test_cross_project_calendar
  152. travel_to issues(:issues_002).start_date
  153. get :show
  154. assert_response :success
  155. assert_select 'ul.cal' do
  156. assert_select 'li' do
  157. assert_select(
  158. 'div.issue.hascontextmenu.tooltip.starting',
  159. :text => /eCookbook.*Add ingredients categories/m
  160. ) do
  161. assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
  162. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
  163. end
  164. end
  165. end
  166. end
  167. def test_cross_project_calendar_version
  168. travel_to versions(:versions_002).effective_date
  169. get :show
  170. assert_response :success
  171. assert_select 'ul.cal' do
  172. assert_select 'li' do
  173. assert_select(
  174. 'span.icon.icon-package'
  175. ) do
  176. assert_select(
  177. 'a[href=?]', '/versions/2',
  178. :text => 'eCookbook - 1.0'
  179. )
  180. end
  181. end
  182. end
  183. end
  184. def test_week_number_calculation
  185. with_settings :start_of_week => 7 do
  186. get(
  187. :show,
  188. :params => {
  189. :month => '1',
  190. :year => '2010'
  191. }
  192. )
  193. assert_response :success
  194. end
  195. assert_select 'ul' do
  196. assert_select 'li.week-number:nth-of-type(2)', :text => /53$/
  197. assert_select 'li.odd', :text => /^27/
  198. assert_select 'li.even', :text => /^2/
  199. end
  200. assert_select 'ul' do
  201. assert_select 'li.week-number', :text => /1$/
  202. assert_select 'li.odd', :text => /^3/
  203. assert_select 'li.even', :text => /^9/
  204. end
  205. with_settings :start_of_week => 1 do
  206. get(
  207. :show,
  208. :params => {
  209. :month => '1',
  210. :year => '2010'
  211. }
  212. )
  213. assert_response :success
  214. end
  215. assert_select 'ul' do
  216. assert_select 'li.week-number:nth-of-type(2)', :text => /53$/
  217. assert_select 'li.even', :text => /^28/
  218. assert_select 'li.even', :text => /^3/
  219. end
  220. assert_select 'ul' do
  221. assert_select 'li.week-number', :text => /1$/
  222. assert_select 'li.even', :text => /^4/
  223. assert_select 'li.even', :text => /^10/
  224. end
  225. end
  226. def test_show_custom_query_with_multiple_sort_criteria
  227. get(
  228. :show,
  229. :params => {
  230. :query_id => 5
  231. }
  232. )
  233. assert_response :success
  234. assert_select 'h2', :text => 'Open issues by priority and tracker'
  235. end
  236. def test_show_custom_query_with_group_by_option
  237. get(
  238. :show,
  239. :params => {
  240. :query_id => 6
  241. }
  242. )
  243. assert_response :success
  244. assert_select 'h2', :text => 'Open issues grouped by tracker'
  245. end
  246. def test_show_calendar_day_css_classes
  247. get(
  248. :show,
  249. :params => {
  250. :month => '12',
  251. :year => '2016'
  252. }
  253. )
  254. assert_response :success
  255. assert_select 'ul' do
  256. assert_select 'li.week-number:nth-of-type(2)', :text => /48$/
  257. # non working days should have "nwday" CSS class
  258. assert_select 'li.nwday', 10
  259. assert_select 'li.nwday', :text => /^4/
  260. assert_select 'li.nwday', :text => /^10/
  261. end
  262. end
  263. end