mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Check if draft exists before starting a new one (#6755)
Co-Authored-By: Bianca Nenciu <nbianca@users.noreply.github.com> Co-Authored-By: zogstrip <regis@hanol.fr>
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
||||
|
||||
acceptance("Composer", {
|
||||
loggedIn: true,
|
||||
pretend(server, helper) {
|
||||
server.get("/draft.json", () => {
|
||||
return helper.response({
|
||||
draft: null,
|
||||
draft_sequence: 42
|
||||
});
|
||||
});
|
||||
},
|
||||
settings: {
|
||||
enable_whispers: true
|
||||
}
|
||||
@@ -527,49 +536,25 @@ QUnit.test(
|
||||
}
|
||||
);
|
||||
|
||||
acceptance("Composer and uncategorized is not allowed", {
|
||||
loggedIn: true,
|
||||
settings: {
|
||||
enable_whispers: true,
|
||||
allow_uncategorized_topics: false
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test("Disable body until category is selected", async assert => {
|
||||
replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
|
||||
|
||||
await visit("/");
|
||||
await click("#create-topic");
|
||||
assert.ok(exists(".d-editor-input"), "the composer input is visible");
|
||||
assert.ok(
|
||||
exists(".title-input .popup-tip.bad.hide"),
|
||||
"title errors are hidden by default"
|
||||
);
|
||||
assert.ok(
|
||||
exists(".d-editor-textarea-wrapper .popup-tip.bad.hide"),
|
||||
"body errors are hidden by default"
|
||||
);
|
||||
assert.ok(
|
||||
exists(".d-editor-textarea-wrapper.disabled"),
|
||||
"textarea is disabled"
|
||||
);
|
||||
|
||||
const categoryChooser = selectKit(".category-chooser");
|
||||
|
||||
await categoryChooser.expand();
|
||||
await categoryChooser.selectRowByValue(2);
|
||||
|
||||
assert.ok(
|
||||
find(".d-editor-textarea-wrapper.disabled").length === 0,
|
||||
"textarea is enabled"
|
||||
);
|
||||
|
||||
await fillIn(".d-editor-input", "Now I can type stuff");
|
||||
await categoryChooser.expand();
|
||||
await categoryChooser.selectRowByValue("__none__");
|
||||
|
||||
assert.ok(
|
||||
find(".d-editor-textarea-wrapper.disabled").length === 0,
|
||||
"textarea is still enabled"
|
||||
);
|
||||
QUnit.test("Checks for existing draft", async assert => {
|
||||
toggleCheckDraftPopup(true);
|
||||
|
||||
// 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 visit("/t/internationalization-localization/280");
|
||||
|
||||
await click(".topic-post:eq(0) button.show-more-actions");
|
||||
await click(".topic-post:eq(0) button.edit");
|
||||
|
||||
assert.equal(find(".modal-body").text(), I18n.t("drafts.abandon.confirm"));
|
||||
|
||||
await click(".modal-footer .btn.btn-default");
|
||||
|
||||
toggleCheckDraftPopup(false);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("Composer and uncategorized is not allowed", {
|
||||
loggedIn: true,
|
||||
pretend(server, helper) {
|
||||
server.get("/draft.json", () => {
|
||||
return helper.response({
|
||||
draft: null,
|
||||
draft_sequence: 42
|
||||
});
|
||||
});
|
||||
},
|
||||
settings: {
|
||||
enable_whispers: true,
|
||||
allow_uncategorized_topics: false
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test("Disable body until category is selected", async assert => {
|
||||
replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
|
||||
|
||||
await visit("/");
|
||||
await click("#create-topic");
|
||||
assert.ok(exists(".d-editor-input"), "the composer input is visible");
|
||||
assert.ok(
|
||||
exists(".title-input .popup-tip.bad.hide"),
|
||||
"title errors are hidden by default"
|
||||
);
|
||||
assert.ok(
|
||||
exists(".d-editor-textarea-wrapper .popup-tip.bad.hide"),
|
||||
"body errors are hidden by default"
|
||||
);
|
||||
assert.ok(
|
||||
exists(".d-editor-textarea-wrapper.disabled"),
|
||||
"textarea is disabled"
|
||||
);
|
||||
|
||||
const categoryChooser = selectKit(".category-chooser");
|
||||
|
||||
await categoryChooser.expand();
|
||||
await categoryChooser.selectRowByValue(2);
|
||||
|
||||
assert.ok(
|
||||
find(".d-editor-textarea-wrapper.disabled").length === 0,
|
||||
"textarea is enabled"
|
||||
);
|
||||
|
||||
await fillIn(".d-editor-input", "Now I can type stuff");
|
||||
await categoryChooser.expand();
|
||||
await categoryChooser.selectRowByValue("__none__");
|
||||
|
||||
assert.ok(
|
||||
find(".d-editor-textarea-wrapper.disabled").length === 0,
|
||||
"textarea is still enabled"
|
||||
);
|
||||
});
|
||||
@@ -41,10 +41,18 @@ QUnit.test("Viewing Summary", async assert => {
|
||||
});
|
||||
|
||||
QUnit.test("Viewing Drafts", async assert => {
|
||||
// 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 visit("/u/eviltrout/activity/drafts");
|
||||
assert.ok(exists(".user-stream"), "has drafts stream");
|
||||
assert.ok(
|
||||
$(".user-stream .user-stream-item-draft-actions").length,
|
||||
exists(".user-stream .user-stream-item-draft-actions"),
|
||||
"has draft action buttons"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user