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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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', :description => 'Description for 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 => query.name
  150. assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
  151. end
  152. def test_cross_project_calendar
  153. travel_to issues(:issues_002).start_date
  154. get :show
  155. assert_response :success
  156. assert_select 'ul.cal' do
  157. assert_select 'li' do
  158. assert_select(
  159. 'div.issue.hascontextmenu.tooltip.starting',
  160. :text => /eCookbook.*Add ingredients categories/m
  161. ) do
  162. assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
  163. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
  164. end
  165. end
  166. end
  167. end
  168. def test_cross_project_calendar_version
  169. travel_to versions(:versions_002).effective_date
  170. get :show
  171. assert_response :success
  172. assert_select 'ul.cal' do
  173. assert_select 'li' do
  174. assert_select(
  175. 'span.icon.icon-package'
  176. ) do
  177. assert_select(
  178. 'a[href=?]', '/versions/2',
  179. :text => 'eCookbook - 1.0'
  180. )
  181. end
  182. end
  183. end
  184. end
  185. def test_week_number_calculation
  186. with_settings :start_of_week => 7 do
  187. get(
  188. :show,
  189. :params => {
  190. :month => '1',
  191. :year => '2010'
  192. }
  193. )
  194. assert_response :success
  195. end
  196. assert_select 'ul' do
  197. assert_select 'li.week-number:nth-of-type(2)', :text => /53$/
  198. assert_select 'li.odd', :text => /^27/
  199. assert_select 'li.even', :text => /^2/
  200. end
  201. assert_select 'ul' do
  202. assert_select 'li.week-number', :text => /1$/
  203. assert_select 'li.odd', :text => /^3/
  204. assert_select 'li.even', :text => /^9/
  205. end
  206. with_settings :start_of_week => 1 do
  207. get(
  208. :show,
  209. :params => {
  210. :month => '1',
  211. :year => '2010'
  212. }
  213. )
  214. assert_response :success
  215. end
  216. assert_select 'ul' do
  217. assert_select 'li.week-number:nth-of-type(2)', :text => /53$/
  218. assert_select 'li.even', :text => /^28/
  219. assert_select 'li.even', :text => /^3/
  220. end
  221. assert_select 'ul' do
  222. assert_select 'li.week-number', :text => /1$/
  223. assert_select 'li.even', :text => /^4/
  224. assert_select 'li.even', :text => /^10/
  225. end
  226. end
  227. def test_show_custom_query_with_multiple_sort_criteria
  228. get(
  229. :show,
  230. :params => {
  231. :query_id => 5
  232. }
  233. )
  234. assert_response :success
  235. assert_select 'h2', :text => 'Open issues by priority and tracker'
  236. end
  237. def test_show_custom_query_with_group_by_option
  238. get(
  239. :show,
  240. :params => {
  241. :query_id => 6
  242. }
  243. )
  244. assert_response :success
  245. assert_select 'h2', :text => 'Open issues grouped by tracker'
  246. end
  247. def test_show_calendar_day_css_classes
  248. get(
  249. :show,
  250. :params => {
  251. :month => '12',
  252. :year => '2016'
  253. }
  254. )
  255. assert_response :success
  256. assert_select 'ul' do
  257. assert_select 'li.week-number:nth-of-type(2)', :text => /48$/
  258. # non working days should have "nwday" CSS class
  259. assert_select 'li.nwday', 10
  260. assert_select 'li.nwday', :text => /^4/
  261. assert_select 'li.nwday', :text => /^10/
  262. end
  263. end
  264. end