8 changed files with 56 additions and 24 deletions
@ -0,0 +1,16 @@ |
|||||||
|
<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %> |
||||||
|
<div class="app-search govuk-!-margin-bottom-4"> |
||||||
|
<div class="govuk-form-group app-search__form-group"> |
||||||
|
<label class="govuk-label govuk-!-margin-bottom-2" for="search-field"> |
||||||
|
<%= label %> |
||||||
|
</label> |
||||||
|
|
||||||
|
<input class="govuk-input app-search__input" id="search-field" name="search-field" type="search" autocomplete="off"> |
||||||
|
</div> |
||||||
|
|
||||||
|
<button class="govuk-button app-search__button undefined" data-module="govuk-button"> |
||||||
|
Search |
||||||
|
</button> |
||||||
|
|
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,13 @@ |
|||||||
|
class SearchComponent < ViewComponent::Base |
||||||
|
attr_reader :current_user, :label |
||||||
|
|
||||||
|
def initialize(current_user:, label:) |
||||||
|
@current_user = current_user |
||||||
|
@label = label |
||||||
|
super |
||||||
|
end |
||||||
|
|
||||||
|
def path(current_user) |
||||||
|
current_user.support? ? users_path : users_organisation_path(current_user.organisation) |
||||||
|
end |
||||||
|
end |
@ -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 |
Loading…
Reference in new issue