diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb
index aea8d2e85..266654bda 100644
--- a/app/views/schemes/index.html.erb
+++ b/app/views/schemes/index.html.erb
@@ -10,33 +10,6 @@
-
- <%= govuk_table do |table| %>
- <%= table.head do |head| %>
- <%= head.row do |row| %>
- <% row.cell(header: true, text: "Code", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Service", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Managing agent", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Created", html_attributes: {
- scope: "col",
- }) %>
- <% end %>
- <% end %>
- <% @schemes.each do |scheme| %>
- <%= table.body do |body| %>
- <%= body.row do |row| %>
- <% row.cell(text: scheme.code) %>
- <% row.cell(text: scheme.service) %>
- <% row.cell(text: scheme.organisation.name) %>
- <% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %>
- <% end %>
- <% end %>
- <% end %>
- <% end %>
-
+<%= render partial: "scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
+
+<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %>
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index c4b4cf135..74ffd5fcf 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -39,6 +39,70 @@ RSpec.describe SchemesController, type: :request do
it "has correct title" do
expect(page).to have_title("Supported housing services - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
+
+ it "shows the total organisations count" do
+ expect(CGI.unescape_html(response.body)).to match("#{schemes.count} total schemes.")
+ end
+
+ context "when paginating over 20 results" do
+ let!(:other_schemes) { FactoryBot.create_list(:scheme, 20) }
+ let(:total_schemes_count) { Scheme.count }
+
+ context "when on the first page" do
+ before do
+ get "/supported-housing"
+ end
+
+ it "shows the total schemes count" do
+ expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes.")
+ end
+
+ it "has pagination links" do
+ expect(page).to have_content("Next")
+ expect(page).to have_link("Next")
+ end
+
+ it "shows which schemes are being shown on the current page" do
+ expect(CGI.unescape_html(response.body)).to match("Showing 1 to 20 of #{total_schemes_count} schemes")
+ end
+
+ it "has correct page 1 of 2 title" do
+ expect(page).to have_title("Supported housing services (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
+ end
+
+ 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
+
+ end
+
+ context "when on the second page" do
+ before do
+ get "/supported-housing?page=2"
+ end
+ it "shows the total schemes count" do
+ expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes.")
+ 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 schemes are being shown on the current page" do
+ expect(CGI.unescape_html(response.body)).to match("Showing 21 to 25 of #{total_schemes_count} schemes")
+ end
+
+ it "has correct page 1 of 2 title" do
+ expect(page).to have_title("Supported housing services (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
+ end
+ end
+ end
end
context "when signed in as a data coordinator user" do