diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb
index 3e02b00ce..c0587ab51 100644
--- a/app/views/organisations/index.html.erb
+++ b/app/views/organisations/index.html.erb
@@ -1,6 +1,6 @@
<% item_label = @pagy.count > 1 ? "organisations" : "organisation" %>
<% if @searched.present? %>
- <% title = "Organisations (#{@pagy.count} #{item_label} matching ‘#{@searched}’" %>
+ <% title = "Organisations (#{@pagy.count} #{item_label} matching ‘#{@searched}’)" %>
<% else %>
<% title = "Organisations" %>
<% end %>
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb
index 74d7aba46..888730a0e 100644
--- a/spec/requests/organisations_controller_spec.rb
+++ b/spec/requests/organisations_controller_spec.rb
@@ -887,6 +887,118 @@ RSpec.describe OrganisationsController, type: :request do
request
expect(response).to redirect_to("/organisations")
end
+
+ it "has a sub-navigation with correct tabs" do
+ expect(page).to have_css(".app-sub-navigation")
+ expect(page).to have_content("About this organisation")
+ end
+
+ it "allows to edit the organisation details" do
+ expect(page).to have_link("Change", count: 3)
+ end
+ end
+ end
+
+ context "when there are more than 20 organisations" do
+ let(:support_user) { FactoryBot.create(:user, :support) }
+
+ let(:total_organisations_count) { Organisation.all.count }
+
+ before do
+ FactoryBot.create_list(:organisation, 25)
+ allow(support_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
+
+ it "has pagination in the title" do
+ expect(page).to have_title("Organisations (page 1 of 2)")
+ end
+ end
+
+ context "when on the second page" do
+ before do
+ get "/organisations?page=2", headers:, params: {}
+ end
+
+ it "shows the total organisations count" do
+ expect(CGI.unescape_html(response.body)).to match("#{total_organisations_count} total organisations.")
+ 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 21 to #{total_organisations_count} of #{total_organisations_count} organisations")
+ end
+
+ it "has pagination in the title" do
+ expect(page).to have_title("Organisations (page 2 of 2)")
+ end
+ end
+
+ context "when searching" do
+ let!(:searched_organisation) { FactoryBot.create(:organisation, name: "Unusual name") }
+ let!(:other_organisation) { FactoryBot.create(:organisation, name: "Some other name") }
+ let(:search_param) { "Unusual" }
+
+ before do
+ get "/organisations?search=#{search_param}"
+ end
+
+ it "returns matching results" do
+ expect(page).to have_content(searched_organisation.name)
+ expect(page).not_to have_content(other_organisation.name)
+ end
+
+ it "updates the table caption" do
+ expect(page).to have_content("1 organisation found matching ‘#{search_param}’ of 29 total organisations.")
+ end
+
+ it "has search in the title" do
+ expect(page).to have_title("Organisations (1 organisation matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
+ end
+
+ context "when the search term matches more than 1 result" do
+ let(:search_param) { "name" }
+
+ it "returns matching results" do
+ expect(page).to have_content(searched_organisation.name)
+ expect(page).to have_content(other_organisation.name)
+ end
+
+ it "updates the table caption" do
+ expect(page).to have_content("2 organisations found matching ‘#{search_param}’ of 29 total organisations.")
+ end
+
+ it "has search in the title" do
+ expect(page).to have_title("Organisations (2 organisations matching ‘#{search_param}’ of 29 total organisations) - Submit social housing lettings and sales data (CORE) - GOV.UK")
+ end
+ end
+
+ context "when search results require pagination" do
+ let(:search_param) { "DLUHC" }
+
+ it "has search and pagination in the title" do
+ expect(page).to have_title("Organisations (27 organisations matching ‘#{search_param}’ of 29 total organisations) (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
+ end
+ end
end
end
end