From 092c8c2ce14d1b9b7d07a064db10966d27a2e145 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 15 Oct 2024 17:12:35 +0300 Subject: [PATCH] Add older/newer links in front of diary, comment, issue, block pages --- app/views/diary_entries/_page.html.erb | 4 ++ app/views/issues/_page.html.erb | 5 +++ app/views/user_blocks/_page.html.erb | 5 +++ .../users/changeset_comments/_page.html.erb | 4 ++ app/views/users/diary_comments/_page.html.erb | 4 ++ .../diary_entries_controller_test.rb | 41 ++++++++++++------- test/system/issues_test.rb | 4 +- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/app/views/diary_entries/_page.html.erb b/app/views/diary_entries/_page.html.erb index 9cba05d20..0940c55be 100644 --- a/app/views/diary_entries/_page.html.erb +++ b/app/views/diary_entries/_page.html.erb @@ -1,6 +1,10 @@

<%= t ".recent_entries" %>

+ <%= render "shared/pagination", + :newer_id => @newer_entries_id, + :older_id => @older_entries_id %> + <%= render @entries, :truncated => true %> <%= render "shared/pagination", diff --git a/app/views/issues/_page.html.erb b/app/views/issues/_page.html.erb index d42d6238d..890423c87 100644 --- a/app/views/issues/_page.html.erb +++ b/app/views/issues/_page.html.erb @@ -6,6 +6,10 @@

<%= t ".issues_not_found" %>

<% end %> <% else %> + <%= render "shared/pagination", + :newer_id => @newer_issues_id, + :older_id => @older_issues_id %> + @@ -38,6 +42,7 @@ <% end %>
+ <%= render "shared/pagination", :newer_id => @newer_issues_id, :older_id => @older_issues_id %> diff --git a/app/views/user_blocks/_page.html.erb b/app/views/user_blocks/_page.html.erb index fa9f0b2d2..67911aca2 100644 --- a/app/views/user_blocks/_page.html.erb +++ b/app/views/user_blocks/_page.html.erb @@ -1,4 +1,9 @@ + <%= render "shared/pagination", + :translation_scope => "shared.pagination.user_blocks", + :newer_id => @newer_user_blocks_id, + :older_id => @older_user_blocks_id %> + diff --git a/app/views/users/changeset_comments/_page.html.erb b/app/views/users/changeset_comments/_page.html.erb index d06159081..3aeaad209 100644 --- a/app/views/users/changeset_comments/_page.html.erb +++ b/app/views/users/changeset_comments/_page.html.erb @@ -1,4 +1,8 @@ + <%= render "shared/pagination", + :newer_id => @newer_comments_id, + :older_id => @older_comments_id %> +
diff --git a/app/views/users/diary_comments/_page.html.erb b/app/views/users/diary_comments/_page.html.erb index cc6019cff..9b34d85f9 100644 --- a/app/views/users/diary_comments/_page.html.erb +++ b/app/views/users/diary_comments/_page.html.erb @@ -1,4 +1,8 @@ + <%= render "shared/pagination", + :newer_id => @newer_comments_id, + :older_id => @older_comments_id %> +
diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index f3f45d238..3acbcba19 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -471,41 +471,42 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest 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 @@ -995,4 +996,14 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest 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 diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 3cf7d22d5..d116b3064 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -204,7 +204,7 @@ class IssuesTest < ApplicationSystemTestCase 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| @@ -215,7 +215,7 @@ class IssuesTest < ApplicationSystemTestCase 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| -- 2.39.5