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.

activities_helper_test.rb 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 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 ActivitiesHelperTest < Redmine::HelperTest
  20. include ActivitiesHelper
  21. fixtures :projects, :members, :users
  22. class MockEvent
  23. attr_reader :event_datetime, :event_group, :name
  24. def initialize(group=nil)
  25. @@count ||= 0
  26. @name = "e#{@@count}"
  27. @event_datetime = Time.now + @@count.hours
  28. @event_group = group || self
  29. @@count += 1
  30. end
  31. def self.clear
  32. @@count = 0
  33. end
  34. end
  35. def setup
  36. super
  37. MockEvent.clear
  38. end
  39. def test_sort_activity_events_should_sort_by_datetime
  40. events = []
  41. events << MockEvent.new
  42. events << MockEvent.new
  43. events << MockEvent.new
  44. assert_equal(
  45. [
  46. ['e2', false],
  47. ['e1', false],
  48. ['e0', false]
  49. ],
  50. sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  51. )
  52. end
  53. def test_sort_activity_events_should_group_events
  54. events = []
  55. events << MockEvent.new
  56. events << MockEvent.new(events[0])
  57. events << MockEvent.new(events[0])
  58. assert_equal(
  59. [
  60. ['e2', false],
  61. ['e1', true],
  62. ['e0', true]
  63. ],
  64. sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  65. )
  66. end
  67. def test_sort_activity_events_with_group_not_in_set_should_group_events
  68. e = MockEvent.new
  69. events = []
  70. events << MockEvent.new(e)
  71. events << MockEvent.new(e)
  72. assert_equal(
  73. [
  74. ['e2', false],
  75. ['e1', true]
  76. ],
  77. sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  78. )
  79. end
  80. def test_sort_activity_events_should_sort_by_datetime_and_group
  81. events = []
  82. events << MockEvent.new
  83. events << MockEvent.new
  84. events << MockEvent.new
  85. events << MockEvent.new(events[1])
  86. events << MockEvent.new(events[2])
  87. events << MockEvent.new
  88. events << MockEvent.new(events[2])
  89. assert_equal(
  90. [
  91. ['e6', false],
  92. ['e4', true],
  93. ['e2', true],
  94. ['e5', false],
  95. ['e3', false],
  96. ['e1', true],
  97. ['e0', false]
  98. ],
  99. sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  100. )
  101. end
  102. def test_activity_authors_options_for_select_if_current_user_is_admin
  103. User.current = User.find(1)
  104. project = Project.find(1)
  105. options = [["<< #{l(:label_me)} >>", 1], ['Dave Lopper', 3], ['John Smith', 2], ['Redmine Admin', 1], ['User Misc', 8]]
  106. assert_equal(
  107. options_for_select(options, nil),
  108. activity_authors_options_for_select(project, nil))
  109. end
  110. def test_activity_authors_options_for_select_if_current_user_is_anonymous
  111. User.current = nil
  112. project = Project.find(1)
  113. options = [['Dave Lopper', 3], ['John Smith', 2]]
  114. assert_equal(
  115. options_for_select(options, nil),
  116. activity_authors_options_for_select(project, nil))
  117. end
  118. end