2015-11-20 20:27:06 -05:00
|
|
|
import Report from 'admin/models/report';
|
2015-08-11 12:27:07 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("Report");
|
2013-06-19 15:06:23 -04:00
|
|
|
|
|
|
|
function reportWithData(data) {
|
2015-11-20 20:27:06 -05:00
|
|
|
return Report.create({
|
2013-06-19 15:06:23 -04:00
|
|
|
type: 'topics',
|
|
|
|
data: _.map(data, function(val, index) {
|
2014-08-20 16:22:58 -04:00
|
|
|
return { x: moment().subtract(index, "days").format('YYYY-MM-DD'), y: val };
|
2013-06-19 15:06:23 -04:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("counts", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var report = reportWithData([5, 4, 3, 2, 1, 100, 99, 98, 1000]);
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(report.get('todayCount'), 5);
|
|
|
|
assert.equal(report.get('yesterdayCount'), 4);
|
|
|
|
assert.equal(report.valueFor(2, 4), 6, "adds the values for the given range of days, inclusive");
|
|
|
|
assert.equal(report.get('lastSevenDaysCount'), 307, "sums 7 days excluding today");
|
2015-08-04 12:23:56 -04:00
|
|
|
|
|
|
|
report.set("method", "average");
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(report.valueFor(2, 4), 2, "averages the values for the given range of days");
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("percentChangeString", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var report = reportWithData([]);
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(report.percentChangeString(8, 5), "+60%", "value increased");
|
|
|
|
assert.equal(report.percentChangeString(2, 8), "-75%", "value decreased");
|
|
|
|
assert.equal(report.percentChangeString(8, 8), "0%", "value unchanged");
|
|
|
|
assert.blank(report.percentChangeString(8, 0), "returns blank when previous value was 0");
|
|
|
|
assert.equal(report.percentChangeString(0, 8), "-100%", "yesterday was 0");
|
|
|
|
assert.blank(report.percentChangeString(0, 0), "returns blank when both were 0");
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("yesterdayCountTitle with valid values", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var title = reportWithData([6,8,5,2,1]).get('yesterdayCountTitle');
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(title.indexOf('+60%') !== -1);
|
|
|
|
assert.ok(title.match(/Was 5/));
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("yesterdayCountTitle when two days ago was 0", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var title = reportWithData([6,8,0,2,1]).get('yesterdayCountTitle');
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(title.indexOf('%'), -1);
|
|
|
|
assert.ok(title.match(/Was 0/));
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("sevenDayCountTitle", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var title = reportWithData([100,1,1,1,1,1,1,1,2,2,2,2,2,2,2,100,100]).get('sevenDayCountTitle');
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(title.match(/-50%/));
|
|
|
|
assert.ok(title.match(/Was 14/));
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("thirtyDayCountTitle", assert => {
|
2013-06-19 15:06:23 -04:00
|
|
|
var report = reportWithData([5,5,5,5]);
|
|
|
|
report.set('prev30Days', 10);
|
|
|
|
var title = report.get('thirtyDayCountTitle');
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(title.indexOf('+50%') !== -1);
|
|
|
|
assert.ok(title.match(/Was 10/));
|
|
|
|
});
|