-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
URIs are always joined with forward slash (#11)
* Use Rack::Request#path instead of File.join * Add a few tests for Pagy::Frontend
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'test_helper' | ||
require 'rack' | ||
|
||
class FrontendTest < Minitest::Test | ||
|
||
class TestView | ||
include Pagy::Frontend | ||
|
||
def request | ||
Rack::Request.new('SCRIPT_NAME' => '/foo') | ||
end | ||
end | ||
|
||
def setup | ||
@frontend = TestView.new | ||
@array = (1..103).to_a.extend(Pagy::Array::PageMethod) | ||
end | ||
|
||
def test_pagy_nav_page_1 | ||
pagy, paged = @array.pagy(1) | ||
|
||
assert_equal( | ||
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \ | ||
'<span class="page prev disabled">‹ Prev</span> ' \ | ||
'<span class="page active">1</span> ' \ | ||
'<span class="page"><a href="/foo?page=2" rel="next">2</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=3">3</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=4">4</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=5">5</a></span> ' \ | ||
'<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 ›</a></span>' \ | ||
'</nav>', | ||
@frontend.pagy_nav(pagy) | ||
) | ||
end | ||
|
||
def test_pagy_nav_page_3 | ||
pagy, paged = @array.pagy(3) | ||
|
||
assert_equal( | ||
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \ | ||
'<span class="page prev"><a href="/foo?page=2" rel="prev" aria-label="previous">‹ 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> ' \ | ||
'<span class="page active">3</span> ' \ | ||
'<span class="page"><a href="/foo?page=4" rel="next">4</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=5">5</a></span> ' \ | ||
'<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 ›</a></span>' \ | ||
'</nav>', | ||
@frontend.pagy_nav(pagy) | ||
) | ||
end | ||
|
||
def test_pagy_nav_page_6 | ||
pagy, paged = @array.pagy(6) | ||
|
||
assert_equal( | ||
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \ | ||
'<span class="page prev"><a href="/foo?page=5" rel="prev" aria-label="previous">‹ 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> ' \ | ||
'<span class="page"><a href="/foo?page=3">3</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=4">4</a></span> ' \ | ||
'<span class="page"><a href="/foo?page=5" rel="prev">5</a></span> ' \ | ||
'<span class="page active">6</span> ' \ | ||
'<span class="page next disabled">Next ›</span>' \ | ||
'</nav>', | ||
@frontend.pagy_nav(pagy) | ||
) | ||
end | ||
end |