From 0647a298faa65735087d29b1746bbce283208f5a Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Thu, 19 Sep 2024 14:03:04 +0100 Subject: [PATCH] Make organisation field searchable 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 --- app/views/devise/invitations/new.html.erb | 23 ++++++++++++----- test/integration/inviting_users_test.rb | 31 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/views/devise/invitations/new.html.erb b/app/views/devise/invitations/new.html.erb index 56ea38eec..715fb8000 100644 --- a/app/views/devise/invitations/new.html.erb +++ b/app/views/devise/invitations/new.html.erb @@ -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) - } %> +
+ <%= 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) + } %> + +
+ <%= render "govuk_publishing_components/components/button", { + text: "Clear selection", + type: "button", + classes: "js-autocomplete__clear-button", + secondary_solid: true + } %> +
+
<% if policy(User).assign_role? %> <%= render "govuk_publishing_components/components/select", { diff --git a/test/integration/inviting_users_test.rb b/test/integration/inviting_users_test.rb index 0ad9dc12a..f137b469e 100644 --- a/test/integration/inviting_users_test.rb +++ b/test/integration/inviting_users_test.rb @@ -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