if respond_to?(:require_relative, true) require_relative 'helper' else require 'test/helper' end require 'pagify/helper/html' 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::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] pager2 = Pagify::ArrayPager.new [] assert_equal ' ', pager2.html.setting[:separator] pager2.html.setting[:inner_links] = 6 assert_equal 6, pager2.html.setting[:inner_links] assert_equal 4, pager1.html.setting[:inner_links] assert_equal 4, pager2.html.class.setting[:inner_links] pager2.html.class.setting[:outer_links] = 3 assert_equal 3, pager1.html.setting[:outer_links] assert_equal 3, pager2.html.setting[:outer_links] pager1.html.setting[:outer_links] = 4 assert_equal 4, pager1.html.setting[:outer_links] assert_equal 3, pager2.html.setting[:outer_links] pager1.html.setting.restore_default! assert_equal ' ', pager1.html.setting[:separator] assert_equal 4, pager1.html.setting[:inner_links] assert_equal 6, pager2.html.setting[:inner_links] assert_equal 3, pager1.html.setting[:outer_links] assert_equal 3, pager2.html.setting[:outer_links] pager2.html.class.setting.restore_default! assert_equal 6, pager2.html.setting[:inner_links] assert_equal 2, pager1.html.setting[:outer_links] assert_equal 2, pager2.html.setting[:outer_links] end def test_generate_html # skip 'not implemented' pager = Pagify::ArrayPager.new((1..1000).to_a, :per_page => 10) users = pager[50] pager.html.setting[:class] = nil assert_equal(#'< Previous 50 Next >
'+ '« First ' + '2 ' + # outer links # '... ' + # '31 ' + # step links, offset = step * step # '... ' + # '40 ' + # step links, amount = inner / 2 # '43 ' + '... ' + '46 ' + # inner links '47 ' + '48 ' + '49 ' + '50 ' + '51 ' + '52 ' + '53 ' + '54 ' + # inner links '... ' + # '57 ' + # '60 ' + # step links, amount = inner / 2 # '... ' + # '69 ' + # step links, offset = step * step # '... ' + '99 ' + # outer links 'Last »', users.pager.html.links(50, &:to_s) ) end def test_with_class pager = Pagify::ArrayPager.new((1..1000).to_a, :per_page => 10) pager.html.setting[:class] = 'pagify' pager.html.setting[:separator] = ',,' pager.html.setting[:ellipsis] = 'zzz' users = pager[50] assert_equal(#'< Previous 50 Next >
'+ '« First,,' + '2,,' + # outer links 'zzz,,' + '46,,' + # inner links '47,,' + '48,,' + '49,,' + '50,,' + '51,,' + '52,,' + '53,,' + '54,,' + # inner links 'zzz,,' + '99,,' + # outer links 'Last »', users.pager.html.links(50, &:to_s) ) end def test_no_page pager = Pagify::ArrayPager.new([1], :per_page => 10) nothing_there pager pager.html.setting[:outer_links] = 10 nothing_there pager pager.html.setting[:inner_links] = 1 nothing_there pager pager.html.setting[:inner_links] = 5 nothing_there pager end def nothing_there pager assert_equal('', pager.html.links(1, &:to_s)) end def test_nothing pager = Pagify::ArrayPager.new([1,2,3]) assert_equal '', pager.html.links_navigate(1, &:to_s) end def test_null_pager pager = Pagify::NullPager.instance assert_equal '', pager.html.links(1) assert_equal '', pager.html.links(nil) assert_equal '', pager.html.links('') assert_equal '', pager.html.links(2) assert_equal '', pager.html.links(-1) end def test_2_pages pager = Pagify::ArrayPager.new([1,2,3], :per_page => 2) pager.html.setting[:inactive_class] = nil pager.html.setting[:active_class] = nil assert_equal '« First Last »', pager.html.links(1, &:to_s) assert_equal '« First Last »', pager.html.links(2, &:to_s) assert_equal 'Next >', pager.html.links_navigate(1, &:to_s) assert_equal '< Previous', pager.html.links_navigate(2, &:to_s) end def test_3_pages pager = Pagify::ArrayPager.new([1,2,3,4,5], :per_page => 2) pager.html.setting[:class] = nil pager.html.setting[:active_class] = 'a' assert_equal '« First 2 Last »', pager.html.links(1, &:to_s) assert_equal '« First 2 Last »', pager.html.links(2, &:to_s) assert_equal '« First 2 Last »', pager.html.links(3, &:to_s) assert_equal 'Next >', pager.html.links_navigate(1, &:to_s) assert_equal '< Previous Next >', pager.html.links_navigate(2, &:to_s) assert_equal '< Previous', 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) pager.html.setting[:first_text] = nil pager.html.setting[:last_text] = nil pager.html.setting[:class] = nil pager.html.setting[:active_class] = 'g' first = ['1', '1'] last = ['11', '11'] (1..11).each{ |page| expected = (2..10).map{ |i| if i == page %Q{#{i}} else %Q{#{i}} end } 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