Skip to content

Commit 08a9bb2

Browse files
committed
Added unit tests for date calculation
1 parent 64f98ea commit 08a9bb2

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function(grunt) {
3131
'Gruntfile.js',
3232
'source/**/*.js',
3333
'source/**/*.js.erb',
34+
'test/*.js',
3435
'.jshint'
3536
],
3637
tasks: ['simplemocha', 'jshint'],

source/javascripts/timesheet.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
max: max
1717
};
1818

19-
this.parse(data);
20-
this.drawSections();
21-
this.insertData();
19+
this.parse(data || []);
20+
21+
if (typeof document !== 'undefined') {
22+
this.drawSections();
23+
this.insertData();
24+
}
2225
};
2326

2427
/**

test/timesheet.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
/**
2+
* Load Timesheet lib and fake a window object …
3+
*/
4+
window = {};
5+
require(__dirname + '/../source/javascripts/timesheet.js');
6+
require(__dirname + '/../source/javascripts/timesheet.bubble.js');
7+
8+
var assert = require('assert');
19
suite('Timesheet', function() {
210
test('Calculation', function(done) {
11+
var TS = new window.Timesheet();
12+
13+
assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2002'))).getMonths());
14+
assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2003'))).getMonths());
15+
assert.equal(24, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'), TS.parseDate('2004'))).getMonths());
16+
17+
assert.equal(9, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2002'))).getMonths());
18+
assert.equal(9, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2003'))).getMonths());
19+
assert.equal(21, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('2004'))).getMonths());
20+
21+
assert.equal(13, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2003'))).getMonths());
22+
23+
assert.equal(25, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'), TS.parseDate('04/2004'))).getMonths());
24+
25+
assert.equal(1, (new window.TimesheetBubble(60, 2012, TS.parseDate('04/2002'))).getMonths());
26+
assert.equal(12, (new window.TimesheetBubble(60, 2012, TS.parseDate('2002'))).getMonths());
27+
328
done();
429
});
530
});

0 commit comments

Comments
 (0)