mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-18 22:05:43 +08:00
When creating a new topic in a category that requires approval, the composer would show a "discard draft" modal on every subsequent attempt to open it (new topic or reply). The issue was in the post-enqueue handler in the composer service. After a post is enqueued, the code tries to push the pending post into `this.topicController.model.pending_posts`. When creating a new topic, the user is on the topic list — not viewing a topic — so `this.topicController.model` is undefined. Accessing `.pending_posts` on undefined throws a TypeError, which prevents `destroyDraft()` and `close()` from ever executing. The composer model stays on the service with dirty content, so any subsequent composer open triggers the discard draft modal. The fix adds optional chaining (`?.`) so the pending_posts push is safely skipped when no topic model is loaded. https://meta.discourse.org/t/397711
38 lines
1.3 KiB
Ruby
Vendored
38 lines
1.3 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe "Composer draft after enqueued post" do
|
|
fab!(:current_user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
context "when creating a new topic that requires approval" do
|
|
fab!(:category) { Fabricate(:category).tap { |c| c.update!(require_topic_approval: true) } }
|
|
|
|
it "clears the draft and does not show the discard draft modal when reopening the composer" do
|
|
visit "/latest"
|
|
find("#create-topic").click
|
|
expect(composer).to be_opened
|
|
|
|
composer.fill_title("This is a test topic requiring approval")
|
|
composer.fill_content("This is the body of a test topic that requires admin approval")
|
|
composer.switch_category(category.name)
|
|
|
|
composer.create
|
|
|
|
expect(page).to have_css(".post-enqueued-modal")
|
|
find(".post-enqueued-modal .btn-primary").click
|
|
expect(page).to have_no_css(".post-enqueued-modal")
|
|
expect(composer).to be_closed
|
|
|
|
try_until_success { expect(Draft.where(user: current_user).count).to eq(0) }
|
|
|
|
find("#create-topic").click
|
|
|
|
expect(discard_draft_modal).to be_closed
|
|
expect(composer).to be_opened
|
|
end
|
|
end
|
|
end
|