From 4836565b959a3e970e8e1541712d8f24494218c3 Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 18 May 2022 14:43:57 +0100 Subject: [PATCH] added pagination test with next and previous links and total count for support user --- .../requests/organisations_controller_spec.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 0e5eb4a19..8324079d4 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -315,5 +315,33 @@ RSpec.describe OrganisationsController, type: :request do expect(page).to have_link unauthorised_organisation.name, href: "organisations/#{unauthorised_organisation.id}/logs" end end + + context "when there are more than 20 organisations" do + before do + FactoryBot.create_list(:organisation, 25) + end + + let(:support_user) { FactoryBot.create(:user, :support) } + + let(:total_organisations_count) { Organisation.all.count } + + before do + allow(user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in support_user + get "/organisations" + end + + 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 organisations are being shown on the current page" do + expect(CGI.unescape_html(response.body)).to match("Showing 1 to 20 of #{total_organisations_count} organisations") + end + end end end