discourse/spec/system/user_selector_spec.rb
2025-06-28 17:13:46 +08:00

73 lines
2.3 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "User selector", type: :system do
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:current_user) { Fabricate(:admin) }
fab!(:user) { with_search_indexer_enabled { Fabricate(:user, username: "someone") } }
before do
current_user.activate
sign_in(current_user)
end
context "with modern autocomplete enabled" do
before { SiteSetting.use_modern_autocomplete = true }
context "when autocompleting a username" do
it "correctly shows the user" do
visit("/t/-/#{topic.id}")
find(".btn-primary.create").click
find(".d-editor-input").send_keys("Hello @som")
within(".autocomplete.ac-user") do |el|
expect(el).to have_selector(".selected .avatar[title=someone]")
expect(el.find(".selected .username")).to have_content("someone")
end
end
end
context "when autocompleting a group" do
it "correctly shows the user" do
visit("/t/-/#{topic.id}")
find(".btn-primary.create").click
find(".d-editor-input").send_keys("Hello @adm")
within(".autocomplete.ac-user") do |el|
expect(el).to have_selector(".selected .d-icon-users")
expect(el.find(".selected .username")).to have_content("admins")
end
end
end
end
context "with legacy autocomplete enabled" do
before { SiteSetting.use_modern_autocomplete = false }
context "when autocompleting a username" do
it "correctly shows the user" do
visit("/t/-/#{topic.id}")
find(".btn-primary.create").click
find(".d-editor-input").send_keys("Hello @som")
within(".autocomplete.ac-user") do |el|
expect(el).to have_selector(".selected .avatar[title=someone]")
expect(el.find(".selected .username")).to have_content("someone")
end
end
end
context "when autocompleting a group" do
it "correctly shows the user" do
visit("/t/-/#{topic.id}")
find(".btn-primary.create").click
find(".d-editor-input").send_keys("Hello @adm")
within(".autocomplete.ac-user") do |el|
expect(el).to have_selector(".selected .d-icon-users")
expect(el.find(".selected .username")).to have_content("admins")
end
end
end
end
end