diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index d65d5930a..20b6c7beb 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -1,5 +1,5 @@ <% item_label = format_label(@pagy.count, "location") %> -<% title = @scheme.service_name %> +<% title = format_title(@searched, @scheme.service_name, current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> <% content_for :before_content do %> diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 3e099e32d..ea9018c0c 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -864,6 +864,30 @@ RSpec.describe LocationsController, type: :request do end end end + + context "when searching" do + let(:searched_location) { locations.first } + let(:search_param) { searched_location.name } + + before do + get "/schemes/#{scheme.id}/locations?search=#{search_param}" + end + + it "returns matching results" do + expect(page).to have_content(searched_location.name) + locations[1..].each do |location| + expect(page).not_to have_content(location.name) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 location found matching ‘#{search_param}’") + end + + it "has search in the title" do + expect(page).to have_title("#{scheme.service_name} (1 location matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end + end end context "when signed in as a support user" do @@ -942,6 +966,30 @@ RSpec.describe LocationsController, type: :request do end end end + + context "when searching" do + let(:searched_location) { locations.first } + let(:search_param) { searched_location.name } + + before do + get "/schemes/#{scheme.id}/locations?search=#{search_param}" + end + + it "returns matching results" do + expect(page).to have_content(searched_location.name) + locations[1..].each do |location| + expect(page).not_to have_content(location.name) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 location found matching ‘#{search_param}’") + end + + it "has search in the title" do + expect(page).to have_title("#{scheme.service_name} (1 location matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end + end end end