2015-02-12 15:37:02 -05:00
module("model:topic");
import Topic from 'discourse/models/topic';
2013-06-20 17:20:08 -04:00
2013-07-11 16:38:46 -04:00
test("defaults", function() {
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234});
2013-07-11 16:38:46 -04:00
blank(topic.get('deleted_at'), 'deleted_at defaults to blank');
blank(topic.get('deleted_by'), 'deleted_by defaults to blank');
});
2013-06-20 17:20:08 -04:00
test('has details', function() {
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234});
2013-06-20 17:20:08 -04:00
var topicDetails = topic.get('details');
present(topicDetails, "a topic has topicDetails after we create it");
equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic");
});
test('has a postStream', function() {
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234});
2013-06-20 17:20:08 -04:00
var postStream = topic.get('postStream');
present(postStream, "a topic has a postStream after we create it");
equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic");
});
test('category relationship', function() {
// It finds the category by id
2014-09-26 14:48:34 -04:00
var category = Discourse.Category.list()[0],
2015-02-12 15:37:02 -05:00
topic = Topic.create({id: 1111, category_id: category.get('id') });
2014-09-26 14:48:34 -04:00
2013-06-20 17:20:08 -04:00
equal(topic.get('category'), category);
});
test("updateFromJson", function() {
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234}),
2014-09-26 14:48:34 -04:00
category = Discourse.Category.list()[0];
2013-06-20 17:20:08 -04:00
topic.updateFromJson({
post_stream: [1,2,3],
details: {hello: 'world'},
cool: 'property',
category_id: category.get('id')
});
blank(topic.get('post_stream'), "it does not update post_stream");
equal(topic.get('details.hello'), 'world', 'it updates the details');
equal(topic.get('cool'), "property", "it updates other properties");
equal(topic.get('category'), category);
2013-07-11 16:38:46 -04:00
});
test("destroy", function() {
var user = Discourse.User.create({username: 'eviltrout'});
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234});
2013-07-11 16:38:46 -04:00
2014-07-30 18:56:01 -04:00
sandbox.stub(Discourse, 'ajax');
2013-07-11 16:38:46 -04:00
topic.destroy(user);
present(topic.get('deleted_at'), 'deleted at is set');
equal(topic.get('deleted_by'), user, 'deleted by is set');
2013-07-12 12:08:23 -04:00
//ok(Discourse.ajax.calledOnce, "it called delete over the wire");
});
test("recover", function() {
var user = Discourse.User.create({username: 'eviltrout'});
2015-02-12 15:37:02 -05:00
var topic = Topic.create({id: 1234, deleted_at: new Date(), deleted_by: user});
2013-07-12 12:08:23 -04:00
2014-07-30 18:56:01 -04:00
sandbox.stub(Discourse, 'ajax');
2013-07-12 12:08:23 -04:00
topic.recover();
blank(topic.get('deleted_at'), "it clears deleted_at");
blank(topic.get('deleted_by'), "it clears deleted_by");
//ok(Discourse.ajax.calledOnce, "it called recover over the wire");
2014-07-30 18:56:01 -04:00
});
2015-06-15 09:27:22 -04:00
test('fancyTitle', function() {
2015-06-15 10:02:30 -04:00
var topic = Topic.create({ fancy_title: ":smile: with all the emojis" });
2015-06-15 09:27:22 -04:00
equal(topic.get('fancyTitle'), "<img src='/images/emoji/undefined/smile.png?v=0' title='smile' alt='smile' class='emoji'> with all the emojis", "supports emojis");
});