discourse/spec/system/private_message_spec.rb
Yuriy Kurant 0c7ac4cd8f
UX: improve logic for new topic and new PM composer actions (#35834)
A follow-up to #35764.

This change enhances the logic when **New topic** option should be
shown/hidden in composer actions:

1. After user switches to **Personal message** mode, we allow to switch
back to **New topic** mode:
<img width="265" height="153" alt="Screenshot 2025-11-05 at 22 17 16"
src="https://github.com/user-attachments/assets/5dedf69d-8e0c-4b28-abb5-1be4d5662a81"
/>

and

<img width="332" height="177" alt="Screenshot 2025-11-05 at 22 22 05"
src="https://github.com/user-attachments/assets/5e17c82d-10fb-4407-b9f8-ced78a85fdd5"
/>

2. In **New topic** mode there is no need to render **New topic**
option:

|Before|After|
|---|---|
|<img width="345" height="233" alt="Screenshot 2025-11-05 at 18 57 20"
src="https://github.com/user-attachments/assets/eef3d4da-b58e-4a11-90df-f76774630fad"
/>|<img width="453" height="197" alt="Screenshot 2025-11-05 at 22 19 37"
src="https://github.com/user-attachments/assets/816b1199-01a7-4022-8695-61cc9edc2473"
/>|
2025-11-06 10:13:00 +08:00

65 lines
2.2 KiB
Ruby

# frozen_string_literal: true
describe "Private Message", type: :system do
let(:sender) { Fabricate(:user, refresh_auto_groups: true) }
let(:recipient) { Fabricate(:user) }
let(:pm_post) { Fabricate(:private_message_post, user: sender, recipient: recipient) }
let(:pm_post_obj) { PageObjects::Components::Post.new(pm_post.post_number) }
let(:composer) { PageObjects::Components::Composer.new }
context "when being removed from private conversation" do
before { sign_in(recipient) }
it "redirects away from the private message" do
visit(pm_post.full_url)
expect(page).to have_css("h1", text: pm_post.topic.title)
pm_post.topic.remove_allowed_user(sender, recipient)
expect(page).to have_current_path("/u/#{recipient.username}/messages")
expect(page).to have_no_css("h1", text: pm_post.topic.title)
end
end
context "for 'new personal message' action option in composer" do
before { sign_in(sender) }
it "should be available in new topic" do
visit "/new-topic"
expect(composer).to be_opened
composer.open_composer_actions
composer.select_action(I18n.t("js.composer.composer_actions.create_personal_message.label"))
expect(composer.button_label).to have_text(I18n.t("js.composer.create_pm"))
end
it "should not be available in private conversation reply" do
visit(pm_post.full_url)
pm_post_obj.reply
expect(composer).to be_opened
composer.open_composer_actions
expect(composer).to have_no_action(
I18n.t("js.composer.composer_actions.create_personal_message.label"),
)
end
it "can switch between topic and personal message modes" do
visit "/new-topic"
expect(composer).to be_opened
# Switch to personal message
composer.open_composer_actions
composer.select_action(I18n.t("js.composer.composer_actions.create_personal_message.label"))
expect(composer.button_label).to have_text(I18n.t("js.composer.create_pm"))
# Switch back to topic
composer.open_composer_actions
composer.select_action(I18n.t("js.composer.composer_actions.create_topic.label"))
expect(composer.button_label).to have_text(I18n.t("js.composer.create_topic"))
end
end
end