@@ -4,69 +4,93 @@ class PaginationHelperTest < ActionView::TestCase
44 include PaginationHelper
55
66 test 'Next links for basic search' do
7- @pagination = { next : 12 }
8- query_params = { q : 'popcorn' }
7+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
8+ query_params = { q : 'popcorn' , page : 12 }
99 assert_equal (
10- '<a aria-label="Next page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=12 &q=popcorn">Next » </a>' , next_url ( query_params )
10+ '<a aria-label="Next 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=13 &q=popcorn">Next 20 results </a>' , next_url ( query_params )
1111 )
1212 end
1313
1414 test 'Next links for advanced search' do
15- @pagination = { next : 12 }
15+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
1616 query_params = { q : 'popcorn' , title : 'titles are cool' , contributors : 'yawn' }
1717 assert_equal (
18- '<a aria-label="Next page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?contributors=yawn&page=12 &q=popcorn&title=titles+are+cool">Next » </a>' ,
18+ '<a aria-label="Next 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?contributors=yawn&page=13 &q=popcorn&title=titles+are+cool">Next 20 results </a>' ,
1919 next_url ( query_params )
2020 )
2121 end
2222
2323 test 'Previous links for basic search' do
24- @pagination = { prev : 11 }
25- query_params = { q : 'popcorn' }
24+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
25+ query_params = { q : 'popcorn' , page : 12 }
2626 assert_equal (
27- '<a aria-label="Previous page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=11&q=popcorn">« Previous</a>' , prev_url ( query_params )
27+ '<a aria-label="Previous 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=11&q=popcorn">Previous 20 results </a>' , prev_url ( query_params )
2828 )
2929 end
3030
3131 test 'Previous links for advanced search' do
32- @pagination = { prev : 11 }
33- query_params = { q : 'popcorn' , title : 'titles are cool' , contributors : 'yawn' }
32+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
33+ query_params = { q : 'popcorn' , title : 'titles are cool' , contributors : 'yawn' , page : 12 }
3434 assert_equal (
35- '<a aria-label="Previous page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?contributors=yawn&page=11&q=popcorn&title=titles+are+cool">« Previous</a>' ,
35+ '<a aria-label="Previous 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?contributors=yawn&page=11&q=popcorn&title=titles+are+cool">Previous 20 results </a>' ,
3636 prev_url ( query_params )
3737 )
3838 end
3939
4040 test 'Next links preserve active tab' do
41- @pagination = { next : 12 }
41+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
4242 @active_tab = 'primo'
43- query_params = { q : 'popcorn' }
43+ query_params = { q : 'popcorn' , page : 12 }
4444 assert_equal (
45- '<a aria-label="Next page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=12 &q=popcorn&tab=primo">Next » </a>' , next_url ( query_params )
45+ '<a aria-label="Next 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=13 &q=popcorn&tab=primo">Next 20 results </a>' , next_url ( query_params )
4646 )
4747 end
4848
4949 test 'Previous links preserve active tab' do
50- @pagination = { prev : 11 }
50+ @pagination = { prev : 11 , next : 13 , per_page : 20 , hits : 1000 , end : 260 }
5151 @active_tab = 'timdex'
52- query_params = { q : 'popcorn' }
52+ query_params = { q : 'popcorn' , page : 12 }
5353 assert_equal (
54- '<a aria-label="Previous page " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=11&q=popcorn&tab=timdex">« Previous</a>' , prev_url ( query_params )
54+ '<a aria-label="Previous 20 results " data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=11&q=popcorn&tab=timdex">Previous 20 results </a>' , prev_url ( query_params )
5555 )
5656 end
5757
58- test 'First links for basic search' do
58+ test 'First links for initial basic search is disabled ' do
5959 query_params = { q : 'popcorn' }
6060 assert_equal (
61- '<a aria-label="First page" data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=1&q=popcorn">«« First</a >' , first_url ( query_params )
61+ '<span role="link" aria-disabled="true" tabindex="-1"> First</span >' , first_url ( query_params )
6262 )
6363 end
6464
6565 test 'First links preserve active tab' do
6666 @active_tab = 'primo'
67- query_params = { q : 'popcorn' }
67+ query_params = { q : 'popcorn' , page : 5 }
68+ assert_equal (
69+ '<a aria-label="First" data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=1&q=popcorn&tab=primo">First</a>' , first_url ( query_params )
70+ )
71+ end
72+
73+ test 'Next link for penultimate page is correct' do
74+ @pagination = { next : 6 , per_page : 20 , hits : 102 , end : 100 }
75+ query_params = { q : 'popcorn' , page : 5 }
76+ assert_equal (
77+ '<a aria-label="Next 2 results" data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=6&q=popcorn">Next 2 results</a>' , next_url ( query_params )
78+ )
79+ end
80+
81+ test 'Next link for full last page is disabled' do
82+ @pagination = { next : 6 , per_page : 20 , hits : 100 , end : 100 }
83+ query_params = { q : 'popcorn' , page : 5 }
84+ assert_equal (
85+ "<span role='link' aria-disabled='true' tabindex='-1'>Next 0 results</span>" , next_url ( query_params )
86+ )
87+ end
88+
89+ test 'Previous link for first page is disabled' do
90+ @pagination = { prev : nil , per_page : 20 , hits : 100 , end : 20 }
91+ query_params = { q : 'popcorn' , page : 1 }
6892 assert_equal (
69- '<a aria-label="First page" data-turbo-frame="search-results" data-turbo-action="advance" rel="nofollow" href="/results?page=1&q=popcorn&tab=primo">«« First</a>' , first_url ( query_params )
93+ "<span role='link' aria-disabled='true' tabindex='-1'>Previous 20 results</span>" , prev_url ( query_params )
7094 )
7195 end
7296end
0 commit comments