aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-04-17 10:03:45 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-04-17 10:03:45 +0200
commita1b44b230af978505222eaee1edbf52aa000e293 (patch)
treedf709dc0d5bc937fa00b41c8d32492f61b1d03d1
parent90506c39bb39ea3cbc77cbd22dd8179e94d46b68 (diff)
downloadbugzilla-triage-a1b44b230af978505222eaee1edbf52aa000e293.tar.gz
Make logger.timeSheetRecordsPrinter testeable and add unit test.
-rw-r--r--lib/logger.js13
-rw-r--r--tests/test-logger.js39
2 files changed, 45 insertions, 7 deletions
diff --git a/lib/logger.js b/lib/logger.js
index d4c5dc9..0b18c1b 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -74,22 +74,21 @@ function getBugzillaAbbr(url) {
}
exports.generateTimeSheet = function generateTimeSheet() {
- var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs);
+ var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs, new Date());
libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML);
};
-function timeSheetRecordsPrinter(records) {
+exports.timeSheetRecordsPrinter = function timeSheetRecordsPrinter(records, date) {
var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g");
// sort the records into temporary array
var tmpArr = [];
- var today = new Date();
- var todayStr = today.getFullYear() + "-" +
- xrpc.leadingZero(today.getMonth()+1) + "-" +
- xrpc.leadingZero(today.getDate());
+ var dateStr = date.getFullYear() + "-" +
+ xrpc.leadingZero(date.getMonth()+1) + "-" +
+ xrpc.leadingZero(date.getDate());
var outStr = '<!DOCTYPE html>' +
"<html><head>\n"+
"<meta charset='utf-8'/>\n"+
- "<title>TimeSheet-"+ todayStr + "</title>\n</head>\n<body>\n" +
+ "<title>TimeSheet-"+ dateStr + "</title>\n</head>\n<body>\n" +
"<h1>TimeSheet</h1>\n";
for (var i in records) {
diff --git a/tests/test-logger.js b/tests/test-logger.js
new file mode 100644
index 0000000..2b087f8
--- /dev/null
+++ b/tests/test-logger.js
@@ -0,0 +1,39 @@
+/*global exports: false, require: false */
+/*jslint plusplus: false */
+"use strict";
+var xrpc = require("xmlrpc");
+var logMod = require("logger");
+var selfMod = require("self");
+
+var testGenerateTimeSheetDataLogs = {
+ "2010-07-27+bugzilla.redhat.com+533567": {
+ "date": "2010-07-27T21:28:47.103Z",
+ "url": "https://bugzilla.redhat.com/show_bug.cgi?id=533567",
+ "title": "KMS:RS480:X200M - GPU lockup (screen goes black)",
+ "comment": "removing filled in chip type for Guadec"
+ },
+ "2010-07-27+bugzilla.redhat.com+618769": {
+ "date": "2010-07-27T21:30:18.845Z",
+ "url": "https://bugzilla.redhat.com/show_bug.cgi?id=618769",
+ "title": "gdm and display unstable with ATI FirePro V3700 graphics card",
+ "comment": "asking for logs"
+ }
+};
+var testGenerateTimeSheetResultStr = "<!DOCTYPE html><html><head>\n<meta charset='utf-8'/>\n"+
+ "<title>TimeSheet-2011-04-17</title>\n</head>\n<body>\n<h1>TimeSheet</h1>\n"+
+ "<hr/><p><strong>2010-07-27</strong></p>\n<p><em>"+
+ "<a href='https://bugzilla.redhat.com/show_bug.cgi?id=533567'>Bug RH/533567: "+
+ "KMS:RS480:X200M - GPU lockup (screen goes black)</a> </em>\n<br/>removing filled "+
+ "in chip type for Guadec</p>\n<p><em><a "+
+ "href='https://bugzilla.redhat.com/show_bug.cgi?id=618769'>Bug RH/618769: "+
+ "gdm and display unstable with ATI FirePro V3700 graphics card</a> </em>\n"+
+ "<br/>asking for logs</p>\n</body></html>";
+
+exports.ensureTimeSheetRecordsPrinter = function (test) {
+ logMod.initialize(JSON.parse(selfMod.data.load(
+ "bugzillalabelAbbreviations.json")))
+ test.assertEqual(logMod.timeSheetRecordsPrinter(testGenerateTimeSheetDataLogs,
+ new Date("2011-04-17")), testGenerateTimeSheetResultStr,
+ "Generates correct log report from given data.");
+};
+