From 1b0267b0774ede6047e915b4b03ab41f5199e6f9 Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Wed, 27 Mar 2019 21:55:09 +0100 Subject: [PATCH] FIX: Switching composer action shouldn't trigger abandon popup (#7261) --- .../components/composer-actions.js.es6 | 2 + .../acceptance/composer-test.js.es6 | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/app/assets/javascripts/select-kit/components/composer-actions.js.es6 b/app/assets/javascripts/select-kit/components/composer-actions.js.es6 index e78aa7fbfc3..1d62264f5c4 100644 --- a/app/assets/javascripts/select-kit/components/composer-actions.js.es6 +++ b/app/assets/javascripts/select-kit/components/composer-actions.js.es6 @@ -230,12 +230,14 @@ export default DropdownSelectBoxComponent.extend({ replyToTopicSelected(options) { options.action = REPLY; options.topic = _topicSnapshot; + options.skipDraftCheck = true; this._openComposer(options); }, replyToPostSelected(options) { options.action = REPLY; options.post = _postSnapshot; + options.skipDraftCheck = true; this._openComposer(options); }, diff --git a/test/javascripts/acceptance/composer-test.js.es6 b/test/javascripts/acceptance/composer-test.js.es6 index fcbff948dc7..73a90575247 100644 --- a/test/javascripts/acceptance/composer-test.js.es6 +++ b/test/javascripts/acceptance/composer-test.js.es6 @@ -600,6 +600,47 @@ QUnit.test("Checks for existing draft", async assert => { toggleCheckDraftPopup(false); }); +QUnit.test("Can switch states without abandon popup", async assert => { + const composerActions = selectKit(".composer-actions"); + toggleCheckDraftPopup(true); + + await visit("/t/internationalization-localization/280"); + + const longText = "a".repeat(256); + + await click(".btn-primary.create.btn"); + + await fillIn(".d-editor-input", longText); + + // prettier-ignore + server.get("/draft.json", () => { // eslint-disable-line no-undef + return [ 200, { "Content-Type": "application/json" }, { + draft: "{\"reply\":\"This is a draft of the first post\",\"action\":\"reply\",\"categoryId\":1,\"archetypeId\":\"regular\",\"metaData\":null,\"composerTime\":2863,\"typingTime\":200}", + draft_sequence: 42 + } ]; + }); + + await click("article#post_3 button.reply"); + + await composerActions.expand(); + await composerActions.selectRowByValue("reply_to_topic"); + + assert.equal(find(".modal-body").text(), "", "abandon popup shouldn't come"); + + assert.equal( + find(".d-editor-input").val(), + longText, + "entered text should still be there" + ); + + assert.ok( + find('.action-title a[href="/t/internationalization-localization/280"]'), + "mode should have changed" + ); + + toggleCheckDraftPopup(false); +}); + QUnit.test("Loading draft also replaces the recipients", async assert => { toggleCheckDraftPopup(true);