-<% end %>
+<%= render SearchComponent.new(current_user:, label: "Search by name or email address") %>
<%= govuk_table do |table| %>
<%= table.caption(size: "s", classes: %w[govuk-!-text-align-left govuk-!-margin-top-4 govuk-!-margin-bottom-4]) do |caption| %>
diff --git a/spec/components/search_component_spec.rb b/spec/components/search_component_spec.rb
new file mode 100644
index 000000000..237ff05d6
--- /dev/null
+++ b/spec/components/search_component_spec.rb
@@ -0,0 +1,19 @@
+require "rails_helper"
+
+RSpec.describe SearchComponent, type: :component do
+ let(:current_user) { FactoryBot.create(:user, :support) }
+ let(:label) { "Search by name or email address" }
+ let(:page) { Capybara::Node::Simple.new(rendered_component) }
+
+ before do
+ render_inline(described_class.new(current_user:, label:))
+ end
+
+ it "renders a search bar" do
+ expect(page).to have_field("search-field", type: "search")
+ end
+
+ it "renders the given label" do
+ expect(page).to have_content(label)
+ end
+end
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 31448b102..beb81a993 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -359,7 +359,7 @@ RSpec.describe UsersController, type: :request do
it "shows a search bar" do
follow_redirect!
- expect(page).to have_field("user-search-field", type: "search")
+ expect(page).to have_field("search-field", type: "search")
end
end
@@ -369,7 +369,7 @@ RSpec.describe UsersController, type: :request do
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@other_example.com") }
before do
- get "/organisations/#{user.organisation.id}/users?user-search-field=#{search_param}"
+ get "/organisations/#{user.organisation.id}/users?search-field=#{search_param}"
end
context "when our search string matches case" do
@@ -822,12 +822,12 @@ RSpec.describe UsersController, type: :request do
end
it "shows a search bar" do
- expect(page).to have_field("user-search-field", type: "search")
+ expect(page).to have_field("search-field", type: "search")
end
context "when a search parameter is passed" do
before do
- get "/users?user-search-field=#{search_param}"
+ get "/users?search-field=#{search_param}"
end
context "when our search term matches a name" do