test/test_html.rb in godfat-pagify-0.5.0 vs test/test_html.rb in godfat-pagify-0.6.1
- old
+ new
@@ -1,20 +1,20 @@
require 'test/helper'
-require 'pagify/helpers/html'
+require 'pagify/helper/html'
-class TestHTML < MiniTest::Unit::TestCase
+class TestHTML < TestCase
# def test_page_and_pager_has_same_html
# pager = Pagify::ArrayPager.new [1]
# assert_equal pager.html.object_id, pager[1].html.object_id
# end
def test_html
pager1 = Pagify::ArrayPager.new []
assert_equal ' ', pager1.html.setting[:separator]
- assert_equal Pagify::Helpers::HTML.object_id, pager1.html.class.object_id
+ assert_equal Pagify::Helper::HTML.object_id, pager1.html.class.object_id
pager1.html.setting[:separator] = 'XD'
assert_equal 'XD', pager1.html.setting[:separator]
assert_equal ' ', pager1.html.class.setting[:separator]
@@ -146,15 +146,41 @@
assert_equal '<a href="1">< Previous</a>', pager.html.links_navigate(2, &:to_s)
end
def test_3_pages
pager = Pagify::ArrayPager.new([1,2,3,4,5], :per_page => 2)
- assert_equal '« First <a href="2">2</a> <a href="3">Last »</a>', pager.html.links(1, &:to_s)
- assert_equal '<a href="1">« First</a> 2 <a href="3">Last »</a>', pager.html.links(2, &:to_s)
- assert_equal '<a href="1">« First</a> <a href="2">2</a> Last »', pager.html.links(3, &:to_s)
+ assert_equal '« First <a href="2">2</a> <a href="3">Last »</a>',
+ pager.html.links(1, &:to_s)
+
+ assert_equal '<a href="1">« First</a> 2 <a href="3">Last »</a>',
+ pager.html.links(2, &:to_s)
+
+ assert_equal '<a href="1">« First</a> <a href="2">2</a> Last »',
+ pager.html.links(3, &:to_s)
+
assert_equal '<a href="2">Next ></a>', pager.html.links_navigate(1, &:to_s)
- assert_equal '<a href="1">< Previous</a> <a href="3">Next ></a>', pager.html.links_navigate(2, &:to_s)
+
+ assert_equal '<a href="1">< Previous</a> <a href="3">Next ></a>',
+ pager.html.links_navigate(2, &:to_s)
+
assert_equal '<a href="2">< Previous</a>', pager.html.links_navigate(3, &:to_s)
+ end
+
+ def test_more_pages_to_left_or_right
+ pager = Pagify::ArrayPager.new((1..33).to_a, :per_page => 3)
+
+ first = ['« First', '<a href="1">« First</a>']
+ last = ['Last »', '<a href="11">Last »</a>']
+
+ (1..11).each{ |page|
+ expected = (2..10).map{ |i| i == page ? i.to_s : "<a href=\"#{i}\">#{i}</a>" }
+
+ expected.unshift( page == 1 ? first.first : first.last )
+ expected.push( page == 11 ? last.first : last.last )
+
+ assert_equal expected.join(' '), pager.html.links(page, &:to_s)
+ }
+
end
end