Skip to content

Commit

Permalink
Make organisation field searchable
Browse files Browse the repository at this point in the history
This upgrades the organisations field in the page for inviting a new
user to use the accessible autocomplete module (with progressive
enhancement)
  • Loading branch information
yndajas committed Sep 19, 2024
1 parent 12b0b93 commit 067f91c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/views/devise/invitations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@
autocomplete: "off",
} %>

<%= render "govuk_publishing_components/components/select", {
id: "user_organisation_id",
name: "user[organisation_id]",
label: "Organisation",
options: options_for_organisation_select(selected: f.object.organisation_id)
} %>
<div data-module="accessible-autocomplete">
<%= render "govuk_publishing_components/components/select", {
id: "user_organisation_id",
name: "user[organisation_id]",
label: "Organisation",
options: options_for_organisation_select(selected: f.object.organisation_id)
} %>

<div class="govuk-button-group">
<%= render "govuk_publishing_components/components/button", {
text: "Clear selection",
type: "button",
classes: "js-autocomplete__clear-button",
secondary_solid: true
} %>
</div>
</div>

<% if policy(User).assign_role? %>
<%= render "govuk_publishing_components/components/select", {
Expand Down
40 changes: 40 additions & 0 deletions test/integration/inviting_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,44 @@ class InvitingUsersTest < ActionDispatch::IntegrationTest
end
end
end

context "with JavaScript enabled" do
setup do
use_javascript_driver

create(:organisation, name: "ABCDEF")
create(:organisation, name: "GHIJKL")
@organisation = create(:organisation, name: "MNOPQR")
create(:organisation, name: "STUVWX")
create(:organisation, name: "YZ1234")

superadmin = create(:superadmin_user)
visit root_path
signin_with(superadmin)
end

should "be able to invite a user" do
visit new_user_invitation_path
fill_in "Name", with: "H from Steps"
fill_in "Email", with: "h@from.steps"
select "Superadmin", from: "Role"

autocomplete_input_element = find(".autocomplete__input")
select_element = find("#user_organisation_id-select", visible: false)

assert_select_with_autocomplete(
autocomplete_input_element:,
select_element:,
option_text: @organisation.name,
option_value: @organisation.id.to_s,
unique_partial_string: "MNO",
)

click_button "Create user and send email"

new_user = User.find_by(email: "h@from.steps", role: Roles::Superadmin.name)
assert_not_nil new_user
assert_equal new_user.organisation, @organisation
end
end
end

0 comments on commit 067f91c

Please sign in to comment.