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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../test_helper', __FILE__)
  18. class ActivitiesHelperTest < ActionView::TestCase
  19. include ActivitiesHelper
  20. include Redmine::I18n
  21. class MockEvent
  22. attr_reader :event_datetime, :event_group, :name
  23. def initialize(group=nil)
  24. @@count ||= 0
  25. @name = "e#{@@count}"
  26. @event_datetime = Time.now + @@count.hours
  27. @event_group = group || self
  28. @@count += 1
  29. end
  30. def self.clear
  31. @@count = 0
  32. end
  33. end
  34. def setup
  35. MockEvent.clear
  36. end
  37. def test_sort_activity_events_should_sort_by_datetime
  38. events = []
  39. events << MockEvent.new
  40. events << MockEvent.new
  41. events << MockEvent.new
  42. assert_equal [
  43. ['e2', false],
  44. ['e1', false],
  45. ['e0', false]
  46. ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  47. end
  48. def test_sort_activity_events_should_group_events
  49. events = []
  50. events << MockEvent.new
  51. events << MockEvent.new(events[0])
  52. events << MockEvent.new(events[0])
  53. assert_equal [
  54. ['e2', false],
  55. ['e1', true],
  56. ['e0', true]
  57. ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  58. end
  59. def test_sort_activity_events_with_group_not_in_set_should_group_events
  60. e = MockEvent.new
  61. events = []
  62. events << MockEvent.new(e)
  63. events << MockEvent.new(e)
  64. assert_equal [
  65. ['e2', false],
  66. ['e1', true]
  67. ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  68. end
  69. def test_sort_activity_events_should_sort_by_datetime_and_group
  70. events = []
  71. events << MockEvent.new
  72. events << MockEvent.new
  73. events << MockEvent.new
  74. events << MockEvent.new(events[1])
  75. events << MockEvent.new(events[2])
  76. events << MockEvent.new
  77. events << MockEvent.new(events[2])
  78. assert_equal [
  79. ['e6', false],
  80. ['e4', true],
  81. ['e2', true],
  82. ['e5', false],
  83. ['e3', false],
  84. ['e1', true],
  85. ['e0', false]
  86. ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
  87. end
  88. end