discourse/spec/system/composer_spec.rb
Gabriel Grubba 181606e0bd
FIX: Prioritize the author when replying to topic (#32244)
Added in https://github.com/discourse/discourse/pull/32086 this
prioritization did not accounted for when the user was replying to the
topic/OP.

Now when replying to the topic, the author will be prioritized in the
list.

All other cases are the same as before.

Added testing for all cases and changed `replyingToUser` to
`replyingToUserId` for clarity and consistency with API.

---------

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
2025-04-10 09:02:32 -03:00

75 lines
2.3 KiB
Ruby

# frozen_string_literal: true
describe "Composer", type: :system do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
let(:composer) { PageObjects::Components::Composer.new }
before { sign_in(user) }
it "displays user cards in preview" do
page.visit "/new-topic"
expect(composer).to be_opened
composer.fill_content("@#{user.username}")
composer.preview.find("a.mention").click
page.has_css?("#user-card")
end
context "in a topic, the autocomplete prioritizes" do
fab!(:topic_user) { Fabricate(:user) }
fab!(:second_reply_user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: topic_user) }
fab!(:op) { Fabricate(:post, topic: topic, user: topic_user) }
let!(:op_post) { PageObjects::Components::Post.new(op.post_number) }
fab!(:second_reply) { Fabricate(:post, topic: topic, user: second_reply_user) }
let!(:second_reply_post) { PageObjects::Components::Post.new(second_reply.post_number) }
it "the topic owner if replying to topic" do
page.visit "/t/#{topic.id}"
op_post.reply
expect(composer).to be_opened
composer.fill_content("@")
expect(composer.mention_menu_autocomplete_username_list).to eq(
[op.username, second_reply_user.username], # must be first the topic owner
)
end
it "the recipient of the reply when replying" do
page.visit "/t/#{topic.id}"
second_reply_post.reply
expect(composer).to be_opened
composer.fill_content("@")
expect(composer.mention_menu_autocomplete_username_list).to eq(
[second_reply_user.username, topic_user.username], # must be first the reply user
)
end
it "the recipient of the reply when editing a reply" do
admin = Fabricate(:admin, refresh_auto_groups: true)
reply_to_second_post =
Fabricate(:post, topic: topic, user: user, reply_to_post_number: second_reply.post_number)
reply_post = PageObjects::Components::Post.new(reply_to_second_post.post_number)
sign_in(admin)
page.visit "/t/#{topic.id}"
reply_post.edit
expect(composer).to be_opened
composer.fill_content("@")
expect(composer.mention_menu_autocomplete_username_list).to eq(
[second_reply_user.username, user.username, topic_user.username],
)
end
end
end