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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 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 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 'p.contextual'
  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 'table.cal' do
  61. assert_select 'tr' do
  62. assert_select 'td' do
  63. assert_select(
  64. 'div.issue.hascontextmenu.tooltip.starting',
  65. :text => /Add ingredients categories/
  66. ) do
  67. assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
  68. assert_select 'span.tip' do
  69. assert_select 'img[class="gravatar"]'
  70. end
  71. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
  72. end
  73. end
  74. end
  75. end
  76. end
  77. def test_show_issue_due_date
  78. travel_to issues(:issues_001).due_date
  79. get(:show, :params => {:project_id => 1})
  80. assert_response :success
  81. assert_select 'table.cal' do
  82. assert_select 'tr' do
  83. assert_select 'td' do
  84. assert_select(
  85. 'div.issue.hascontextmenu.tooltip.ending',
  86. :text => /Cannot print recipes/
  87. ) do
  88. assert_select 'a.issue[href=?]', '/issues/1', :text => 'Bug #1'
  89. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '1'
  90. end
  91. end
  92. end
  93. end
  94. end
  95. test "show issue of start and due dates are same" do
  96. subject = 'start and due dates are same'
  97. issue = Issue.generate!(:start_date => '2012-10-06',
  98. :due_date => '2012-10-06',
  99. :project_id => 1, :tracker_id => 1,
  100. :subject => subject)
  101. get(
  102. :show,
  103. :params => {
  104. :project_id => 1,
  105. :month => '10',
  106. :year => '2012'
  107. }
  108. )
  109. assert_response :success
  110. assert_select 'table.cal' do
  111. assert_select 'tr' do
  112. assert_select 'td' do
  113. assert_select(
  114. 'div.issue.hascontextmenu.tooltip.starting.ending',
  115. :text => /#{subject}/
  116. ) do
  117. assert_select(
  118. 'a.issue[href=?]', "/issues/#{issue.id}",
  119. :text => "Bug ##{issue.id}"
  120. )
  121. assert_select(
  122. 'input[name=?][type=?][value=?]',
  123. 'ids[]',
  124. 'checkbox',
  125. issue.id.to_s
  126. )
  127. end
  128. end
  129. end
  130. end
  131. end
  132. def test_show_version
  133. travel_to versions(:versions_002).effective_date
  134. get(:show, :params => {:project_id => 1})
  135. assert_response :success
  136. assert_select 'table.cal' do
  137. assert_select 'tr' do
  138. assert_select 'td' do
  139. assert_select(
  140. 'span.icon.icon-package'
  141. ) do
  142. assert_select 'a[href=?]', '/versions/2', :text => '1.0'
  143. end
  144. end
  145. end
  146. end
  147. end
  148. def test_show_should_run_custom_queries
  149. @query = IssueQuery.create!(:name => 'Calendar Query', :visibility => IssueQuery::VISIBILITY_PUBLIC)
  150. get(
  151. :show,
  152. :params => {
  153. :query_id => @query.id
  154. }
  155. )
  156. assert_response :success
  157. assert_select 'h2', :text => 'Calendar Query'
  158. end
  159. def test_cross_project_calendar
  160. travel_to issues(:issues_002).start_date
  161. get :show
  162. assert_response :success
  163. assert_select 'table.cal' do
  164. assert_select 'tr' do
  165. assert_select 'td' do
  166. assert_select(
  167. 'div.issue.hascontextmenu.tooltip.starting',
  168. :text => /eCookbook.*Add ingredients categories/m
  169. ) do
  170. assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
  171. assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
  172. end
  173. end
  174. end
  175. end
  176. end
  177. def test_cross_project_calendar_version
  178. travel_to versions(:versions_002).effective_date
  179. get :show
  180. assert_response :success
  181. assert_select 'table.cal' do
  182. assert_select 'tr' do
  183. assert_select 'td' do
  184. assert_select(
  185. 'span.icon.icon-package'
  186. ) do
  187. assert_select(
  188. 'a[href=?]', '/versions/2',
  189. :text => 'eCookbook - 1.0'
  190. )
  191. end
  192. end
  193. end
  194. end
  195. end
  196. def test_week_number_calculation
  197. with_settings :start_of_week => 7 do
  198. get(
  199. :show,
  200. :params => {
  201. :month => '1',
  202. :year => '2010'
  203. }
  204. )
  205. assert_response :success
  206. end
  207. assert_select 'tr' do
  208. assert_select 'td.week-number', :text => '53'
  209. assert_select 'td.odd', :text => '27'
  210. assert_select 'td.even', :text => '2'
  211. end
  212. assert_select 'tr' do
  213. assert_select 'td.week-number', :text => '1'
  214. assert_select 'td.odd', :text => '3'
  215. assert_select 'td.even', :text => '9'
  216. end
  217. with_settings :start_of_week => 1 do
  218. get(
  219. :show,
  220. :params => {
  221. :month => '1',
  222. :year => '2010'
  223. }
  224. )
  225. assert_response :success
  226. end
  227. assert_select 'tr' do
  228. assert_select 'td.week-number', :text => '53'
  229. assert_select 'td.even', :text => '28'
  230. assert_select 'td.even', :text => '3'
  231. end
  232. assert_select 'tr' do
  233. assert_select 'td.week-number', :text => '1'
  234. assert_select 'td.even', :text => '4'
  235. assert_select 'td.even', :text => '10'
  236. end
  237. end
  238. def test_show_custom_query_with_multiple_sort_criteria
  239. get(
  240. :show,
  241. :params => {
  242. :query_id => 5
  243. }
  244. )
  245. assert_response :success
  246. assert_select 'h2', :text => 'Open issues by priority and tracker'
  247. end
  248. def test_show_custom_query_with_group_by_option
  249. get(
  250. :show,
  251. :params => {
  252. :query_id => 6
  253. }
  254. )
  255. assert_response :success
  256. assert_select 'h2', :text => 'Open issues grouped by tracker'
  257. end
  258. def test_show_calendar_day_css_classes
  259. get(
  260. :show,
  261. :params => {
  262. :month => '12',
  263. :year => '2016'
  264. }
  265. )
  266. assert_response :success
  267. assert_select 'tr:nth-child(2)' do
  268. assert_select 'td.week-number', :text => '49'
  269. # non working days should have "nwday" CSS class
  270. assert_select 'td.nwday', 2
  271. assert_select 'td.nwday', :text => '4'
  272. assert_select 'td.nwday', :text => '10'
  273. end
  274. end
  275. end