Browse Source

Make sure we have next/prev

pull/438/head
baarkerlounger 3 years ago
parent
commit
64011cec9d
  1. 8
      app/views/pagy/_nav.html.erb
  2. 35
      spec/requests/case_logs_controller_spec.rb

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

@ -3,7 +3,9 @@
<ul class="govuk-pagination__list">
<li class="govuk-pagination__item govuk-pagination__item--prev">
<a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.prev}" %>>
<% if pagy.prev %>
<a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.prev}" %>>
<% end %>
<span class="govuk-pagination__link-title">
<svg class="govuk-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
@ -19,7 +21,9 @@
<% end %>
<% end %>
<li class="govuk-pagination__item govuk-pagination__item--next">
<a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.next}" %>>
<% if pagy.next %>
<a class="govuk-pagination__link" href=<%= "/logs?page=#{pagy.next}" %>>
<% end %>
Next <span class="govuk-visually-hidden">page</span>
<span class="govuk-pagination__link-title">
<svg class="govuk-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17">

35
spec/requests/case_logs_controller_spec.rb

@ -137,6 +137,7 @@ RSpec.describe CaseLogsController, type: :request do
end
describe "GET" do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation) }
@ -196,8 +197,38 @@ RSpec.describe CaseLogsController, type: :request do
get "/logs", headers: headers, params: {}
end
it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> total logs")
context "when on the first page" do
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).not_to have_link("Previous")
expect(page).to have_content("Next")
expect(page).to have_link("Next")
end
it "shows which logs are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> logs")
end
end
context "when on the second page" do
before do
get "/logs?page=2", headers: headers, params: {}
end
it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> total logs")
end
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).to have_link("Previous")
expect(page).to have_content("Next")
expect(page).not_to have_link("Next")
end
it "shows which logs are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>21</b> to <b>26</b> logs")
end
end
end
end

Loading…
Cancel
Save