FEATURE: Drafts view in user profile
* add drafts.json endpoint, user profile tab with drafts stream * improve drafts stream display in user profile * truncate excerpts in drafts list, better handling for resume draft action * improve draft stream SQL query, add rspec tests * if composer is open, quietly close it when user opens another draft from drafts stream; load PM draft only when user is in /u/username/messages (instead of /u/username) * cleanup * linting fixes * apply prettier styling to modified files * add client tests for drafts, includes a fixture for drafts.json * improvements to code following review * refresh drafts route when user deletes a draft open in the composer while being in the drafts route; minor prettier scss fix * added more spec tests, deleted an acceptance test for removing drafts that was too finicky, formatting and code style fixes, added appEvent for draft:destroyed * prettier, eslint fixes * use "username_lower" from users table, added error handling for rejected promises * adds guardian spec for can_see_drafts, adds improvements following code review * move DraftsController spec to its own file * fix failing drafts qunit test, use getOwner instead of deprecated this.container * limit test fixture for draft.json testing to new_topic request only
This commit is contained in:
@@ -39,3 +39,18 @@ QUnit.test("Viewing Summary", async assert => {
|
||||
assert.ok(exists(".badges-section .badge-card"), "badges");
|
||||
assert.ok(exists(".top-categories-section .category-link"), "top categories");
|
||||
});
|
||||
|
||||
QUnit.test("Viewing Drafts", async assert => {
|
||||
await visit("/u/eviltrout/activity/drafts");
|
||||
assert.ok(exists(".user-stream"), "has drafts stream");
|
||||
assert.ok(
|
||||
$(".user-stream .user-stream-item-draft-actions").length,
|
||||
"has draft action buttons"
|
||||
);
|
||||
|
||||
await click(".user-stream button.resume-draft:eq(0)");
|
||||
assert.ok(
|
||||
exists(".d-editor-input"),
|
||||
"composer is visible after resuming a draft"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
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_sequence: 0
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
export default {
|
||||
"/drafts.json": {
|
||||
drafts: [
|
||||
{
|
||||
excerpt: "A fun new topic for testing drafts. ",
|
||||
truncated: true,
|
||||
created_at: "2018-07-22T22:20:14.608Z",
|
||||
draft_key: "new_topic",
|
||||
sequence: 26,
|
||||
draft_username: "eviltrout",
|
||||
avatar_template: "/user_avatar/localhost/eviltrout/{size}/2_1.png",
|
||||
data:
|
||||
'{"reply":"A fun new topic for testing drafts. \\n","action":"createTopic","title":"This here is a new topic, friend","categoryId":3,"archetypeId":"regular","metaData":null,"composerTime":24532,"typingTime":2500}',
|
||||
topic_id: null,
|
||||
username: "eviltrout",
|
||||
name: null,
|
||||
user_id: 1,
|
||||
title: null,
|
||||
category_id: 3,
|
||||
archetype: null
|
||||
},
|
||||
{
|
||||
excerpt:
|
||||
"The last reply to this topic was 6 months ago. Your reply will bump the topic to the top of its list",
|
||||
truncated: true,
|
||||
created_at: "2018-07-20T19:04:32.023Z",
|
||||
draft_key: "topic_280",
|
||||
sequence: 0,
|
||||
draft_username: "eviltrout",
|
||||
avatar_template: "/letter_avatar_proxy/v2/letter/p/a87d85/{size}.png",
|
||||
data:
|
||||
'{"reply":"The last reply to this topic was 6 months ago. Your reply will bump the topic to the top of its list.","action":"reply","categoryId":8,"archetypeId":"regular","metaData":null,"composerTime":139499,"typingTime":6100}',
|
||||
topic_id: 280,
|
||||
username: "zogstrip",
|
||||
name: "zogstrip",
|
||||
user_id: 6,
|
||||
title: "Django hangs if I write gibberish",
|
||||
slug: "django-hangs-if-i-write-gibberish",
|
||||
category_id: 8,
|
||||
archetype: "regular"
|
||||
},
|
||||
{
|
||||
excerpt: "here goes a reply to a PM.",
|
||||
created_at: "2018-07-20T16:58:47.433Z",
|
||||
draft_key: "topic_93",
|
||||
sequence: 1,
|
||||
draft_username: "eviltrout",
|
||||
avatar_template: "/user_avatar/localhost/eviltrout/{size}/2_1.png",
|
||||
data:
|
||||
'{"reply":"here goes a reply to a PM.","action":"reply","categoryId":null,"postId":212,"archetypeId":"regular","whisper":false,"metaData":null,"composerTime":455711,"typingTime":5400}',
|
||||
topic_id: 93,
|
||||
username: "eviltrout",
|
||||
name: null,
|
||||
user_id: 1,
|
||||
title: "Hello dear friend, good to see you again",
|
||||
slug: "hello-dear-friend-good-to-see-you-again",
|
||||
archetype: "private_message"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -225,7 +225,15 @@ export default function() {
|
||||
return response({ category });
|
||||
});
|
||||
|
||||
this.get("/draft.json", () => response({}));
|
||||
this.get("/draft.json", request => {
|
||||
if (request.queryParams.draft_key === "new_topic") {
|
||||
return response(fixturesByUrl["/draft.json"]);
|
||||
}
|
||||
|
||||
return response({});
|
||||
});
|
||||
|
||||
this.get("/drafts.json", () => response(fixturesByUrl["/drafts.json"]));
|
||||
|
||||
this.put("/queued_posts/:queued_post_id", function(request) {
|
||||
return response({ queued_post: { id: request.params.queued_post_id } });
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import UserDraft from "discourse/models/user-draft";
|
||||
import { NEW_TOPIC_KEY } from "discourse/models/composer";
|
||||
|
||||
QUnit.module("model:user-drafts");
|
||||
|
||||
QUnit.test("stream", assert => {
|
||||
const user = Discourse.User.create({ id: 1, username: "eviltrout" });
|
||||
const stream = user.get("userDraftsStream");
|
||||
assert.present(stream, "a user has a drafts stream by default");
|
||||
assert.equal(stream.get("itemsLoaded"), 0, "no items are loaded by default");
|
||||
assert.blank(stream.get("content"), "no content by default");
|
||||
});
|
||||
|
||||
QUnit.test("draft", assert => {
|
||||
const drafts = [
|
||||
UserDraft.create({
|
||||
draft_key: "topic_1",
|
||||
post_number: "10"
|
||||
}),
|
||||
UserDraft.create({
|
||||
draft_key: NEW_TOPIC_KEY
|
||||
})
|
||||
];
|
||||
|
||||
assert.equal(drafts.length, 2, "drafts count is right");
|
||||
assert.equal(
|
||||
drafts[1].get("draftType"),
|
||||
I18n.t("drafts.new_topic"),
|
||||
"loads correct draftType label"
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user