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.

pagination_test.rb 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 Redmine::PaginationTest < ActiveSupport::TestCase
  19. def setup
  20. @klass = Redmine::Pagination::Paginator
  21. end
  22. def test_count_is_zero
  23. p = @klass.new 0, 10, 1
  24. assert_equal 0, p.offset
  25. assert_equal 10, p.per_page
  26. %w(first_page previous_page next_page last_page).each do |method|
  27. assert_nil p.send(method), "#{method} was not nil"
  28. end
  29. assert_equal 0, p.first_item
  30. assert_equal 0, p.last_item
  31. assert_equal [], p.linked_pages
  32. end
  33. def test_count_is_less_than_per_page
  34. p = @klass.new 7, 10, 1
  35. assert_equal 0, p.offset
  36. assert_equal 10, p.per_page
  37. assert_equal 1, p.first_page
  38. assert_nil p.previous_page
  39. assert_nil p.next_page
  40. assert_equal 1, p.last_page
  41. assert_equal 1, p.first_item
  42. assert_equal 7, p.last_item
  43. assert_equal [], p.linked_pages
  44. end
  45. def test_count_is_equal_to_per_page
  46. p = @klass.new 10, 10, 1
  47. assert_equal 0, p.offset
  48. assert_equal 10, p.per_page
  49. assert_equal 1, p.first_page
  50. assert_nil p.previous_page
  51. assert_nil p.next_page
  52. assert_equal 1, p.last_page
  53. assert_equal 1, p.first_item
  54. assert_equal 10, p.last_item
  55. assert_equal [], p.linked_pages
  56. end
  57. def test_2_pages
  58. p = @klass.new 16, 10, 1
  59. assert_equal 0, p.offset
  60. assert_equal 10, p.per_page
  61. assert_equal 1, p.first_page
  62. assert_nil p.previous_page
  63. assert_equal 2, p.next_page
  64. assert_equal 2, p.last_page
  65. assert_equal 1, p.first_item
  66. assert_equal 10, p.last_item
  67. assert_equal [1, 2], p.linked_pages
  68. end
  69. def test_many_pages
  70. p = @klass.new 155, 10, 1
  71. assert_equal 0, p.offset
  72. assert_equal 10, p.per_page
  73. assert_equal 1, p.first_page
  74. assert_nil p.previous_page
  75. assert_equal 2, p.next_page
  76. assert_equal 16, p.last_page
  77. assert_equal 1, p.first_item
  78. assert_equal 10, p.last_item
  79. assert_equal [1, 2, 3, 16], p.linked_pages
  80. end
  81. end