Skip to content

Commit

Permalink
indentation fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 1, 2018
1 parent a927d57 commit 1263540
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 77 deletions.
52 changes: 26 additions & 26 deletions test/pagy/frontend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def request
Rack::Request.new('SCRIPT_NAME' => '/foo')
end
end

let(:frontend) { TestView.new }

describe "#pagy_nav" do
before do
@array = (1..103).to_a.extend(Pagy::Array::PageMethod)
end

def test_pagy_nav_page_1
pagy, _ = @array.pagy(1)

assert_equal(
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<span class="page prev disabled">&lsaquo;&nbsp;Prev</span> ' \
'<span class="page active">1</span> ' \
'<span class="page"><a href="/foo?page=2" rel="next">2</a></span> ' \
Expand All @@ -32,15 +32,15 @@ def test_pagy_nav_page_1
'<span class="page"><a href="/foo?page=6">6</a></span> ' \
'<span class="page next"><a href="/foo?page=2" rel="next" aria-label="next">Next&nbsp;&rsaquo;</a></span>' \
'</nav>',
frontend.pagy_nav(pagy)
frontend.pagy_nav(pagy)
)
end

def test_pagy_nav_page_3
pagy, _ = @array.pagy(3)

assert_equal(
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<span class="page prev"><a href="/foo?page=2" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></span> ' \
'<span class="page"><a href="/foo?page=1">1</a></span> ' \
'<span class="page"><a href="/foo?page=2" rel="prev">2</a></span> ' \
Expand All @@ -50,15 +50,15 @@ def test_pagy_nav_page_3
'<span class="page"><a href="/foo?page=6">6</a></span> ' \
'<span class="page next"><a href="/foo?page=4" rel="next" aria-label="next">Next&nbsp;&rsaquo;</a></span>' \
'</nav>',
frontend.pagy_nav(pagy)
frontend.pagy_nav(pagy)
)
end

def test_pagy_nav_page_6
pagy, _ = @array.pagy(6)

assert_equal(
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<span class="page prev"><a href="/foo?page=5" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></span> ' \
'<span class="page"><a href="/foo?page=1">1</a></span> ' \
'<span class="page"><a href="/foo?page=2">2</a></span> ' \
Expand All @@ -68,7 +68,7 @@ def test_pagy_nav_page_6
'<span class="page active">6</span> ' \
'<span class="page next disabled">Next&nbsp;&rsaquo;</span>' \
'</nav>',
frontend.pagy_nav(pagy)
frontend.pagy_nav(pagy)
)
end
end
Expand All @@ -78,28 +78,28 @@ def test_data
assert_equal "&lsaquo;&nbsp;Prev", Pagy::Frontend::I18N_DATA['pagy']['nav']['prev']
assert_equal "&hellip;", Pagy::Frontend::I18N_DATA['pagy']['nav']['gap']
end

def test_translation
assert_equal "&lsaquo;&nbsp;Prev", frontend.pagy_t('pagy.nav.prev')

assert_equal "items", frontend.pagy_t('pagy.info.item_name', count: 0)
assert_equal "item", frontend.pagy_t('pagy.info.item_name', count: 1)
assert_equal "items", frontend.pagy_t('pagy.info.item_name', count: 10)

assert_equal "No %{item_name} found",
frontend.pagy_t('pagy.info.single_page', count: 0)
frontend.pagy_t('pagy.info.single_page', count: 0)
assert_equal "Displaying <b>1</b> %{item_name}",
frontend.pagy_t('pagy.info.single_page', count: 1)
frontend.pagy_t('pagy.info.single_page', count: 1)
assert_equal "Displaying <b>all 10</b> %{item_name}",
frontend.pagy_t('pagy.info.single_page', count: 10)
frontend.pagy_t('pagy.info.single_page', count: 10)
assert_equal "Displaying %{item_name} <b>%{from}-%{to}</b> of <b>10</b> in total",
frontend.pagy_t('pagy.info.multiple_pages', count: 10)
frontend.pagy_t('pagy.info.multiple_pages', count: 10)
end

def test_missing
assert_equal 'translation missing: "pagy.nav.not_here"', frontend.pagy_t('pagy.nav.not_here')
end

def test_render_info_no_118n_key
pagy = Pagy.new count: 0
assert_equal "No items found", frontend.pagy_info(pagy)
Expand All @@ -110,11 +110,11 @@ def test_render_info_no_118n_key
pagy = Pagy.new count: 100, page: 3
assert_equal "Displaying items <b>41-60</b> of <b>100</b> in total", frontend.pagy_info(pagy)
end

def test_render_info_with_existing_118n_key
Pagy::Frontend::I18N_DATA['pagy']['info']['product'] = { 'zero' => 'Products',
'one' => 'Product',
'other' => 'Products' }
'one' => 'Product',
'other' => 'Products' }
pagy = Pagy.new count: 0, item_path: 'pagy.info.product'
assert_equal "No Products found", frontend.pagy_info(pagy)
pagy = Pagy.new count: 1, item_path: 'pagy.info.product'
Expand Down
102 changes: 51 additions & 51 deletions test/pagy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ def test_initialization
assert_raises(ArgumentError) { Pagy.new({}) }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 0) }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 2, items: 0) }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 2, size: [1,2,3]).series }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 2, size: [1,2,3,'4']).series }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 2, size: [1, 2, 3]).series }
assert_raises(ArgumentError) { Pagy.new(count: 100, page: 2, size: [1, 2, 3, '4']).series }
assert_raises(Pagy::OutOfRangeError) { Pagy.new(count: 100, page: '11') }
assert_raises(Pagy::OutOfRangeError) { Pagy.new(count: 100, page: 12 ) }
assert_raises(Pagy::OutOfRangeError) { Pagy.new(count: 100, page: 12) }
end
end

describe "accessors" do
def test_respond_to_accessors
[
:count, :page, :items, :vars, # input
:offset, :pages, :last, :from, :to, :prev, :next, :series # output
:count, :page, :items, :vars, # input
:offset, :pages, :last, :from, :to, :prev, :next, :series # output
].each do |meth|
assert_respond_to pagy, meth
end
Expand All @@ -38,17 +38,17 @@ def test_respond_to_accessors

describe "#series" do
def setup
@vars0 = { count: 103,
items: 10,
size: [0,2,2,0] }
@vars0 = { count: 103,
items: 10,
size: [0, 2, 2, 0] }

@vars1 = { count: 103,
items: 10,
size: [3,0,0,3] }
@vars1 = { count: 103,
items: 10,
size: [3, 0, 0, 3] }

@vars2 = { count: 103,
items: 10,
size: [3,2,0,0] }
@vars2 = { count: 103,
items: 10,
size: [3, 2, 0, 0] }

end

Expand All @@ -61,86 +61,86 @@ def series_tests(page, *expected)

def test_page_1
series_tests 1,
["1", 2, 3, :gap],
["1", 2, 3, :gap, 9, 10, 11],
["1", 2, 3, :gap]
["1", 2, 3, :gap],
["1", 2, 3, :gap, 9, 10, 11],
["1", 2, 3, :gap]
end

def test_page_2
series_tests 2,
[1, "2", 3, 4, :gap],
[1, "2", 3, :gap, 9, 10, 11],
[1, "2", 3, :gap]
[1, "2", 3, 4, :gap],
[1, "2", 3, :gap, 9, 10, 11],
[1, "2", 3, :gap]
end

def test_page_3
series_tests 3,
[1, 2, "3", 4, 5, :gap],
[1, 2, "3", :gap, 9, 10, 11],
[1, 2, "3", :gap]
[1, 2, "3", 4, 5, :gap],
[1, 2, "3", :gap, 9, 10, 11],
[1, 2, "3", :gap]
end

def test_page_4
series_tests 4,
[1, 2, 3, "4", 5, 6, :gap],
[1, 2, 3, "4", :gap, 9, 10, 11],
[1, 2, 3, "4", :gap]
[1, 2, 3, "4", 5, 6, :gap],
[1, 2, 3, "4", :gap, 9, 10, 11],
[1, 2, 3, "4", :gap]
end

def test_page_5
series_tests 5,
[:gap, 3, 4, "5", 6, 7, :gap],
[1, 2, 3, 4, "5", :gap, 9, 10, 11],
[1, 2, 3, 4, "5", :gap]
[:gap, 3, 4, "5", 6, 7, :gap],
[1, 2, 3, 4, "5", :gap, 9, 10, 11],
[1, 2, 3, 4, "5", :gap]
end

def test_page_6
series_tests 6,
[:gap, 4, 5, "6", 7, 8, :gap],
[1, 2, 3, :gap, "6", :gap, 9, 10, 11],
[1, 2, 3, 4, 5, "6", :gap]
[:gap, 4, 5, "6", 7, 8, :gap],
[1, 2, 3, :gap, "6", :gap, 9, 10, 11],
[1, 2, 3, 4, 5, "6", :gap]
end

def test_page_7
series_tests 7,
[:gap, 5, 6, "7", 8, 9, :gap],
[1, 2, 3, :gap, "7", 8, 9, 10, 11],
[1, 2, 3, 4, 5, 6, "7", :gap]
[:gap, 5, 6, "7", 8, 9, :gap],
[1, 2, 3, :gap, "7", 8, 9, 10, 11],
[1, 2, 3, 4, 5, 6, "7", :gap]
end

def test_page_8
series_tests 8,
[:gap, 6, 7, "8", 9, 10, 11],
[1, 2, 3, :gap, "8", 9, 10, 11],
[1, 2, 3, :gap, 6, 7, "8", :gap]
[:gap, 6, 7, "8", 9, 10, 11],
[1, 2, 3, :gap, "8", 9, 10, 11],
[1, 2, 3, :gap, 6, 7, "8", :gap]
end

def test_page_9
series_tests 9,
[:gap, 7, 8, "9", 10, 11],
[1, 2, 3, :gap, "9", 10, 11],
[1, 2, 3, :gap, 7, 8, "9", :gap]
[:gap, 7, 8, "9", 10, 11],
[1, 2, 3, :gap, "9", 10, 11],
[1, 2, 3, :gap, 7, 8, "9", :gap]
end

def test_page_10
series_tests 10,
[:gap, 8, 9, "10", 11],
[1, 2, 3, :gap, 9, "10", 11],
[1, 2, 3, :gap, 8, 9, "10", 11]
[:gap, 8, 9, "10", 11],
[1, 2, 3, :gap, 9, "10", 11],
[1, 2, 3, :gap, 8, 9, "10", 11]
end

def test_page_11
series_tests 11,
[:gap, 9, 10, "11"],
[1, 2, 3, :gap, 9, 10, "11"],
[1, 2, 3, :gap, 9, 10, "11"]
[:gap, 9, 10, "11"],
[1, 2, 3, :gap, 9, 10, "11"],
[1, 2, 3, :gap, 9, 10, "11"]
end
end

# TODO: split these into #initialize or #series
describe "metrics" do
def setup
@vars = { items: 10, size: [3,2,2,3] }
@vars = { items: 10, size: [3, 2, 2, 3] }
@array = (1..103).to_a.extend(Pagy::Array::PageMethod)
end

Expand Down Expand Up @@ -329,12 +329,12 @@ def test_other_output
assert_equal 103, pagy.count
assert_equal 10, pagy.items
assert_equal 10, pagy.offset
assert_equal 11 , pagy.pages
assert_equal 11, pagy.pages
assert_equal 11, pagy.last
end

def test_initial_offset_page_1
pagy = Pagy.new(count: 87, page:1, outset:10, items: 10)
pagy = Pagy.new(count: 87, page: 1, outset: 10, items: 10)
assert_equal 10, pagy.offset
assert_equal 10, pagy.items
assert_equal 1, pagy.from
Expand All @@ -343,7 +343,7 @@ def test_initial_offset_page_1
end

def test_initial_offset_page_9
pagy = Pagy.new(count: 87, page:9, outset:10, items: 10)
pagy = Pagy.new(count: 87, page: 9, outset: 10, items: 10)
assert_equal 90, pagy.offset
assert_equal 7, pagy.items
assert_equal 81, pagy.from
Expand Down

0 comments on commit 1263540

Please sign in to comment.