0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/spec/system/create_invite_with_roles_spec.rb
Kris 665494fc53
DEV: simplify and use reuable components in invite modal, fix bug, (#42273)
We were creating some new conventions here instead of relying on
existing components. This gets the invite modal on more shared
components, reduces the custom css, and fixes the bug reported here:
https://meta.discourse.org/t/invite-restricted-cant-remove/409058

reusing existing components
- segment control 
- formkit conditional section
- advanced mode toggle  


Removed some redundant text: 
"invite people to join this site" — what else would you be inviting
people to?
"share a link or send an email invitation" – that's what the radio
options already indicate
"to invite a specific person, use email above" – that's implied by
"email"

before
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/1cdb474c-e393-4066-854f-3b6d714b0195"
/>

after
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/506229b7-88fe-437f-8a2d-db3618814c48"
/>


I've also triggered the success button on the copy button on the second
step, as an indication that the link has been copied successfully.

<img width="600" alt="image"
src="https://github.com/user-attachments/assets/52c9ef8d-94ea-4b11-923d-9e5745a7e53e"
/>


Changed the order here so the descriptions are associated with the
selection and below them (rather than being above them, which is awkward
for reading order)

Removed "invite people to join your staff team" which was redundant, the
roles describe what kind of access you're inviting — also elaborated a
little to make the full admin scope more apparent

before
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/9f4684ec-b2d0-43d6-92b7-23dd27156f77"
/>


after
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/b7af2317-21c4-4b0c-809a-c4ac13c218e3"
/>


Mobile also fits slightly better on the tiniest screens at 320px wide 

before
<img width="320" alt="image"
src="https://github.com/user-attachments/assets/11e61205-f3a6-4f68-a8ea-0c1ef75b9aa1"
/>

after
<img width="320" alt="image"
src="https://github.com/user-attachments/assets/b2caef7d-5562-452f-8d51-6c9af779a809"
/>
2026-08-03 15:31:55 -04:00

191 lines
6.1 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Creating invites with roles" do
include ThemeScreenshotMarker
fab!(:admin)
fab!(:group)
fab!(:user) { Fabricate(:user, groups: [group]) }
let(:user_invited_pending_page) { PageObjects::Pages::UserInvitedPending.new }
let(:modal) { PageObjects::Modals::CreateInviteWithRoles.new }
let(:invite_form) { PageObjects::Pages::InviteForm.new }
let(:cdp) { PageObjects::CDP.new }
before { SiteSetting.enable_invite_modal_with_roles = true }
def open_invite_modal_for(current_user)
user_invited_pending_page.visit(current_user)
find(".user-invite-buttons .btn", match: :first).click
end
context "when signed in as an admin" do
fab!(:placeholder_invite) do
Fabricate(:invite, invited_by: admin, email: "placeholder@example.com")
end
before { sign_in(admin) }
it "can create an admin invite and redeem it end to end" do
open_invite_modal_for(admin)
expect(modal).to be_open
expect(modal).to have_role_toggle
expect(modal.selected_role).to eq("member")
modal.select_role("admin")
screenshot_marker(label: "invite-admins", only: :desktop)
modal.toggle_advanced_options
screenshot_marker(label: "invite-admins-advanced", only: :desktop)
modal.toggle_advanced_options
modal.form.field("email").fill_in("future-admin@example.com")
modal.save_button.click
expect(modal).to have_sent_to_message("future-admin@example.com")
expect(modal).to have_summary
screenshot_marker(label: "invite-admin-sent", only: :desktop)
invite = Invite.last
expect(invite.admin).to eq(true)
expect(invite.email).to eq("future-admin@example.com")
expect(invite.max_redemptions_allowed).to eq(1)
expect(modal.invite_link_input.value).to eq(invite.link)
modal.close
Capybara.reset_sessions!
invite_form.open(invite.invite_key)
invite_form.fill_username("futureadmin")
invite_form.fill_password("supersecurepassword")
expect(invite_form).to have_valid_fields
invite_form.click_create_account
expect(invite_form).to have_successful_message
invited_user = User.find_by_username("futureadmin")
expect(invited_user.moderator).to eq(true)
expect(invited_user.admin).to eq(false)
expect(AdminConfirmation.exists_for?(invited_user.id)).to eq(true)
token = Discourse.redis.get("admin-confirmation:#{invited_user.id}")
AdminConfirmation.find_by_code(token).email_confirmed!
expect(invited_user.reload.admin).to eq(true)
end
it "marks the invite step complete via the create-invite:saved event when inviting an admin" do
SiteSetting.enable_site_owner_onboarding = true
banner = PageObjects::Components::AdminOnboardingBanner.new
visit("/")
expect(banner.step_not_completed?("invite_collaborators")).to eq(true)
screenshot_marker(label: "invite-onboarding-banner", only: :desktop)
banner.click_step_action("invite_collaborators")
expect(modal).to be_open
expect(modal.selected_role).to eq("admin")
modal.form.field("email").fill_in("collaborator@example.com")
modal.save_button.click
expect(modal).to have_summary
modal.close
expect(banner.step_completed?("invite_collaborators")).to eq(true)
end
it "can create a member link invite with a domain restriction" do
cdp.allow_clipboard
open_invite_modal_for(admin)
expect(modal.selected_role).to eq("member")
screenshot_marker(label: "invite-members", only: :desktop)
modal.toggle_advanced_options
screenshot_marker(label: "invite-members-advanced", only: :desktop)
modal.toggle_advanced_options
modal.form.field("domain").fill_in("example.com")
modal.save_button.click
expect(modal).to have_summary
cdp.clipboard_has_text?(Invite.last.link)
expect(page).to have_css(".copy-button.ok")
screenshot_marker(label: "invite-created", only: :desktop)
invite = Invite.last
expect(invite.admin).to eq(false)
expect(invite.domain).to eq("example.com")
cdp.clipboard_has_text?(invite.link)
end
it "can create a member email invite" do
open_invite_modal_for(admin)
modal.select_delivery("email")
modal.form.field("email").fill_in("new-member@example.com")
screenshot_marker(label: "invite-members-email", only: :desktop)
modal.save_button.click
expect(modal).to have_email_sent_confirmation("new-member@example.com")
screenshot_marker(label: "invite-email-sent", only: :desktop)
invite = Invite.last
expect(invite.admin).to eq(false)
expect(invite.email).to eq("new-member@example.com")
end
it "locks the role when editing an invite from the summary" do
open_invite_modal_for(admin)
modal.select_role("admin")
modal.form.field("email").fill_in("future-admin@example.com")
modal.save_button.click
expect(modal).to have_summary
modal.edit_button.click
expect(modal).to have_no_role_toggle
expect(modal.save_button).to have_text(I18n.t("js.user.invited.invite_roles.update"))
modal.cancel_button.click
expect(modal).to have_summary
end
end
context "when signed in as a regular user who can invite" do
fab!(:placeholder_invite) do
Fabricate(:invite, invited_by: user, email: "placeholder@example.com")
end
before do
SiteSetting.invite_allowed_groups = group.id.to_s
sign_in(user)
end
it "does not offer the admins option" do
open_invite_modal_for(user)
expect(modal).to be_open
expect(modal).to have_no_role_toggle
end
end
context "when enable_invite_modal_with_roles is disabled" do
fab!(:placeholder_invite) do
Fabricate(:invite, invited_by: admin, email: "placeholder@example.com")
end
before do
SiteSetting.enable_invite_modal_with_roles = false
sign_in(admin)
end
it "shows the previous invite modal" do
open_invite_modal_for(admin)
expect(page).to have_css(".create-invite-modal")
expect(page).to have_no_css(".create-invite-with-roles-modal")
end
end
end