mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 02:04:53 +08:00

The previous excerpt was a simple truncated raw message. Starting with this commit, the raw content of the draft is cooked and an excerpt is extracted from it. The logic for extracting the excerpt mimics the the `ExcerptParser` class, but does not implement all functionality, being a much simpler implementation. The two draft controllers have been merged into one and the /draft.json route has been changed to /drafts.json to be consistent with the other route names.
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import { module, test } from "qunit";
|
|
import I18n from "I18n";
|
|
import { NEW_TOPIC_KEY } from "discourse/models/composer";
|
|
import User from "discourse/models/user";
|
|
import UserDraft from "discourse/models/user-draft";
|
|
|
|
module("Unit | Model | user-draft", function () {
|
|
test("stream", function (assert) {
|
|
const user = User.create({ id: 1, username: "eviltrout" });
|
|
const stream = user.userDraftsStream;
|
|
assert.present(stream, "a user has a drafts stream by default");
|
|
assert.equal(stream.content.length, 0, "no items are loaded by default");
|
|
assert.blank(stream.content, "no content by default");
|
|
});
|
|
|
|
test("draft", function (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].draftType,
|
|
I18n.t("drafts.new_topic"),
|
|
"loads correct draftType label"
|
|
);
|
|
});
|
|
});
|