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">&lt; 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 '&laquo; First <a href="2">2</a> <a href="3">Last &raquo;</a>', pager.html.links(1, &:to_s) - assert_equal '<a href="1">&laquo; First</a> 2 <a href="3">Last &raquo;</a>', pager.html.links(2, &:to_s) - assert_equal '<a href="1">&laquo; First</a> <a href="2">2</a> Last &raquo;', pager.html.links(3, &:to_s) + assert_equal '&laquo; First <a href="2">2</a> <a href="3">Last &raquo;</a>', + pager.html.links(1, &:to_s) + + assert_equal '<a href="1">&laquo; First</a> 2 <a href="3">Last &raquo;</a>', + pager.html.links(2, &:to_s) + + assert_equal '<a href="1">&laquo; First</a> <a href="2">2</a> Last &raquo;', + pager.html.links(3, &:to_s) + assert_equal '<a href="2">Next &gt;</a>', pager.html.links_navigate(1, &:to_s) - assert_equal '<a href="1">&lt; Previous</a> <a href="3">Next &gt;</a>', pager.html.links_navigate(2, &:to_s) + + assert_equal '<a href="1">&lt; Previous</a> <a href="3">Next &gt;</a>', + pager.html.links_navigate(2, &:to_s) + assert_equal '<a href="2">&lt; 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 = ['&laquo; First', '<a href="1">&laquo; First</a>'] + last = ['Last &raquo;', '<a href="11">Last &raquo;</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