Browse Source

Remove pagination indicators when only 1 page

pull/438/head
baarkerlounger 3 years ago
parent
commit
dfa0b89d5d
  1. 2
      app/views/pagy/_nav.html.erb
  2. 19
      spec/requests/case_logs_controller_spec.rb

2
app/views/pagy/_nav.html.erb

@ -13,6 +13,7 @@
<span class="govuk-visually-hidden">page</span> <span class="govuk-visually-hidden">page</span>
</span></a> </span></a>
</li> </li>
<% if pagy.pages > 1 %>
<% (1..pagy.pages).each do |idx| %> <% (1..pagy.pages).each do |idx| %>
<% if pagy.page == idx %> <% if pagy.page == idx %>
<li class="govuk-pagination__item govuk-pagination__item--current"><span class="govuk-visually-hidden">Page </span><%= idx %><span class="govuk-visually-hidden"> (current page) </span></li> <li class="govuk-pagination__item govuk-pagination__item--current"><span class="govuk-visually-hidden">Page </span><%= idx %><span class="govuk-visually-hidden"> (current page) </span></li>
@ -35,4 +36,5 @@
<p class="app_pagination__results"> <p class="app_pagination__results">
Showing <b><%= pagy.from %></b> to <b><%= pagy.to %></b> of <b><%= pagy.count %></b> <%= item_name %> Showing <b><%= pagy.from %></b> to <b><%= pagy.to %></b> of <b><%= pagy.count %></b> <%= item_name %>
</p> </p>
<% end %>
</nav> </nav>

19
spec/requests/case_logs_controller_spec.rb

@ -161,6 +161,10 @@ RSpec.describe CaseLogsController, type: :request do
before do before do
sign_in user sign_in user
end
context "when there are less than 20 logs" do
before do
get "/logs", headers: headers, params: {} get "/logs", headers: headers, params: {}
end end
@ -189,13 +193,26 @@ RSpec.describe CaseLogsController, type: :request do
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs")
end 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 <b>1</b> to <b>20</b> of <b>26</b> logs")
end
end
context "when there are more than 20 logs" do context "when there are more than 20 logs" do
before do before do
FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation)
get "/logs", headers: headers, params: {}
end end
context "when on the first page" do context "when on the first page" do
before do
get "/logs", headers: headers, params: {}
end
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")

Loading…
Cancel
Save