mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
Add a js spec for admin/report model, and find a bug too
This commit is contained in:
parent
a1c879668d
commit
c589b4b187
@ -16,8 +16,8 @@ Discourse.Report = Discourse.Model.extend({
|
|||||||
|
|
||||||
sumDays: function(startDaysAgo, endDaysAgo) {
|
sumDays: function(startDaysAgo, endDaysAgo) {
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
var earliestDate = Date.create(endDaysAgo + ' days ago', 'en');
|
var earliestDate = Date.create(endDaysAgo + ' days ago', 'en').beginningOfDay();
|
||||||
var latestDate = Date.create(startDaysAgo + ' days ago', 'en');
|
var latestDate = Date.create(startDaysAgo + ' days ago', 'en').beginningOfDay();
|
||||||
var d, sum = 0;
|
var d, sum = 0;
|
||||||
this.data.each(function(datum){
|
this.data.each(function(datum){
|
||||||
d = Date.create(datum.x);
|
d = Date.create(datum.x);
|
||||||
|
41
spec/javascripts/models/report_spec.js
Normal file
41
spec/javascripts/models/report_spec.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
|
||||||
|
|
||||||
|
describe("Discourse.Report", function() {
|
||||||
|
|
||||||
|
function dateString(arg) {
|
||||||
|
return Date.create(arg, 'en').format('{yyyy}-{MM}-{dd}');
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportWithData(data) {
|
||||||
|
var arr = [];
|
||||||
|
data.each(function(val, index) {
|
||||||
|
arr.push({x: dateString(index + ' days ago'), y: val});
|
||||||
|
});
|
||||||
|
return Discourse.Report.create({ type: 'topics', data: arr });
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("todayCount", function() {
|
||||||
|
it("displays the correct value", function() {
|
||||||
|
expect( reportWithData([5,4,3,2,1]).get('todayCount') ).toBe(5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("yesterdayCount", function() {
|
||||||
|
it("displays the correct value", function() {
|
||||||
|
expect( reportWithData([5,4,3,2,1]).get('yesterdayCount') ).toBe(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("sumDays", function() {
|
||||||
|
it("adds the values for the given range of days, inclusive", function() {
|
||||||
|
expect( reportWithData([1,2,3,5,8,13]).sumDays(2,4) ).toBe(16);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("lastSevenDaysCount", function() {
|
||||||
|
it("displays the correct value", function() {
|
||||||
|
expect( reportWithData([100,9,8,7,6,5,4,3,200,300,400]).get('lastSevenDaysCount') ).toBe(42);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -39,6 +39,7 @@
|
|||||||
//= require_tree ../../app/assets/javascripts/discourse/helpers
|
//= require_tree ../../app/assets/javascripts/discourse/helpers
|
||||||
//= require_tree ../../app/assets/javascripts/discourse/templates
|
//= require_tree ../../app/assets/javascripts/discourse/templates
|
||||||
//= require_tree ../../app/assets/javascripts/discourse/routes
|
//= require_tree ../../app/assets/javascripts/discourse/routes
|
||||||
|
//= require_tree ../../app/assets/javascripts/admin/models
|
||||||
|
|
||||||
//= require_tree ../../app/assets/javascripts/defer
|
//= require_tree ../../app/assets/javascripts/defer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user