2015-08-08 03:08:27 +08:00
|
|
|
module("mixin:selected-posts-count");
|
2013-06-19 01:44:20 +08:00
|
|
|
|
2015-05-12 18:54:28 +08:00
|
|
|
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
|
2015-02-13 04:37:02 +08:00
|
|
|
import Topic from 'discourse/models/topic';
|
|
|
|
|
2013-12-31 02:29:52 +08:00
|
|
|
var buildTestObj = function(params) {
|
2015-05-12 18:54:28 +08:00
|
|
|
return Ember.Object.createWithMixins(SelectedPostsCount, params || {});
|
2013-06-19 01:44:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
test("without selectedPosts", function () {
|
|
|
|
var testObj = buildTestObj();
|
|
|
|
|
|
|
|
equal(testObj.get('selectedPostsCount'), 0, "No posts are selected without a selectedPosts property");
|
|
|
|
|
|
|
|
testObj.set('selectedPosts', []);
|
|
|
|
equal(testObj.get('selectedPostsCount'), 0, "No posts are selected when selectedPosts is an empty array");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("with some selectedPosts", function() {
|
2013-10-30 01:01:42 +08:00
|
|
|
var testObj = buildTestObj({ selectedPosts: [Discourse.Post.create({id: 123})] });
|
2013-06-19 01:44:20 +08:00
|
|
|
equal(testObj.get('selectedPostsCount'), 1, "It returns the amount of posts");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("when all posts are selected and there is a posts_count", function() {
|
|
|
|
var testObj = buildTestObj({ allPostsSelected: true, posts_count: 1024 });
|
|
|
|
equal(testObj.get('selectedPostsCount'), 1024, "It returns the posts_count");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("when all posts are selected and there is topic with a posts_count", function() {
|
|
|
|
var testObj = buildTestObj({
|
|
|
|
allPostsSelected: true,
|
2015-02-13 04:37:02 +08:00
|
|
|
topic: Topic.create({ posts_count: 3456 })
|
2013-06-19 01:44:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
equal(testObj.get('selectedPostsCount'), 3456, "It returns the topic's posts_count");
|
|
|
|
});
|