2019-03-15 00:44:49 -04:00
|
|
|
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
2016-06-14 14:31:51 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("model:topic");
|
2015-02-12 15:37:02 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
import Topic from "discourse/models/topic";
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("defaults", assert => {
|
2017-12-14 18:00:48 -05:00
|
|
|
const topic = Topic.create({ id: 1234 });
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(topic.get("deleted_at"), "deleted_at defaults to blank");
|
|
|
|
assert.blank(topic.get("deleted_by"), "deleted_by defaults to blank");
|
2013-07-11 16:38:46 -04:00
|
|
|
});
|
|
|
|
|
2017-12-14 18:00:48 -05:00
|
|
|
QUnit.test("visited", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
const topic = Topic.create({
|
|
|
|
highest_post_number: 2,
|
|
|
|
last_read_post_number: 1
|
|
|
|
});
|
2017-12-14 18:00:48 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
topic.get("visited"),
|
|
|
|
"not visited unless we've read all the posts"
|
|
|
|
);
|
2017-12-14 18:00:48 -05:00
|
|
|
|
|
|
|
topic.set("last_read_post_number", 2);
|
|
|
|
assert.ok(topic.get("visited"), "is visited once we've read all the posts");
|
|
|
|
|
|
|
|
topic.set("last_read_post_number", 3);
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
topic.get("visited"),
|
|
|
|
"is visited if we've read all the posts and some are deleted at the end"
|
|
|
|
);
|
2017-12-14 18:00:48 -05:00
|
|
|
});
|
|
|
|
|
2018-07-16 04:10:22 -04:00
|
|
|
QUnit.test("lastUnreadUrl", assert => {
|
2019-01-11 11:54:23 -05:00
|
|
|
const category = Ember.Object.create({
|
2018-07-16 04:10:22 -04:00
|
|
|
navigate_to_first_post_after_read: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const topic = Topic.create({
|
|
|
|
id: 101,
|
|
|
|
highest_post_number: 10,
|
|
|
|
last_read_post_number: 10,
|
|
|
|
slug: "hello"
|
|
|
|
});
|
|
|
|
|
|
|
|
topic.set("category", category);
|
|
|
|
|
|
|
|
assert.equal(topic.get("lastUnreadUrl"), "/t/hello/101/1");
|
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("has details", assert => {
|
2017-12-14 18:00:48 -05:00
|
|
|
const topic = Topic.create({ id: 1234 });
|
2018-06-15 11:03:24 -04:00
|
|
|
const topicDetails = topic.get("details");
|
2017-12-14 18:00:48 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.present(topicDetails, "a topic has topicDetails after we create it");
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
topicDetails.get("topic"),
|
|
|
|
topic,
|
|
|
|
"the topicDetails has a reference back to the topic"
|
|
|
|
);
|
2013-06-20 17:20:08 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("has a postStream", assert => {
|
2017-12-14 18:00:48 -05:00
|
|
|
const topic = Topic.create({ id: 1234 });
|
2018-06-15 11:03:24 -04:00
|
|
|
const postStream = topic.get("postStream");
|
2017-12-14 18:00:48 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.present(postStream, "a topic has a postStream after we create it");
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
postStream.get("topic"),
|
|
|
|
topic,
|
|
|
|
"the postStream has a reference back to the topic"
|
|
|
|
);
|
2013-06-20 17:20:08 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("has suggestedTopics", assert => {
|
2017-09-26 04:15:25 -04:00
|
|
|
const topic = Topic.create({ suggested_topics: [{ id: 1 }, { id: 2 }] });
|
2018-06-15 11:03:24 -04:00
|
|
|
const suggestedTopics = topic.get("suggestedTopics");
|
2017-09-26 04:15:25 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(suggestedTopics.length, 2, "it loaded the suggested_topics");
|
2017-09-26 04:15:25 -04:00
|
|
|
assert.containsInstance(suggestedTopics, Topic);
|
|
|
|
});
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("category relationship", assert => {
|
2013-06-20 17:20:08 -04:00
|
|
|
// It finds the category by id
|
2017-12-14 18:00:48 -05:00
|
|
|
const category = Discourse.Category.list()[0];
|
2018-06-15 11:03:24 -04:00
|
|
|
const topic = Topic.create({ id: 1111, category_id: category.get("id") });
|
2014-09-26 14:48:34 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(topic.get("category"), category);
|
2013-06-20 17:20:08 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("updateFromJson", assert => {
|
2017-12-14 18:00:48 -05:00
|
|
|
const topic = Topic.create({ id: 1234 });
|
|
|
|
const category = Discourse.Category.list()[0];
|
2013-06-20 17:20:08 -04:00
|
|
|
|
|
|
|
topic.updateFromJson({
|
2018-06-15 11:03:24 -04:00
|
|
|
post_stream: [1, 2, 3],
|
|
|
|
details: { hello: "world" },
|
|
|
|
cool: "property",
|
|
|
|
category_id: category.get("id")
|
2013-06-20 17:20:08 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(topic.get("post_stream"), "it does not update post_stream");
|
|
|
|
assert.equal(topic.get("details.hello"), "world", "it updates the details");
|
|
|
|
assert.equal(topic.get("cool"), "property", "it updates other properties");
|
|
|
|
assert.equal(topic.get("category"), category);
|
2013-07-11 16:38:46 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("destroy", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
const user = Discourse.User.create({ username: "eviltrout" });
|
2017-12-14 18:00:48 -05:00
|
|
|
const topic = Topic.create({ id: 1234 });
|
2013-07-11 16:38:46 -04:00
|
|
|
|
|
|
|
topic.destroy(user);
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.present(topic.get("deleted_at"), "deleted at is set");
|
|
|
|
assert.equal(topic.get("deleted_by"), user, "deleted by is set");
|
2013-07-12 12:08:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("recover", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
const user = Discourse.User.create({ username: "eviltrout" });
|
|
|
|
const topic = Topic.create({
|
|
|
|
id: 1234,
|
|
|
|
deleted_at: new Date(),
|
|
|
|
deleted_by: user
|
|
|
|
});
|
2013-07-12 12:08:23 -04:00
|
|
|
|
|
|
|
topic.recover();
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(topic.get("deleted_at"), "it clears deleted_at");
|
|
|
|
assert.blank(topic.get("deleted_by"), "it clears deleted_by");
|
2014-07-30 18:56:01 -04:00
|
|
|
});
|
2015-06-15 09:27:22 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("fancyTitle", assert => {
|
|
|
|
const topic = Topic.create({
|
|
|
|
fancy_title: ":smile: with all :) the emojis :pear::peach:"
|
|
|
|
});
|
2016-03-04 14:20:44 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
topic.get("fancyTitle"),
|
|
|
|
`<img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'> with all <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'> the emojis <img src='/images/emoji/emoji_one/pear.png?v=${v}' title='pear' alt='pear' class='emoji'><img src='/images/emoji/emoji_one/peach.png?v=${v}' title='peach' alt='peach' class='emoji'>`,
|
|
|
|
"supports emojis"
|
|
|
|
);
|
2017-08-30 03:36:45 -04:00
|
|
|
});
|
2017-09-07 05:06:04 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("fancyTitle direction", assert => {
|
2018-01-29 20:42:19 -05:00
|
|
|
const rtlTopic = Topic.create({ fancy_title: "هذا اختبار" });
|
2018-06-15 11:03:24 -04:00
|
|
|
const ltrTopic = Topic.create({ fancy_title: "This is a test" });
|
2018-01-29 20:42:19 -05:00
|
|
|
|
|
|
|
Discourse.SiteSettings.support_mixed_text_direction = true;
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
rtlTopic.get("fancyTitle"),
|
|
|
|
`<span dir="rtl">هذا اختبار</span>`,
|
|
|
|
"sets the dir-span to rtl"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
ltrTopic.get("fancyTitle"),
|
|
|
|
`<span dir="ltr">This is a test</span>`,
|
|
|
|
"sets the dir-span to ltr"
|
|
|
|
);
|
2018-01-29 20:42:19 -05:00
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("excerpt", assert => {
|
|
|
|
const topic = Topic.create({
|
|
|
|
excerpt: "This is a test topic :smile:",
|
|
|
|
pinned: true
|
|
|
|
});
|
2017-09-07 05:06:04 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
topic.get("escapedExcerpt"),
|
|
|
|
`This is a test topic <img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'>`,
|
|
|
|
"supports emojis"
|
|
|
|
);
|
2017-09-07 05:06:04 -04:00
|
|
|
});
|