A platform for community discussion. Free, open, simple.
FIX: Handle cancel action in topic reply choice dialog (#35534)
Martin Brennanbef35e2cd440
diff --git a/app/assets/javascripts/discourse/app/components/topic-label-content.gjs b/app/assets/javascripts/discourse/app/components/topic-reply-choice-dialog.gjssimilarity index 96%rename from app/assets/javascripts/discourse/app/components/topic-label-content.gjsrename to app/assets/javascripts/discourse/app/components/topic-reply-choice-dialog.gjsindex a42f080c8e9..e00d324a868 100644--- a/app/assets/javascripts/discourse/app/components/topic-label-content.gjs+++ b/app/assets/javascripts/discourse/app/components/topic-reply-choice-dialog.gjs@@ -49,7 +49,7 @@ const TopicLabelButton = <template></DButton></template>;-export default class TopicLabelContent extends Component {+export default class TopicReplyChoiceDialog extends Component {@actionreplyOnOriginal() {this.args.model.replyOnOriginal();diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.jsindex b4a5228b993..4bfc36925cf 100644--- a/app/assets/javascripts/discourse/app/services/composer.js+++ b/app/assets/javascripts/discourse/app/services/composer.js@@ -10,7 +10,7 @@ import { Promise } from "rsvp";import DiscardDraftModal from "discourse/components/modal/discard-draft";import PostEnqueuedModal from "discourse/components/modal/post-enqueued";import SpreadsheetEditor from "discourse/components/modal/spreadsheet-editor";-import TopicLabelContent from "discourse/components/topic-label-content";+import TopicReplyChoiceDialog from "discourse/components/topic-reply-choice-dialog";import {cannotPostAgain,durationTextFromSeconds,@@ -20,6 +20,7 @@ import { customPopupMenuOptions } from "discourse/lib/composer/custom-popup-menuimport discourseDebounce from "discourse/lib/debounce";import discourseComputed from "discourse/lib/decorators";import deprecated from "discourse/lib/deprecated";+import { isRailsTesting } from "discourse/lib/environment";import prepareFormTemplateData, {getFormTemplateObject,} from "discourse/lib/form-template-validation";@@ -1125,7 +1126,7 @@ export default class ComposerService extends Service {) {this.dialog.alert({title: i18n("composer.posting_not_on_topic"),- bodyComponent: TopicLabelContent,+ bodyComponent: TopicReplyChoiceDialog,bodyComponentModel: {originalTopic,replyOnOriginal: () => {@@ -1146,6 +1147,12 @@ export default class ComposerService extends Service {},],class: "reply-where-modal",+ didCancel: () => {+ composer.set("disableDrafts", false);+ this.skipAutoSave = true;+ this._saveDraft(true);+ this.skipAutoSave = false;+ },});return;}@@ -1749,7 +1756,12 @@ export default class ComposerService extends Service {// pretend so we get a save unconditionally in 15 secsthis._lastDraftSaved = Date.now();}- if (Date.now() - this._lastDraftSaved > 15000) {++ // Speed this up a bit in system specs so we don't have to wait as long+ if (+ Date.now() - this._lastDraftSaved >+ (isRailsTesting() ? 3000 : 15000)+ ) {this._saveDraft();} else {this._saveDraftDebounce = discourseDebounce(diff --git a/spec/system/composer/drafts_spec.rb b/spec/system/composer/drafts_spec.rbindex cd16cf03c95..fce9bea895b 100644--- a/spec/system/composer/drafts_spec.rb+++ b/spec/system/composer/drafts_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: truedescribe "Composer - Drafts", type: :system do- fab!(:topic)+ fab!(:topic, :topic_with_op)fab!(:current_user, :admin)let(:toasts) { PageObjects::Components::Toasts.new }@@ -173,4 +173,136 @@ describe "Composer - Drafts", type: :system doexpect(composer).to be_openedendend++ context "when replying to a different topic with an active draft" do+ fab!(:other_topic, :topic_with_op)++ let(:topic_reply_choice_dialog) { PageObjects::Components::TopicReplyChoiceDialog.new }+ let(:topic_list) { PageObjects::Components::TopicList.new }++ before do+ topic.first_post.update!(raw: "This is the original topic OP content.")+ topic.first_post.rebake!++ other_topic.first_post.update!(raw: "This is the other topic OP content.")+ other_topic.first_post.rebake!+ end++ def visit_topic_and_save_draft+ topic_page.visit_topic(topic)+ topic_page.click_reply_button++ expect(composer).to be_opened+ 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)++ topic_page.visit_topic(topic)+ topic_page.click_reply_button++ expect(composer).to be_opened+ expect(composer).to have_content("a b c d e f g")+ end++ context "when clicking the original topic in the topic reply choice dialog" do+ it "replies with the current content to the original topic" do+ visit_topic_and_save_draft++ # We have to navigate by clicking through the app to keep the+ # composer open.+ click_logo+ expect(topic_list).to have_topic(other_topic)+ topic_list.visit_topic(other_topic)++ expect(topic_page).to have_post_content(+ post_number: 1,+ content: "This is the other topic OP content.",+ )++ composer.create++ expect(topic_reply_choice_dialog).to be_open+ expect(topic_reply_choice_dialog).to have_reply_on_original_topic(topic)+ topic_reply_choice_dialog.click_reply_on_original++ expect(topic_reply_choice_dialog).to be_closed+ expect(composer).to be_closed++ expect(topic_page).to have_post_content(+ post_number: 1,+ content: "This is the original topic OP content.",+ )+ expect(topic_page).to have_post_content(post_number: 2, content: "a b c d e f g")+ expect(topic.reload.posts.last.raw).to eq("a b c d e f g")+ end+ end++ context "when clicking the new topic in the topic reply choice dialog" do+ it "replies with the current content to the new topic" do+ visit_topic_and_save_draft++ # We have to navigate by clicking through the app to keep the+ # composer open.+ click_logo+ expect(topic_list).to have_topic(other_topic)+ topic_list.visit_topic(other_topic)++ expect(topic_page).to have_post_content(+ post_number: 1,+ content: "This is the other topic OP content.",+ )++ composer.create++ expect(topic_reply_choice_dialog).to be_open+ expect(topic_reply_choice_dialog).to have_reply_here_topic(other_topic)+ topic_reply_choice_dialog.click_reply_here++ expect(topic_reply_choice_dialog).to be_closed+ expect(composer).to be_closed++ expect(topic_page).to have_post_content(+ post_number: 1,+ content: "This is the other topic OP content.",+ )+ expect(topic_page).to have_post_content(post_number: 2, content: "a b c d e f g")+ expect(other_topic.reload.posts.last.raw).to eq("a b c d e f g")+ end+ end++ context "when clicking Cancel in the topic reply choice dialog" do+ it "saves the current draft and will save future changes to the draft" do+ visit_topic_and_save_draft++ # We have to navigate by clicking through the app to keep the+ # composer open.+ click_logo+ expect(topic_list).to have_topic(other_topic)+ topic_list.visit_topic(other_topic)++ expect(topic_page).to have_post_content(+ post_number: 1,+ content: "This is the other topic OP content.",+ )++ composer.create++ expect(topic_reply_choice_dialog).to be_open+ topic_reply_choice_dialog.click_cancel+ expect(topic_reply_choice_dialog).to be_closed++ composer.fill_content("This is my updated draft content, wow very impressive.")++ try_until_success(reason: "Relies on waiting a few seconds for the draft to autosave") do+ draft = Draft.where(user: current_user).first+ expect(JSON.parse(draft.data)["reply"]).to eq(+ "This is my updated draft content, wow very impressive.",+ )+ end+ end+ end+ endenddiff --git a/spec/system/page_objects/components/topic_reply_choice_dialog.rb b/spec/system/page_objects/components/topic_reply_choice_dialog.rbnew file mode 100644index 00000000000..a74934282c5--- /dev/null+++ b/spec/system/page_objects/components/topic_reply_choice_dialog.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++module PageObjects+ module Components+ class TopicReplyChoiceDialog < PageObjects::Components::Dialog+ def has_reply_on_original_topic?(topic)+ find("#{reply_on_original_selector}").has_content?(topic.title)+ end++ def reply_on_original_selector+ ".btn-reply-on-original"+ end++ def click_reply_on_original+ find("#{reply_on_original_selector}").click+ end++ def has_reply_here_topic?(topic)+ find("#{reply_here_selector}").has_content?(topic.title)+ end++ def reply_here_selector+ ".btn-reply-here"+ end++ def click_reply_here+ find("#{reply_here_selector}").click+ end++ def click_cancel+ find(".btn-reply-where__cancel").click+ end+ end+ end+end