Improve how category stats are rendered

This commit is contained in:
Neil Lalonde
2013-12-17 16:50:34 -05:00
parent d422113a0d
commit 47c6bb4cf2
4 changed files with 69 additions and 36 deletions

View File

@ -39,29 +39,39 @@ test('findBySlug', function() {
blank(Discourse.Category.findBySlug('luke', 'leia'), 'luke is blank with an incorrect parent');
});
test('postCountStatsStrings', function() {
test('postCountStats', function() {
var category1 = Discourse.Category.create({id: 1, slug: 'unloved', posts_year: 2, posts_month: 0, posts_week: 0, posts_day: 0}),
category2 = Discourse.Category.create({id: 2, slug: 'hasbeen', posts_year: 50, posts_month: 4, posts_week: 0, posts_day: 0}),
category3 = Discourse.Category.create({id: 3, slug: 'solastweek', posts_year: 250, posts_month: 200, posts_week: 50, posts_day: 0}),
category4 = Discourse.Category.create({id: 4, slug: 'hotstuff', posts_year: 500, posts_month: 280, posts_week: 100, posts_day: 22});
category4 = Discourse.Category.create({id: 4, slug: 'hotstuff', posts_year: 500, posts_month: 280, posts_week: 100, posts_day: 22}),
category5 = Discourse.Category.create({id: 6, slug: 'empty', posts_year: 0, posts_month: 0, posts_week: 0, posts_day: 0});
var result = category1.get('postCountStatsStrings');
var result = category1.get('postCountStats');
equal(result.length, 1, "should only show year");
equal(result[0].value, 2);
equal(result[0].unit, 'year');
result = category2.get('postCountStats');
equal(result.length, 2, "should show month and year");
equal(result[0], '0 / month', "should show month and year");
equal(result[1], '2 / year', "should show month and year");
equal(result[0].value, 4);
equal(result[0].unit, 'month');
equal(result[1].value, 50);
equal(result[1].unit, 'year');
result = category2.get('postCountStatsStrings');
equal(result.length, 2, "should show month and year");
equal(result[0], '4 / month', "should show month and year");
equal(result[1], '50 / year', "should show month and year");
result = category3.get('postCountStatsStrings');
result = category3.get('postCountStats');
equal(result.length, 2, "should show week and month");
equal(result[0], '50 / week', "should show week and month");
equal(result[1], '200 / month', "should show week and month");
equal(result[0].value, 50);
equal(result[0].unit, 'week');
equal(result[1].value, 200);
equal(result[1].unit, 'month');
result = category4.get('postCountStatsStrings');
result = category4.get('postCountStats');
equal(result.length, 2, "should show day and week");
equal(result[0], '22 / day', "should show day and week");
equal(result[1], '100 / week', "should show day and week");
equal(result[0].value, 22);
equal(result[0].unit, 'day');
equal(result[1].value, 100);
equal(result[1].unit, 'week');
result = category5.get('postCountStats');
equal(result.length, 0, "should show nothing");
});