Browse Source

Remove pagination indicators when only 1 page

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

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

@ -13,26 +13,28 @@
<span class="govuk-visually-hidden">page</span> <span class="govuk-visually-hidden">page</span>
</span></a> </span></a>
</li> </li>
<% (1..pagy.pages).each do |idx| %> <% if pagy.pages > 1 %>
<% if pagy.page == idx %> <% (1..pagy.pages).each do |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> <% if pagy.page == idx %>
<% else %> <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"><a class="govuk-pagination__link" href=<%= "/logs?page=#{idx}" %>><span class="govuk-visually-hidden">Page </span><%= idx %></a></li> <% else %>
<li class="govuk-pagination__item"><a class="govuk-pagination__link" href=<%= "/logs?page=#{idx}" %>><span class="govuk-visually-hidden">Page </span><%= idx %></a></li>
<% end %>
<% end %> <% end %>
<% end %> <li class="govuk-pagination__item govuk-pagination__item--next">
<li class="govuk-pagination__item govuk-pagination__item--next"> <% if pagy.next %>
<% if pagy.next %> <a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.next}" %>>
<a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.next}" %>> <% end %>
<% end %> Next <span class="govuk-visually-hidden">page</span>
Next <span class="govuk-visually-hidden">page</span> <span class="govuk-pagination__link-title">
<span class="govuk-pagination__link-title"> <svg class="govuk-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17">
<svg class="govuk-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17"> <path d="m10.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
<path d="m10.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path> </svg>
</svg> </span></a>
</span></a> </li>
</li> </ul>
</ul> <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>

59
spec/requests/case_logs_controller_spec.rb

@ -161,41 +161,58 @@ RSpec.describe CaseLogsController, type: :request do
before do before do
sign_in user sign_in user
get "/logs", headers: headers, params: {}
end end
it "shows a table of logs" do context "when there are less than 20 logs" do
expect(CGI.unescape_html(response.body)).to match(/<table class="govuk-table">/) before do
expect(CGI.unescape_html(response.body)).to match(/logs/) get "/logs", headers: headers, params: {}
end end
it "only shows case logs for your organisation" do it "shows a table of logs" do
expected_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{case_log.id}\">#{case_log.id}</a>" expect(CGI.unescape_html(response.body)).to match(/<table class="govuk-table">/)
unauthorized_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{unauthorized_case_log.id}\">#{unauthorized_case_log.id}</a>" expect(CGI.unescape_html(response.body)).to match(/logs/)
expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) end
expect(CGI.unescape_html(response.body)).not_to include(unauthorized_case_row_log)
end
it "shows the formatted created at date for each log" do it "only shows case logs for your organisation" do
formatted_date = case_log.created_at.to_formatted_s(:govuk_date) expected_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{case_log.id}\">#{case_log.id}</a>"
expect(CGI.unescape_html(response.body)).to include(formatted_date) unauthorized_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{unauthorized_case_log.id}\">#{unauthorized_case_log.id}</a>"
end 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 it "shows the formatted created at date for each log" do
expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) formatted_date = case_log.created_at.to_formatted_s(:govuk_date)
end expect(CGI.unescape_html(response.body)).to include(formatted_date)
end
it "shows the total log count" do it "shows the log's status" do
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") 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("<strong>1</strong> 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 <b>1</b> to <b>20</b> of <b>26</b> logs")
end
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