Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Dec 1, 2018
1 parent 6e8cde8 commit 910facc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 58 deletions.
4 changes: 3 additions & 1 deletion lib/pagy/extras/items.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
# frozen_string_literal: true

require 'pagy/extras/shared'

class Pagy

# Default variables for this extra
Expand Down Expand Up @@ -51,7 +53,7 @@ def pagy_items_selector(pagy, id=caller(1,1)[0].hash.to_s)
html << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)})
html << %(</span><script type="application/json" class="pagy-json">#{[:items, id, MARKER, pagy.from]}</script>)
html << %(</span>#{pagy_json_tag(:items, id, MARKER, pagy.from)})
end

end
Expand Down
14 changes: 7 additions & 7 deletions test/pagy/extras/bootstrap_test.rb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions test/pagy/extras/bulma_test.rb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions test/pagy/extras/foundation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@
pagy, _ = @array.pagy(1)
html = frontend.pagy_foundation_compact_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a style=\"margin-bottom: 0px;\" class=\"prev button primary disabled\" href=\"#\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"1\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a href=\"/foo?page=2\" rel=\"next\" style=\"margin-bottom: 0px;\" aria-label=\"next\" class=\"next button primary\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-compact-json\">[\"test-id\", \"#{Pagy::Frontend::MARKER}\", \"1\", false]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a style=\"margin-bottom: 0px;\" class=\"prev button primary disabled\" href=\"#\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"1\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a href=\"/foo?page=2\" rel=\"next\" style=\"margin-bottom: 0px;\" aria-label=\"next\" class=\"next button primary\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-json\">[\"compact\",\"test-id\",\"#{Pagy::Frontend::MARKER}\",1,false]</script>"
end

it 'renders page 3 for foundation' do
pagy, _ = @array.pagy(3)
html = frontend.pagy_foundation_compact_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a href=\"/foo?page=2\" rel=\"prev\" style=\"margin-bottom: 0px;\" aria-label=\"previous\" class=\"prev button primary\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"3\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a href=\"/foo?page=4\" rel=\"next\" style=\"margin-bottom: 0px;\" aria-label=\"next\" class=\"next button primary\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-compact-json\">[\"test-id\", \"#{Pagy::Frontend::MARKER}\", \"3\", false]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a href=\"/foo?page=2\" rel=\"prev\" style=\"margin-bottom: 0px;\" aria-label=\"previous\" class=\"prev button primary\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"3\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a href=\"/foo?page=4\" rel=\"next\" style=\"margin-bottom: 0px;\" aria-label=\"next\" class=\"next button primary\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-json\">[\"compact\",\"test-id\",\"#{Pagy::Frontend::MARKER}\",3,false]</script>"
end

it 'renders page 6 for foundation' do
pagy, _ = @array.pagy(6)
html = frontend.pagy_foundation_compact_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a href=\"/foo?page=5\" rel=\"prev\" style=\"margin-bottom: 0px;\" aria-label=\"previous\" class=\"prev button primary\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"6\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a style=\"margin-bottom: 0px;\" class=\"next button primary disabled\" href=\"#\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-compact-json\">[\"test-id\", \"#{Pagy::Frontend::MARKER}\", \"6\", false]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-compact-foundation pagy-foundation-compact-nav\" role=\"navigation\" aria-label=\"Pagination\"><a href=\"/foo?page=#{Pagy::Frontend::MARKER}\" style=\"display: none;\" ></a><div class=\"input-group\"><a href=\"/foo?page=5\" rel=\"prev\" style=\"margin-bottom: 0px;\" aria-label=\"previous\" class=\"prev button primary\">&lsaquo;&nbsp;Prev</a><span class=\"input-group-label\">Page <input class=\"input-group-field cell shrink\" type=\"number\" min=\"1\" max=\"6\" value=\"6\" style=\"width: 2rem; padding: 0 0.3rem; margin: 0 0.3rem;\"> of 6</span><a style=\"margin-bottom: 0px;\" class=\"next button primary disabled\" href=\"#\">Next&nbsp;&rsaquo;</a></div></nav><script type=\"application/json\" class=\"pagy-json\">[\"compact\",\"test-id\",\"#{Pagy::Frontend::MARKER}\",6,false]</script>"
end

end
Expand All @@ -80,29 +80,29 @@
pagy, _ = @array.pagy(1)
html = frontend.pagy_foundation_responsive_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-responsive-json\">[\"test-id\", {\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev disabled\\\">&lsaquo;&nbsp;Prev</li>\",\"1\":\"<li class=\\\"current\\\">1</li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" rel=\\\"next\\\" >2</a></li>\",\"3\":\"<li><a href=\\\"/foo?page=3\\\" >3</a></li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" >5</a></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=2\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"}, [0], {\"0\":[\"1\",2,3,4,5,6]}]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-json\">[\"responsive\",\"test-id\",{\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev disabled\\\">&lsaquo;&nbsp;Prev</li>\",\"1\":\"<li class=\\\"current\\\">1</li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" rel=\\\"next\\\" >2</a></li>\",\"3\":\"<li><a href=\\\"/foo?page=3\\\" >3</a></li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" >5</a></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=2\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"},[0],{\"0\":[\"1\",2,3,4,5,6]}]</script>"
end

it 'renders page 3 for foundation' do
pagy, _ = @array.pagy(3)
html = frontend.pagy_foundation_responsive_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-responsive-json\">[\"test-id\", {\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=2\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" rel=\\\"prev\\\" >2</a></li>\",\"3\":\"<li class=\\\"current\\\">3</li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" rel=\\\"next\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" >5</a></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=4\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"}, [0], {\"0\":[1,2,\"3\",4,5,6]}]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-json\">[\"responsive\",\"test-id\",{\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=2\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" rel=\\\"prev\\\" >2</a></li>\",\"3\":\"<li class=\\\"current\\\">3</li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" rel=\\\"next\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" >5</a></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=4\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"},[0],{\"0\":[1,2,\"3\",4,5,6]}]</script>"
end

it 'renders page 6 for foundation' do
pagy, _ = @array.pagy(6)
html = frontend.pagy_foundation_responsive_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-responsive-json\">[\"test-id\", {\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=5\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" >2</a></li>\",\"3\":\"<li><a href=\\\"/foo?page=3\\\" >3</a></li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" rel=\\\"prev\\\" >5</a></li>\",\"6\":\"<li class=\\\"current\\\">6</li>\",\"after\":\"<li class=\\\"next disabled\\\">Next&nbsp;&rsaquo;</li></ul>\"}, [0], {\"0\":[1,2,3,4,5,\"6\"]}]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-json\">[\"responsive\",\"test-id\",{\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=5\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"2\":\"<li><a href=\\\"/foo?page=2\\\" >2</a></li>\",\"3\":\"<li><a href=\\\"/foo?page=3\\\" >3</a></li>\",\"4\":\"<li><a href=\\\"/foo?page=4\\\" >4</a></li>\",\"5\":\"<li><a href=\\\"/foo?page=5\\\" rel=\\\"prev\\\" >5</a></li>\",\"6\":\"<li class=\\\"current\\\">6</li>\",\"after\":\"<li class=\\\"next disabled\\\">Next&nbsp;&rsaquo;</li></ul>\"},[0],{\"0\":[1,2,3,4,5,\"6\"]}]</script>"
end

it 'renders page 10 for foundation' do
@array = (1..1000).to_a.extend(Pagy::Array::PageMethod)
pagy, _ = @array.pagy(10)
html = frontend.pagy_foundation_responsive_nav(pagy, pagy_test_id)
html.must_equal \
"<nav id=\"pagy-nav-test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-responsive-json\">[\"test-id\", {\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=9\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"gap\":\"<li class=\\\"ellipsis gap\\\" aria-hidden=\\\"true\\\"></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"7\":\"<li><a href=\\\"/foo?page=7\\\" >7</a></li>\",\"8\":\"<li><a href=\\\"/foo?page=8\\\" >8</a></li>\",\"9\":\"<li><a href=\\\"/foo?page=9\\\" rel=\\\"prev\\\" >9</a></li>\",\"10\":\"<li class=\\\"current\\\">10</li>\",\"11\":\"<li><a href=\\\"/foo?page=11\\\" rel=\\\"next\\\" >11</a></li>\",\"12\":\"<li><a href=\\\"/foo?page=12\\\" >12</a></li>\",\"13\":\"<li><a href=\\\"/foo?page=13\\\" >13</a></li>\",\"14\":\"<li><a href=\\\"/foo?page=14\\\" >14</a></li>\",\"50\":\"<li><a href=\\\"/foo?page=50\\\" >50</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=11\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"}, [0], {\"0\":[1,\"gap\",6,7,8,9,\"10\",11,12,13,14,\"gap\",50]}]</script>"
"<nav id=\"test-id\" class=\"pagy-nav-responsive-foundation pagy-foundation-responsive-nav\" aria-label=\"Pagination\"></nav><script type=\"application/json\" class=\"pagy-json\">[\"responsive\",\"test-id\",{\"before\":\"<ul class=\\\"pagination\\\"><li class=\\\"prev\\\"><a href=\\\"/foo?page=9\\\" rel=\\\"prev\\\" aria-label=\\\"previous\\\">&lsaquo;&nbsp;Prev</a></li>\",\"1\":\"<li><a href=\\\"/foo?page=1\\\" >1</a></li>\",\"gap\":\"<li class=\\\"ellipsis gap\\\" aria-hidden=\\\"true\\\"></li>\",\"6\":\"<li><a href=\\\"/foo?page=6\\\" >6</a></li>\",\"7\":\"<li><a href=\\\"/foo?page=7\\\" >7</a></li>\",\"8\":\"<li><a href=\\\"/foo?page=8\\\" >8</a></li>\",\"9\":\"<li><a href=\\\"/foo?page=9\\\" rel=\\\"prev\\\" >9</a></li>\",\"10\":\"<li class=\\\"current\\\">10</li>\",\"11\":\"<li><a href=\\\"/foo?page=11\\\" rel=\\\"next\\\" >11</a></li>\",\"12\":\"<li><a href=\\\"/foo?page=12\\\" >12</a></li>\",\"13\":\"<li><a href=\\\"/foo?page=13\\\" >13</a></li>\",\"14\":\"<li><a href=\\\"/foo?page=14\\\" >14</a></li>\",\"50\":\"<li><a href=\\\"/foo?page=50\\\" >50</a></li>\",\"after\":\"<li class=\\\"next\\\"><a href=\\\"/foo?page=11\\\" rel=\\\"next\\\" aria-label=\\\"next\\\">Next&nbsp;&rsaquo;</a></li></ul>\"},[0],{\"0\":[1,\"gap\",6,7,8,9,\"10\",11,12,13,14,\"gap\",50]}]</script>"
end

end
Expand Down
4 changes: 2 additions & 2 deletions test/pagy/extras/items_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@
html, id = frontend.pagy_items_selector(@pagy), caller(0,1)[0].hash

html.must_equal \
%(<span id="pagy-items-#{id}">) +
%(<span id="#{id}">) +
%(<a href="/foo?page=#{Pagy::Frontend::MARKER}-page-&items=#{Pagy::Frontend::MARKER}-items-"></a>) +
%(Show <input type="number" min="1" max="100" value="20" style="padding: 0; text-align: center; width: 3rem;"> items per page) +
%(</span>) +
%(<script type="application/json" class="pagy-items-json">["#{id}", "#{Pagy::Frontend::MARKER}", 41]</script>)
%(<script type="application/json" class="pagy-json">["items","#{id}","#{Pagy::Frontend::MARKER}",41]</script>)
end

end
Expand Down
Loading

0 comments on commit 910facc

Please sign in to comment.