mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 22:44:43 +08:00
9bdd97db42
BEFORE: if you click the "reply" button on a post and then decided that you want to "edit" the same post, clicking the "edit" button would do nothing. Clicking "edit" on another post works, but editing the same post would appear broken.
AFTER: if you click the "edit" button, it will properly load the content of the post you're trying to edit. No matter which one it is.
This was somewhat tricky to track down as the system specs seemed to contradict the qunit tests until I realized that the qunit tests were only testing the edit on the 1st post and the system specs were testing on replies.
I improved the qunit tests to test both editing OP and a reply and (hopefully) made the system specs a little bit clearer.
This is a follow up to bbe62d88d2
.
122 lines
3.5 KiB
Ruby
122 lines
3.5 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
describe "Composer - discard draft modal", type: :system do
|
||
fab!(:topic)
|
||
fab!(:admin)
|
||
|
||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||
let(:composer) { PageObjects::Components::Composer.new }
|
||
let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
|
||
|
||
before { sign_in(admin) }
|
||
|
||
context "when editing different post" do
|
||
fab!(:post_1) { Fabricate(:post, topic:, user: admin) }
|
||
fab!(:post_2) { Fabricate(:post, topic:, user: admin) }
|
||
|
||
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: admin) }
|
||
|
||
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
|
||
|
||
context "when clicking abandon draft" do
|
||
let(:dialog) { PageObjects::Components::Dialog.new }
|
||
|
||
before { Jobs.run_immediately! }
|
||
|
||
it "destroys draft" do
|
||
visit "/new-topic"
|
||
|
||
composer.fill_content("a b c d e f g")
|
||
composer.close
|
||
|
||
expect(discard_draft_modal).to be_open
|
||
discard_draft_modal.click_save
|
||
|
||
wait_for(timeout: 5) { Draft.last != nil }
|
||
draft_key = Draft.last.draft_key
|
||
|
||
visit "/new-topic"
|
||
|
||
expect(dialog).to be_open
|
||
expect(page).to have_content(I18n.t("js.drafts.abandon.confirm"))
|
||
dialog.click_danger
|
||
|
||
wait_for(timeout: 5) { Draft.find_by(draft_key: draft_key) == nil }
|
||
end
|
||
|
||
it "resumes draft when using /new-message" do
|
||
visit "/new-message"
|
||
|
||
composer.fill_content("a b c d e f g")
|
||
composer.close
|
||
|
||
expect(discard_draft_modal).to be_open
|
||
discard_draft_modal.click_save
|
||
|
||
visit "/new-message"
|
||
|
||
expect(dialog).to be_open
|
||
expect(page).to have_content(I18n.t("js.drafts.abandon.confirm"))
|
||
dialog.click_button I18n.t("js.drafts.abandon.no_value")
|
||
|
||
expect(composer).to be_opened
|
||
expect(composer).to have_content("a b c d e f g")
|
||
end
|
||
end
|
||
end
|