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