2024-04-16 16:34:32 +08:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
describe "Composer - discard draft modal", type: :system do
|
2024-12-02 23:06:36 +08:00
|
|
|
|
fab!(:topic)
|
|
|
|
|
fab!(:admin)
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
|
|
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
2024-12-02 23:06:36 +08:00
|
|
|
|
let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
before { sign_in(admin) }
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
|
|
|
|
context "when editing different post" do
|
2024-12-02 23:06:36 +08:00
|
|
|
|
fab!(:post_1) { Fabricate(:post, topic:, user: admin) }
|
|
|
|
|
fab!(:post_2) { Fabricate(:post, topic:, user: admin) }
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
it "shows the discard modal when there are changes in the composer" do
|
2024-04-16 16:34:32 +08:00
|
|
|
|
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
|
2024-12-02 23:06:36 +08:00
|
|
|
|
|
2024-04-16 16:34:32 +08:00
|
|
|
|
topic_page.click_post_action_button(post_2, :edit)
|
|
|
|
|
|
|
|
|
|
expect(discard_draft_modal).to be_open
|
|
|
|
|
end
|
2024-12-02 23:06:36 +08:00
|
|
|
|
|
|
|
|
|
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
|
2024-04-16 16:34:32 +08:00
|
|
|
|
end
|
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
context "when editing the same post" do
|
|
|
|
|
fab!(:post_1) { Fabricate(:post, topic:, user: admin) }
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
it "doesn’t show the discard modal even if there are changes in the composer" do
|
2024-04-16 16:34:32 +08:00
|
|
|
|
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
|
2024-12-02 23:06:36 +08:00
|
|
|
|
|
2024-04-16 16:34:32 +08:00
|
|
|
|
topic_page.click_post_action_button(post_1, :edit)
|
|
|
|
|
|
|
|
|
|
expect(discard_draft_modal).to be_closed
|
|
|
|
|
expect(composer).to be_opened
|
2024-12-02 23:06:36 +08:00
|
|
|
|
expect(composer).to have_content("a b c d e f g")
|
|
|
|
|
|
|
|
|
|
composer.minimize
|
|
|
|
|
expect(composer).to be_minimized
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
|
|
|
|
topic_page.click_post_action_button(post_1, :edit)
|
|
|
|
|
|
|
|
|
|
expect(discard_draft_modal).to be_closed
|
|
|
|
|
expect(composer).to be_opened
|
|
|
|
|
end
|
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
it "doesn’t show the discard modal when there are no changes in the composer" do
|
2024-04-16 16:34:32 +08:00
|
|
|
|
topic_page.visit_topic(post_1.topic)
|
2024-12-02 23:06:36 +08:00
|
|
|
|
topic_page.click_post_action_button(post_1, :edit)
|
2024-04-16 16:34:32 +08:00
|
|
|
|
composer.minimize
|
|
|
|
|
|
2024-12-02 23:06:36 +08:00
|
|
|
|
topic_page.click_post_action_button(post_1, :edit)
|
2024-04-16 16:34:32 +08:00
|
|
|
|
|
|
|
|
|
expect(discard_draft_modal).to be_closed
|
|
|
|
|
expect(composer).to be_opened
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-08-26 23:49:26 +08:00
|
|
|
|
|
|
|
|
|
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
|
2024-11-08 04:39:58 +08:00
|
|
|
|
|
|
|
|
|
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
|
2024-08-26 23:49:26 +08:00
|
|
|
|
end
|
2024-04-16 16:34:32 +08:00
|
|
|
|
end
|