FIX: Warn users of overwriting new topic draft (#8841)

This commit is contained in:
Mark VanLandingham 2020-02-04 09:59:56 -06:00 committed by GitHub
parent 91b70f8ffc
commit c8a02161dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 46 deletions

View File

@ -5,6 +5,7 @@ import {
CREATE_SHARED_DRAFT,
REPLY
} from "discourse/models/composer";
import Draft from "discourse/models/draft";
import { computed } from "@ember/object";
import { camelize } from "@ember/string";
@ -223,6 +224,21 @@ export default DropdownSelectBoxComponent.extend({
},
replyAsNewTopicSelected(options) {
Draft.get("new_topic").then(response => {
if (response.draft) {
bootbox.confirm(
I18n.t("composer.composer_actions.reply_as_new_topic.confirm"),
result => {
if (result) this._replyAsNewTopicSelect(options);
}
);
} else {
this._replyAsNewTopicSelect(options);
}
});
},
_replyAsNewTopicSelect(options) {
options.action = CREATE_TOPIC;
options.categoryId = this.get("composerModel.topic.category.id");
options.disableScopedCategory = true;

View File

@ -1756,6 +1756,7 @@ en:
reply_as_new_topic:
label: Reply as linked topic
desc: Create a new topic linked to this topic
confirm: You have a new topic draft saved, which will be overwritten if you create a linked topic.
reply_as_private_message:
label: New message
desc: Create a new personal message

View File

@ -2,6 +2,8 @@ import selectKit from "helpers/select-kit-helper";
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
import { _clearSnapshots } from "select-kit/components/composer-actions";
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
import Draft from "discourse/models/draft";
import { Promise } from "rsvp";
acceptance("Composer Actions", {
loggedIn: true,
@ -99,6 +101,9 @@ QUnit.test("replying to post - toggle_whisper", async assert => {
});
QUnit.test("replying to post - reply_as_new_topic", async assert => {
sandbox
.stub(Draft, "get")
.returns(Promise.resolve({ draft: "", draft_sequence: 0 }));
const composerActions = selectKit(".composer-actions");
const categoryChooser = selectKit(".title-wrapper .category-chooser");
const categoryChooserReplyArea = selectKit(".reply-area .category-chooser");
@ -129,46 +134,16 @@ QUnit.test("replying to post - reply_as_new_topic", async assert => {
.val()
.includes(quote)
);
sandbox.restore();
});
QUnit.test("shared draft", async assert => {
try {
toggleCheckDraftPopup(true);
const composerActions = selectKit(".composer-actions");
const tags = selectKit(".mini-tag-chooser");
await visit("/");
await click("#create-topic");
await fillIn(
"#reply-title",
"This is the new text for the title using 'quotes'"
);
await fillIn(".d-editor-input", "This is the new text for the post");
await tags.expand();
await tags.selectRowByValue("monkey");
await composerActions.expand();
await composerActions.selectRowByValue("shared_draft");
assert.equal(tags.header().value(), "monkey", "tags are not reset");
assert.equal(
find("#reply-title").val(),
"This is the new text for the title using 'quotes'"
);
assert.equal(
find("#reply-control .btn-primary.create .d-button-label").text(),
I18n.t("composer.create_shared_draft")
);
assert.ok(find("#reply-control.composing-shared-draft").length === 1);
await click(".modal-footer .btn.btn-default");
} finally {
toggleCheckDraftPopup(false);
}
QUnit.test("reply_as_new_topic without a new_topic draft", async assert => {
await visit("/t/internationalization-localization/280");
await click(".create.reply");
const composerActions = selectKit(".composer-actions");
await composerActions.expand();
await composerActions.selectRowByValue("reply_as_new_topic");
assert.equal(exists(find(".bootbox")), false);
});
QUnit.test("hide component if no content", async assert => {
@ -363,3 +338,78 @@ QUnit.test(
);
}
);
acceptance("Composer Actions With New Topic Draft", {
loggedIn: true,
settings: {
enable_whispers: true
},
site: {
can_tag_topics: true
},
beforeEach() {
_clearSnapshots();
},
pretend(server, helper) {
server.get("draft.json", () => {
return helper.response({
draft:
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
draft_sequence: 0
});
});
}
});
QUnit.test("shared draft", async assert => {
try {
toggleCheckDraftPopup(true);
const composerActions = selectKit(".composer-actions");
const tags = selectKit(".mini-tag-chooser");
await visit("/");
await click("#create-topic");
await fillIn(
"#reply-title",
"This is the new text for the title using 'quotes'"
);
await fillIn(".d-editor-input", "This is the new text for the post");
await tags.expand();
await tags.selectRowByValue("monkey");
await composerActions.expand();
await composerActions.selectRowByValue("shared_draft");
assert.equal(tags.header().value(), "monkey", "tags are not reset");
assert.equal(
find("#reply-title").val(),
"This is the new text for the title using 'quotes'"
);
assert.equal(
find("#reply-control .btn-primary.create .d-button-label").text(),
I18n.t("composer.create_shared_draft")
);
assert.ok(find("#reply-control.composing-shared-draft").length === 1);
await click(".modal-footer .btn.btn-default");
} finally {
toggleCheckDraftPopup(false);
}
});
QUnit.test("reply_as_new_topic with new_topic draft", async assert => {
await visit("/t/internationalization-localization/280");
await click(".create.reply");
const composerActions = selectKit(".composer-actions");
await composerActions.expand();
await composerActions.selectRowByValue("reply_as_new_topic");
assert.equal(
find(".bootbox .modal-body").text(),
I18n.t("composer.composer_actions.reply_as_new_topic.confirm")
);
await click(".modal-footer .btn.btn-default");
});

View File

@ -366,14 +366,14 @@ QUnit.test("update post time through advanced search ui", async assert => {
"it should update the search term correctly"
);
const postTimeSelector = selectKit(
".search-advanced-options .select-kit#postTime"
);
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-post-date .date-picker", "2016-10-05");
await fillIn("#search-post-date .date-picker", "October 5, 2016");
const postTimeSelector = selectKit(
".search-advanced-options .select-kit#postTime"
);
await postTimeSelector.expand();
await postTimeSelector.selectRowByValue("after");

View File

@ -18,5 +18,10 @@ QUnit.test("Stream - resume draft", async assert => {
assert.ok(find(".user-stream-item").length > 0, "has drafts");
await click(".user-stream-item .resume-draft");
assert.equal(find(".d-editor-input").val(), "dum de dum da ba.");
assert.equal(
find(".d-editor-input")
.val()
.trim(),
"A fun new topic for testing drafts."
);
});

View File

@ -1,7 +1,6 @@
export default {
"/draft.json": {
draft:
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
draft: null,
draft_sequence: 0
}
};