您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

pagination_test.rb 2.7KB

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