2015-08-12 00:27:07 +08:00
|
|
|
import { blank, present } from 'helpers/qunit-helpers';
|
|
|
|
|
2014-07-31 05:53:14 +08:00
|
|
|
moduleFor('controller:topic', 'controller:topic', {
|
|
|
|
needs: ['controller:header', 'controller:modal', 'controller:composer', 'controller:quote-button',
|
2015-08-29 02:32:53 +08:00
|
|
|
'controller:topic-progress', 'controller:application']
|
2014-07-31 05:53:14 +08:00
|
|
|
});
|
2013-06-21 05:20:08 +08:00
|
|
|
|
2015-02-13 04:37:02 +08:00
|
|
|
import Topic from 'discourse/models/topic';
|
|
|
|
|
2013-09-04 23:53:00 +08:00
|
|
|
var buildTopic = function() {
|
2015-02-13 04:37:02 +08:00
|
|
|
return Topic.create({
|
2013-09-04 23:53:00 +08:00
|
|
|
title: "Qunit Test Topic",
|
|
|
|
participants: [
|
|
|
|
{id: 1234,
|
|
|
|
post_count: 4,
|
|
|
|
username: "eviltrout"}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
};
|
2013-06-21 05:20:08 +08:00
|
|
|
|
2014-07-31 05:53:14 +08:00
|
|
|
|
2013-06-21 05:20:08 +08:00
|
|
|
test("editingMode", function() {
|
2013-09-04 23:53:00 +08:00
|
|
|
var topic = buildTopic(),
|
2014-07-31 05:53:14 +08:00
|
|
|
topicController = this.subject({model: topic});
|
2013-06-21 05:20:08 +08:00
|
|
|
|
|
|
|
ok(!topicController.get('editingTopic'), "we are not editing by default");
|
|
|
|
|
|
|
|
topicController.set('model.details.can_edit', false);
|
2013-09-17 02:08:55 +08:00
|
|
|
topicController.send('editTopic');
|
2013-06-21 05:20:08 +08:00
|
|
|
ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit");
|
|
|
|
|
|
|
|
topicController.set('model.details.can_edit', true);
|
2013-09-17 02:08:55 +08:00
|
|
|
topicController.send('editTopic');
|
2013-06-21 05:20:08 +08:00
|
|
|
ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit");
|
2015-01-03 02:47:07 +08:00
|
|
|
equal(topicController.get('buffered.title'), topic.get('title'));
|
|
|
|
equal(topicController.get('buffered.category_id'), topic.get('category_id'));
|
2013-06-21 05:20:08 +08:00
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
topicController.send('cancelEditingTopic');
|
2013-06-21 05:20:08 +08:00
|
|
|
ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value");
|
2013-09-04 23:53:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("toggledSelectedPost", function() {
|
2014-07-31 05:53:14 +08:00
|
|
|
var tc = this.subject({ model: buildTopic() }),
|
2013-09-04 23:53:00 +08:00
|
|
|
post = Discourse.Post.create({id: 123, post_number: 2}),
|
2015-05-28 02:59:52 +08:00
|
|
|
postStream = tc.get('model.postStream');
|
2013-09-04 23:53:00 +08:00
|
|
|
|
|
|
|
postStream.appendPost(post);
|
|
|
|
postStream.appendPost(Discourse.Post.create({id: 124, post_number: 3}));
|
|
|
|
|
|
|
|
blank(tc.get('selectedPosts'), "there are no selected posts by default");
|
|
|
|
equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0");
|
|
|
|
ok(!tc.postSelected(post), "the post is not selected by default");
|
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPost', post);
|
2013-09-04 23:53:00 +08:00
|
|
|
present(tc.get('selectedPosts'), "there is a selectedPosts collection");
|
|
|
|
equal(tc.get('selectedPostsCount'), 1, "there is a selected post now");
|
|
|
|
ok(tc.postSelected(post), "the post is now selected");
|
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPost', post);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(!tc.postSelected(post), "the post is no longer selected");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("selectAll", function() {
|
2014-07-31 05:53:14 +08:00
|
|
|
var tc = this.subject({model: buildTopic()}),
|
2013-09-04 23:53:00 +08:00
|
|
|
post = Discourse.Post.create({id: 123, post_number: 2}),
|
2015-05-28 02:59:52 +08:00
|
|
|
postStream = tc.get('model.postStream');
|
2013-09-04 23:53:00 +08:00
|
|
|
|
|
|
|
postStream.appendPost(post);
|
|
|
|
|
|
|
|
ok(!tc.postSelected(post), "the post is not selected by default");
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('selectAll');
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(tc.postSelected(post), "the post is now selected");
|
|
|
|
ok(tc.get('allPostsSelected'), "all posts are selected");
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('deselectAll');
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(!tc.postSelected(post), "the post is deselected again");
|
|
|
|
ok(!tc.get('allPostsSelected'), "all posts are not selected");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Automating setting of allPostsSelected", function() {
|
|
|
|
var topic = buildTopic(),
|
2014-07-31 05:53:14 +08:00
|
|
|
tc = this.subject({model: topic}),
|
2013-09-04 23:53:00 +08:00
|
|
|
post = Discourse.Post.create({id: 123, post_number: 2}),
|
2015-05-28 02:59:52 +08:00
|
|
|
postStream = tc.get('model.postStream');
|
2013-09-04 23:53:00 +08:00
|
|
|
|
|
|
|
topic.set('posts_count', 1);
|
|
|
|
postStream.appendPost(post);
|
|
|
|
ok(!tc.get('allPostsSelected'), "all posts are not selected by default");
|
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPost', post);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post");
|
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPost', post);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Select Replies when present", function() {
|
|
|
|
var topic = buildTopic(),
|
2014-07-31 05:53:14 +08:00
|
|
|
tc = this.subject({ model: topic }),
|
2013-09-04 23:53:00 +08:00
|
|
|
p1 = Discourse.Post.create({id: 1, post_number: 1, reply_count: 1}),
|
|
|
|
p2 = Discourse.Post.create({id: 2, post_number: 2}),
|
2013-12-31 02:29:52 +08:00
|
|
|
p3 = Discourse.Post.create({id: 2, post_number: 3, reply_to_post_number: 1});
|
2013-09-04 23:53:00 +08:00
|
|
|
|
|
|
|
ok(!tc.postSelected(p3), "replies are not selected by default");
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPostReplies', p1);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(tc.postSelected(p1), "it selects the post");
|
|
|
|
ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply");
|
|
|
|
ok(tc.postSelected(p3), "it selects a post that is a reply");
|
|
|
|
equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two");
|
|
|
|
|
|
|
|
// If we deselected the post whose replies are selected...
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPost', p1);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(!tc.postSelected(p1), "it deselects the post");
|
|
|
|
ok(!tc.postSelected(p3), "it deselects the replies too");
|
|
|
|
|
|
|
|
// If we deselect a reply, it should deselect the parent's replies selected attribute. Weird but what else would make sense?
|
2013-09-17 02:08:55 +08:00
|
|
|
tc.send('toggledSelectedPostReplies', p1);
|
|
|
|
tc.send('toggledSelectedPost', p3);
|
2013-09-04 23:53:00 +08:00
|
|
|
ok(tc.postSelected(p1), "the post stays selected");
|
|
|
|
ok(!tc.postSelected(p3), "it deselects the replies too");
|
|
|
|
|
|
|
|
});
|
|
|
|
|