2016-06-15 02:31:51 +08:00
|
|
|
import { IMAGE_VERSION as v} from 'pretty-text/emoji';
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("model:topic");
|
2015-02-13 04:37:02 +08:00
|
|
|
|
|
|
|
import Topic from 'discourse/models/topic';
|
2013-06-21 05:20:08 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("defaults", assert => {
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234});
|
2017-06-15 01:57:58 +08: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-12 04:38:46 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test('has details', assert => {
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234});
|
2013-06-21 05:20:08 +08:00
|
|
|
var topicDetails = topic.get('details');
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(topicDetails, "a topic has topicDetails after we create it");
|
|
|
|
assert.equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic");
|
2013-06-21 05:20:08 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test('has a postStream', assert => {
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234});
|
2013-06-21 05:20:08 +08:00
|
|
|
var postStream = topic.get('postStream');
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(postStream, "a topic has a postStream after we create it");
|
|
|
|
assert.equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic");
|
2013-06-21 05:20:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test('category relationship', assert => {
|
2013-06-21 05:20:08 +08:00
|
|
|
// It finds the category by id
|
2014-09-27 02:48:34 +08:00
|
|
|
var category = Discourse.Category.list()[0],
|
2015-02-13 04:37:02 +08:00
|
|
|
topic = Topic.create({id: 1111, category_id: category.get('id') });
|
2014-09-27 02:48:34 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(topic.get('category'), category);
|
2013-06-21 05:20:08 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("updateFromJson", assert => {
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234}),
|
2014-09-27 02:48:34 +08:00
|
|
|
category = Discourse.Category.list()[0];
|
2013-06-21 05:20:08 +08:00
|
|
|
|
|
|
|
topic.updateFromJson({
|
|
|
|
post_stream: [1,2,3],
|
|
|
|
details: {hello: 'world'},
|
|
|
|
cool: 'property',
|
|
|
|
category_id: category.get('id')
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08: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-12 04:38:46 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("destroy", assert => {
|
2013-07-12 04:38:46 +08:00
|
|
|
var user = Discourse.User.create({username: 'eviltrout'});
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234});
|
2013-07-12 04:38:46 +08:00
|
|
|
|
|
|
|
topic.destroy(user);
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(topic.get('deleted_at'), 'deleted at is set');
|
|
|
|
assert.equal(topic.get('deleted_by'), user, 'deleted by is set');
|
2013-07-13 00:08:23 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("recover", assert => {
|
2013-07-13 00:08:23 +08:00
|
|
|
var user = Discourse.User.create({username: 'eviltrout'});
|
2015-02-13 04:37:02 +08:00
|
|
|
var topic = Topic.create({id: 1234, deleted_at: new Date(), deleted_by: user});
|
2013-07-13 00:08:23 +08:00
|
|
|
|
|
|
|
topic.recover();
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.blank(topic.get('deleted_at'), "it clears deleted_at");
|
|
|
|
assert.blank(topic.get('deleted_by'), "it clears deleted_by");
|
2014-07-31 06:56:01 +08:00
|
|
|
});
|
2015-06-15 21:27:22 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test('fancyTitle', assert => {
|
2015-06-16 16:15:42 +08:00
|
|
|
var topic = Topic.create({ fancy_title: ":smile: with all :) the emojis :pear::peach:" });
|
2016-03-05 03:20:44 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(topic.get('fancyTitle'),
|
2016-03-05 03:20:44 +08:00
|
|
|
`<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'>`,
|
2015-06-16 16:15:42 +08:00
|
|
|
"supports emojis");
|
2017-06-15 01:57:58 +08:00
|
|
|
});
|