Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add older/newer links in front of diary, comment, issue, block pages #5262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/views/diary_comments/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<%= render "shared/pagination",
:newer_id => @newer_comments_id,
:older_id => @older_comments_id %>

<table class="table table-striped" width="100%">
<thead>
<tr>
Expand Down
4 changes: 4 additions & 0 deletions app/views/diary_entries/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<h4><%= t ".recent_entries" %></h4>

<%= render "shared/pagination",
:newer_id => @newer_entries_id,
:older_id => @older_entries_id %>

<%= render @entries %>

<%= render "shared/pagination",
Expand Down
5 changes: 5 additions & 0 deletions app/views/issues/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<p><%= t ".issues_not_found" %></p>
<% end %>
<% else %>
<%= render "shared/pagination",
:newer_id => @newer_issues_id,
:older_id => @older_issues_id %>

<table class="table table-sm">
<thead>
<tr>
Expand Down Expand Up @@ -35,6 +39,7 @@
<% end %>
</tbody>
</table>

<%= render "shared/pagination",
:newer_id => @newer_issues_id,
:older_id => @older_issues_id %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/user_blocks/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<%= render "shared/pagination",
:newer_id => @newer_user_blocks_id,
:older_id => @older_user_blocks_id %>

<table id="block_list" class="table table-borderless table-striped table-sm">
<thead>
<tr>
Expand Down
41 changes: 26 additions & 15 deletions test/controllers/diary_entries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,41 +449,42 @@ def test_index_language
def test_index_paged
# Create several pages worth of diary entries
create_list(:diary_entry, 50)
next_path = diary_entries_path

# Try and get the index
get diary_entries_path
get next_path
assert_response :success
assert_select "article.diary_post", :count => 20
assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1
assert_select "li.page-item.disabled span.page-link", :text => "Newer Entries", :count => 1
check_no_page_link "Newer Entries"
next_path = check_page_link "Older Entries"

# Try and get the second page
get css_select("li.page-item .page-link").last["href"]
get next_path
assert_response :success
assert_select "article.diary_post", :count => 20
assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1
assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1
check_page_link "Newer Entries"
next_path = check_page_link "Older Entries"

# Try and get the third page
get css_select("li.page-item .page-link").last["href"]
get next_path
assert_response :success
assert_select "article.diary_post", :count => 10
assert_select "li.page-item.disabled span.page-link", :text => "Older Entries", :count => 1
assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1
next_path = check_page_link "Newer Entries"
check_no_page_link "Older Entries"

# Go back to the second page
get css_select("li.page-item .page-link").first["href"]
get next_path
assert_response :success
assert_select "article.diary_post", :count => 20
assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1
assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1
next_path = check_page_link "Newer Entries"
check_page_link "Older Entries"

# Go back to the first page
get css_select("li.page-item .page-link").first["href"]
get next_path
assert_response :success
assert_select "article.diary_post", :count => 20
assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1
assert_select "li.page-item.disabled span.page-link", :text => "Newer Entries", :count => 1
check_no_page_link "Newer Entries"
check_page_link "Older Entries"
end

def test_index_invalid_paged
Expand Down Expand Up @@ -962,4 +963,14 @@ def check_diary_index(*entries)
assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}"
end
end

def check_no_page_link(name)
assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/, :count => 0 }, "unexpected #{name} page link"
end

def check_page_link(name)
assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/ }, "missing #{name} page link" do |buttons|
return buttons.first.attributes["href"].value
end
end
end
4 changes: 2 additions & 2 deletions test/system/issues_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_issues_pagination
end

# Second Page
click_on "Older Issues"
click_on "Older Issues", :match => :first
assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.page.issues_not_found")
4.upto(8).each do |n|
Expand All @@ -194,7 +194,7 @@ def test_issues_pagination
end

# Back to First Page
click_on "Newer Issues"
click_on "Newer Issues", :match => :first
assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.page.issues_not_found")
4.upto(8).each do |n|
Expand Down