mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-09 01:35:44 +08:00
This change simplifies controls of confirmation dialog when post is discarded in composer: * `Discard` button stays unchanged * `Save draft for later` button is removed * `Keep editing` button is renamed to `Cancel` (functionality is unchanged) * changes modal copy from `What would you like to do with your post?` to `Do you want to discard your post?` |Before|After| |---|---| |<img width="614" height="138" alt="Screenshot 2025-10-10 at 13 18 06" src="https://github.com/user-attachments/assets/76be21fa-c9d9-4c1d-9cb2-079d87d0e913" />|<img width="618" height="142" alt="Screenshot 2025-10-10 at 13 09 40" src="https://github.com/user-attachments/assets/b106a6f0-e420-4351-8785-cb69ee587a49" />| NOTE: do not mind the design on screenshots (dark/light mode). They showcase change in controls. This PR doesn't change UI.
176 lines
5.2 KiB
Ruby
176 lines
5.2 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
describe "Composer - Drafts", type: :system do
|
||
fab!(:topic)
|
||
fab!(:current_user, :admin)
|
||
|
||
let(:toasts) { PageObjects::Components::Toasts.new }
|
||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||
let(:composer) { PageObjects::Components::Composer.new }
|
||
let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
|
||
|
||
before { sign_in(current_user) }
|
||
|
||
context "when clicking X (save and close)" do
|
||
it "saves the draft and shows a toast" do
|
||
visit "/new-topic"
|
||
|
||
expect(composer).to be_opened
|
||
composer.fill_title("this is a test topic")
|
||
composer.fill_content("a b c d e f g")
|
||
composer.close
|
||
|
||
expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))
|
||
expect(Draft.where(user: current_user).count).to eq(1)
|
||
end
|
||
|
||
context "when only a title and category is specified" do
|
||
fab!(:category_1, :category)
|
||
fab!(:category_2, :category)
|
||
|
||
it "saves the draft and shows a toast" do
|
||
visit "/new-topic"
|
||
|
||
expect(composer).to be_opened
|
||
composer.fill_title("this is a test topic")
|
||
composer.switch_category(category_1.name)
|
||
composer.close
|
||
|
||
expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))
|
||
expect(Draft.where(user: current_user).count).to eq(1)
|
||
end
|
||
end
|
||
|
||
context "when only title is specified and it is too short" do
|
||
it "does not save the draft or show a toast" do
|
||
visit "/new-topic"
|
||
|
||
expect(composer).to be_opened
|
||
composer.fill_title("test")
|
||
composer.close
|
||
expect(composer).to be_closed
|
||
|
||
expect(toasts).to have_no_message
|
||
expect(Draft.where(user: current_user).count).to eq(0)
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when clicking discard" do
|
||
let(:dialog) { PageObjects::Components::Dialog.new }
|
||
|
||
before { Jobs.run_immediately! }
|
||
|
||
it "does not show confirmation if there is no user input in the composer" do
|
||
visit "/new-topic"
|
||
|
||
expect(composer).to be_opened
|
||
composer.discard
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_closed
|
||
end
|
||
|
||
it "destroys draft after discard confirmation" do
|
||
visit "/new-topic"
|
||
|
||
composer.fill_title("this is a test topic")
|
||
composer.fill_content("a b c d e f g")
|
||
|
||
try_until_success(reason: "Relies on an Ember debounce to update the draft") do
|
||
expect(Draft.where(user: current_user).count).to eq(1)
|
||
end
|
||
|
||
composer.discard
|
||
|
||
expect(discard_draft_modal).to be_open
|
||
discard_draft_modal.click_discard
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_closed
|
||
expect(Draft.where(user: current_user).count).to eq(0)
|
||
end
|
||
|
||
context "when only a title and category is specified" do
|
||
fab!(:category_1, :category)
|
||
fab!(:category_2, :category)
|
||
|
||
it "shows Discard draft confirmation modal and hides it on Cancel button click" do
|
||
visit "/new-topic"
|
||
|
||
expect(composer).to be_opened
|
||
composer.fill_title("this is a test topic")
|
||
composer.switch_category(category_1.name)
|
||
composer.discard
|
||
|
||
expect(discard_draft_modal).to be_open
|
||
discard_draft_modal.click_cancel
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when editing different post" do
|
||
fab!(:post_1) { Fabricate(:post, topic:, user: current_user) }
|
||
fab!(:post_2) { Fabricate(:post, topic:, user: current_user) }
|
||
|
||
it "shows the discard modal when there are changes in the composer" do
|
||
topic_page.visit_topic(post_1.topic)
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
composer.fill_content("a b c d e f g")
|
||
composer.minimize
|
||
|
||
topic_page.click_post_action_button(post_2, :edit)
|
||
|
||
expect(discard_draft_modal).to be_open
|
||
end
|
||
|
||
it "doesn't show the discard modal when there are no changes in the composer" do
|
||
topic_page.visit_topic(post_1.topic)
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
composer.minimize
|
||
|
||
topic_page.click_post_action_button(post_2, :edit)
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_opened
|
||
end
|
||
end
|
||
|
||
context "when editing the same post" do
|
||
fab!(:post_1) { Fabricate(:post, topic:, user: current_user) }
|
||
|
||
it "doesn’t show the discard modal even if there are changes in the composer" do
|
||
topic_page.visit_topic(post_1.topic)
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
composer.fill_content("a b c d e f g")
|
||
composer.minimize
|
||
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_opened
|
||
expect(composer).to have_content("a b c d e f g")
|
||
|
||
composer.minimize
|
||
expect(composer).to be_minimized
|
||
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_opened
|
||
end
|
||
|
||
it "doesn’t show the discard modal when there are no changes in the composer" do
|
||
topic_page.visit_topic(post_1.topic)
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
composer.minimize
|
||
|
||
topic_page.click_post_action_button(post_1, :edit)
|
||
|
||
expect(discard_draft_modal).to be_closed
|
||
expect(composer).to be_opened
|
||
end
|
||
end
|
||
end
|