From dfa0b89d5d3dad22105109ea04cb8790ba5c4ce9 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 31 Mar 2022 12:47:37 +0100 Subject: [PATCH] Remove pagination indicators when only 1 page --- app/views/pagy/_nav.html.erb | 44 ++++++++-------- spec/requests/case_logs_controller_spec.rb | 59 ++++++++++++++-------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/app/views/pagy/_nav.html.erb b/app/views/pagy/_nav.html.erb index d7281690d..bd470b336 100644 --- a/app/views/pagy/_nav.html.erb +++ b/app/views/pagy/_nav.html.erb @@ -13,26 +13,28 @@ page - <% (1..pagy.pages).each do |idx| %> - <% if pagy.page == idx %> -
  • Page <%= idx %> (current page)
  • - <% else %> -
  • >Page <%= idx %>
  • + <% if pagy.pages > 1 %> + <% (1..pagy.pages).each do |idx| %> + <% if pagy.page == idx %> +
  • Page <%= idx %> (current page)
  • + <% else %> +
  • >Page <%= idx %>
  • + <% end %> <% end %> - <% end %> -
  • - <% if pagy.next %> - > - <% end %> - Next page - - - - - -
  • - -

    - Showing <%= pagy.from %> to <%= pagy.to %> of <%= pagy.count %> <%= item_name %> -

    +
  • + <% if pagy.next %> + > + <% end %> + Next page + + + + + +
  • + +

    + Showing <%= pagy.from %> to <%= pagy.to %> of <%= pagy.count %> <%= item_name %> +

    + <% end %> diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index 74e79e421..1ca8cb9b7 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -161,41 +161,58 @@ RSpec.describe CaseLogsController, type: :request do before do sign_in user - get "/logs", headers: headers, params: {} end - it "shows a table of logs" do - expect(CGI.unescape_html(response.body)).to match(//) - expect(CGI.unescape_html(response.body)).to match(/logs/) - end + context "when there are less than 20 logs" do + before do + get "/logs", headers: headers, params: {} + end - it "only shows case logs for your organisation" do - expected_case_row_log = "#{case_log.id}" - unauthorized_case_row_log = "#{unauthorized_case_log.id}" - expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) - expect(CGI.unescape_html(response.body)).not_to include(unauthorized_case_row_log) - end + it "shows a table of logs" do + expect(CGI.unescape_html(response.body)).to match(/
    /) + expect(CGI.unescape_html(response.body)).to match(/logs/) + end - it "shows the formatted created at date for each log" do - formatted_date = case_log.created_at.to_formatted_s(:govuk_date) - expect(CGI.unescape_html(response.body)).to include(formatted_date) - end + it "only shows case logs for your organisation" do + expected_case_row_log = "#{case_log.id}" + unauthorized_case_row_log = "#{unauthorized_case_log.id}" + expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) + expect(CGI.unescape_html(response.body)).not_to include(unauthorized_case_row_log) + end - it "shows the log's status" do - expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) - end + it "shows the formatted created at date for each log" do + formatted_date = case_log.created_at.to_formatted_s(:govuk_date) + expect(CGI.unescape_html(response.body)).to include(formatted_date) + end - it "shows the total log count" do - expect(CGI.unescape_html(response.body)).to match("1 total logs") + it "shows the log's status" do + expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) + end + + it "shows the total log count" do + expect(CGI.unescape_html(response.body)).to match("1 total logs") + end + + it "does not show the pagination links" do + expect(page).not_to have_link("Previous") + expect(page).not_to have_link("Next") + end + + it "does not show the pagination result line" do + expect(CGI.unescape_html(response.body)).not_to match("Showing 1 to 20 of 26 logs") + end end context "when there are more than 20 logs" do before do FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) - get "/logs", headers: headers, params: {} end context "when on the first page" do + before do + get "/logs", headers: headers, params: {} + end + it "has pagination links" do expect(page).to have_content("Previous") expect(page).not_to have_link("Previous")