Skip to content

Commit 64f98ea

Browse files
committed
Added basics for mocha unit tests
1 parent 488b4fd commit 64f98ea

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

Gruntfile.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ module.exports = function(grunt) {
1313
}
1414
}
1515
},
16+
simplemocha: {
17+
options: {
18+
globals: ['should'],
19+
timeout: 3000,
20+
ignoreLeaks: false,
21+
grep: '',
22+
ui: 'tdd',
23+
reporter: 'spec'
24+
},
25+
all: { src: ['test/**/*.js'] }
26+
},
1627
watch: {
1728
scripts: {
1829
files: [
@@ -22,7 +33,7 @@ module.exports = function(grunt) {
2233
'source/**/*.js.erb',
2334
'.jshint'
2435
],
25-
tasks: ['jshint'],
36+
tasks: ['simplemocha', 'jshint'],
2637
options: {
2738
interrupt: true,
2839
},
@@ -33,7 +44,8 @@ module.exports = function(grunt) {
3344
// For this to work, you need to have run `npm install grunt-simple-mocha`
3445
grunt.loadNpmTasks('grunt-contrib-jshint');
3546
grunt.loadNpmTasks('grunt-contrib-watch');
47+
grunt.loadNpmTasks('grunt-simple-mocha');
3648

3749
// Add a default task. This is optional, of course :)
38-
grunt.registerTask('default', ['jshint', 'watch']);
50+
grunt.registerTask('default', ['simplemocha', 'jshint', 'watch']);
3951
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"grunt-cli": "~0.1.11",
99
"grunt-jslint": "~1.1.1",
1010
"grunt-contrib-jshint": "~0.7.2",
11-
"grunt-contrib-watch": "^0.6.1"
11+
"grunt-contrib-watch": "^0.6.1",
12+
"grunt-simple-mocha": "^0.4.0"
1213
}
1314
}

source/javascripts/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@
2020
['02/2010', '05/2010', 'LOST Season #5', 'lorem'],
2121
['09/2008', '06/2010', 'FRINGE #1 & #2', 'ipsum']
2222
]);
23-
2423
});
2524
})();

source/javascripts/timesheet.bubble.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
(function() {
22
'use strict';
33

4+
/**
5+
* Timesheet Bubble
6+
*/
47
var Bubble = function(wMonth, min, start, end) {
58
this.min = min;
69
this.start = start;
710
this.end = end;
811
this.widthMonth = wMonth;
912
};
1013

14+
/**
15+
* Format month number
16+
*/
1117
Bubble.prototype.formatMonth = function(num) {
1218
num = parseInt(num, 10);
1319

1420
return num >= 10 ? num : '0' + num;
1521
};
1622

23+
/**
24+
* Calculate starting offset for bubble
25+
*/
1726
Bubble.prototype.getStartOffset = function() {
1827
return (this.widthMonth/12) * (12 * (this.start.getFullYear() - this.min) + this.start.getMonth());
1928
};
2029

30+
/**
31+
* Get count of full years from start to end
32+
*/
2133
Bubble.prototype.getFullYears = function() {
2234
return ((this.end && this.end.getFullYear()) || this.start.getFullYear()) - this.start.getFullYear();
2335
};
2436

37+
/**
38+
* Get count of all months in Timesheet Bubble
39+
*/
2540
Bubble.prototype.getMonths = function() {
2641
var fullYears = this.getFullYears();
2742
var months = 0;
@@ -35,17 +50,23 @@
3550
} else {
3651
months += this.end.getMonth() + 1;
3752
months += 12 - (this.start.hasMonth ? this.start.getMonth() : 0);
38-
months += 12 *(fullYears-1 > 0 ? fullYears-1 : 0);
53+
months += 12 * (fullYears-1);
3954
}
4055
}
4156

4257
return months;
4358
};
4459

60+
/**
61+
* Get bubble's width in pixel
62+
*/
4563
Bubble.prototype.getWidth = function() {
4664
return (this.widthMonth/12) * this.getMonths();
4765
};
4866

67+
/**
68+
* Get the bubble's label
69+
*/
4970
Bubble.prototype.getDateLabel = function() {
5071
return [
5172
(this.start.hasMonth ? this.formatMonth(this.start.getMonth() + 1) + '/' : '' ) + this.start.getFullYear(),

source/javascripts/timesheet.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
(function() {
66
'use strict';
77

8+
/**
9+
* Initialize a Timesheet
10+
*/
811
var Timesheet = function(container, min, max, data) {
912
this.container = '#' + container;
1013
this.data = [];
@@ -18,6 +21,9 @@
1821
this.insertData();
1922
};
2023

24+
/**
25+
* Insert data into Timesheet
26+
*/
2127
Timesheet.prototype.insertData = function() {
2228
var html = [];
2329
var widthMonth = document.querySelector(this.container + ' .scale section').offsetWidth;
@@ -38,6 +44,9 @@
3844
document.querySelector(this.container).innerHTML += '<ul class="data">' + html.join('') + '</ul>';
3945
};
4046

47+
/**
48+
* Draw section labels
49+
*/
4150
Timesheet.prototype.drawSections = function() {
4251
var html = [];
4352

@@ -49,6 +58,9 @@
4958
document.querySelector(this.container).innerHTML = '<div class="scale">' + html.join('') + '</div>';
5059
};
5160

61+
/**
62+
* Parse data string
63+
*/
5264
Timesheet.prototype.parseDate = function(date) {
5365
if (date.indexOf('/') === -1) {
5466
date = new Date(parseInt(date, 10), 0, 1);
@@ -62,6 +74,9 @@
6274
return date;
6375
};
6476

77+
/**
78+
* Parse passed data
79+
*/
6580
Timesheet.prototype.parse = function(data) {
6681
for (var n = 0, m = data.length; n<m; n++) {
6782
var beg = this.parseDate(data[n][0]);

test/timesheet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
suite('Timesheet', function() {
2+
test('Calculation', function(done) {
3+
done();
4+
});
5+
});

0 commit comments

Comments
 (0)