Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/javascript/controllers/double_select_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class extends Controller {
const val = $(this.sourceTarget).val()
const url = new URL(this.urlValue)
url.searchParams.append('resource_type', val);
$(this.destinationTarget).empty().val(null).trigger('change');
$(this.destinationTarget).select2({
ajax: {
url: url.toString(),
Expand Down
18 changes: 18 additions & 0 deletions spec/system/admin/users_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
expect(page.find(".error")).to have_content "Failed to create user: Please select an associated resource for the role."
end

it "clears the resource when the role type changes" do
create(:partner, name: "Partner ABC", organization: organization)

visit new_admin_user_path
find('select#resource_type option', exact_text: "Organization").select_option
find("label", text: "Resource").sibling(".input-group").click
find('li[role="option"]', text: organization.name).click
find('select#resource_type option', text: "Partner").select_option
fill_in "user_name", with: "TestUser"
fill_in "user_email", with: "testuser@example.com"
click_on "Save"

expect(page.find(".error")).to have_content(
"Failed to create user: Please select an associated resource for the role."
)
expect(User.find_by(email: "testuser@example.com")).to be_nil
end

it "hides the resource dropdown if super admin role is selected" do
visit new_admin_user_path
expect(page).to have_content("Resource")
Expand Down