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)

Co-authored-by: George Eaton <george@dxw.com>
  • Loading branch information
yndajas and Gweaton committed Sep 26, 2024
1 parent d37a163 commit 0647a29
Show file tree
Hide file tree
Showing 2 changed files with 48 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
31 changes: 31 additions & 0 deletions test/integration/inviting_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,35 @@ 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"

AutocompleteHelper.new.select_autocomplete_option(@organisation.name)

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 0647a29

Please sign in to comment.