Switch to mocha.

This commit is contained in:
Olly Smith 2012-06-10 21:39:00 +01:00
parent 046903cd6f
commit 67525d5735
9 changed files with 8098 additions and 310 deletions

3403
test/lib/chai-1.0.4.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

4
test/lib/jquery-1.7.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

182
test/lib/mocha-1.1.0.css Normal file
View File

@ -0,0 +1,182 @@
body {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
}
#mocha .test:hover h2::after {
position: relative;
top: 0;
right: -10px;
content: '(view source)';
font-size: 12px;
font-family: arial;
color: #888;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
}
#mocha .test pre {
display: inline-block;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
}
#error {
color: #c00;
font-size: 1.5 em;
font-weight: 100;
letter-spacing: 1px;
}
#stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
}
#stats .progress {
float: right;
padding-top: 0;
}
#stats em {
color: black;
}
#stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }

4224
test/lib/mocha-1.1.0.js Normal file

File diff suppressed because it is too large Load Diff

10
test/lib/raphael-2.1.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,74 +0,0 @@
/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
*
* @param testFx javascript condition that evaluates to a boolean,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param onReady what to do when testFx condition is fulfilled,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
*/
function waitFor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timout is 3s
start = new Date().getTime(),
condition = false,
interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
// If not time-out yet and condition not yet fulfilled
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
} else {
if(!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
phantom.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
clearInterval(interval); //< Stop this interval
}
}
}, 100); //< repeat check every 250ms
};
if (phantom.args.length === 0 || phantom.args.length > 2) {
console.log('Usage: run-qunit.js URL');
phantom.exit(1);
}
var page = require('webpage').create();
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(phantom.args[0], function(status){
if (status !== "success") {
console.log("Unable to access network");
phantom.exit(1);
} else {
waitFor(function(){
return page.evaluate(function(){
var el = document.getElementById('qunit-testresult');
if (el && el.innerText.match('completed')) {
return true;
}
return false;
});
}, function(){
var failedNum = page.evaluate(function(){
var el = document.getElementById('qunit-testresult');
console.log(el.innerText);
try {
return el.getElementsByClassName('failed')[0].innerHTML;
} catch (e) { }
return 10000;
});
phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
});
}
});

View File

@ -1,248 +1,29 @@
<!doctype html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js"></script>
<meta charset="utf-8">
<script src="lib/jquery-1.7.2.min.js"></script>
<script src="lib/coffee-script-1.3.3.js"></script>
<link rel="stylesheet" href="lib/mocha-1.1.0.css" type="text/css" media="screen" />
<script type="text/javascript" src="lib/mocha-1.1.0.js"></script>
<script type="text/javascript" src="lib/chai-1.0.4.js"></script>
<script type="text/javascript" src="lib/raphael-2.1.0.min.js"></script>
<script type="text/javascript" src="../morris.js"></script>
<script>
$(document).ready(function(){
mocha.setup('bdd')
should = chai.should()
</script>
module("Morris");
test("Input data remains untouched", function () {
var my_data = [{x: 1, y: 1}, {x: 2, y: 2}];
var expected_data = [{x: 1, y: 1}, {x: 2, y: 2}];
Morris.Line({
element: "graph-placeholder",
data: my_data,
xkey: 'x',
ykeys: ['y'],
labels: ['dontcare']
});
deepEqual(my_data, expected_data);
});
test("Raise an error when the placeholder element is not found.", function () {
var my_data = [{x: 1, y: 1}, {x: 2, y: 2}];
raises(function() {
Morris.Line({
element: "thisplacedoesnotexist",
data: my_data,
xkey: 'x',
ykeys: ['y'],
labels: ['dontcare']})
}, "Graph placeholder not found.");
});
test("Morris.commas", function () {
// zero
equal(Morris.commas(0), "0", "commas(0) = 0")
// positive integers
equal(Morris.commas(1), "1", "commas(1) = 1")
equal(Morris.commas(12), "12", "commas(12) = 12")
equal(Morris.commas(123), "123", "commas(123) = 123");
equal(Morris.commas(1234), "1,234", "commas(1234) = 1,234");
equal(Morris.commas(12345), "12,345", "commas(12345) = 12,345");
equal(Morris.commas(123456), "123,456", "commas(123456) = 123,456");
equal(Morris.commas(1234567), "1,234,567", "commas(1234567) = 1,234,567");
// negative integers
equal(Morris.commas(-1), "-1", "commas(-1) = -1")
equal(Morris.commas(-12), "-12", "commas(-12) = -12")
equal(Morris.commas(-123), "-123", "commas(-123) = -123");
equal(Morris.commas(-1234), "-1,234", "commas(-1234) = -1,234");
equal(Morris.commas(-12345), "-12,345", "commas(-12345) = -12,345");
equal(Morris.commas(-123456), "-123,456", "commas(-123456) = -123,456");
equal(Morris.commas(-1234567), "-1,234,567", "commas(-1234567) = -1,234,567");
// positive decimals
equal(Morris.commas(1.2), "1.2", "commas(1.2) = 1.2")
equal(Morris.commas(12.34), "12.34", "commas(12.34) = 12.34")
equal(Morris.commas(123.456), "123.456", "commas(123.456) = 123.456")
equal(Morris.commas(1234.56), "1,234.56", "commas(1234.56) = 1,234.56")
// negative decimals
equal(Morris.commas(-1.2), "-1.2", "commas(-1.2) = -1.2")
equal(Morris.commas(-12.34), "-12.34", "commas(-12.34) = -12.34")
equal(Morris.commas(-123.456), "-123.456", "commas(-123.456) = -123.456")
equal(Morris.commas(-1234.56), "-1,234.56", "commas(-1234.56) = -1,234.56")
});
test("Morris.pad2", function () {
equal(Morris.pad2(0), "00", "pad2(0) = 0")
equal(Morris.pad2(1), "01", "pad2(1) = 1")
equal(Morris.pad2(2), "02", "pad2(2) = 2")
equal(Morris.pad2(3), "03", "pad2(3) = 3")
equal(Morris.pad2(4), "04", "pad2(4) = 4")
equal(Morris.pad2(5), "05", "pad2(5) = 5")
equal(Morris.pad2(6), "06", "pad2(6) = 6")
equal(Morris.pad2(7), "07", "pad2(7) = 7")
equal(Morris.pad2(8), "08", "pad2(8) = 8")
equal(Morris.pad2(9), "09", "pad2(9) = 9")
equal(Morris.pad2(10), "10", "pad2(10) = 10")
equal(Morris.pad2(12), "12", "pad2(12) = 12")
equal(Morris.pad2(34), "34", "pad2(34) = 34")
equal(Morris.pad2(123), "123", "pad2(123) = 123")
});
test("Morris.labelSeries", function () {
var expected = [
[
new Date(2007, 0, 1).getTime(),
new Date(2012, 0, 1).getTime(),
[["2007", new Date(2007, 0, 1).getTime()],
["2008", new Date(2008, 0, 1).getTime()],
["2009", new Date(2009, 0, 1).getTime()],
["2010", new Date(2010, 0, 1).getTime()],
["2011", new Date(2011, 0, 1).getTime()],
["2012", new Date(2012, 0, 1).getTime()]]
],
[
new Date(2007, 3, 1).getTime(),
new Date(2012, 3, 1).getTime(),
[["2008", new Date(2008, 0, 1).getTime()],
["2009", new Date(2009, 0, 1).getTime()],
["2010", new Date(2010, 0, 1).getTime()],
["2011", new Date(2011, 0, 1).getTime()],
["2012", new Date(2012, 0, 1).getTime()]]
],
[
new Date(2012, 0, 1).getTime(),
new Date(2012, 5, 1).getTime(),
[["2012-01", new Date(2012, 0, 1).getTime()],
["2012-02", new Date(2012, 1, 1).getTime()],
["2012-03", new Date(2012, 2, 1).getTime()],
["2012-04", new Date(2012, 3, 1).getTime()],
["2012-05", new Date(2012, 4, 1).getTime()],
["2012-06", new Date(2012, 5, 1).getTime()]]
],
[
new Date(2012, 0, 1).getTime(),
new Date(2012, 0, 6).getTime(),
[["2012-01-01", new Date(2012, 0, 1).getTime()],
["2012-01-02", new Date(2012, 0, 2).getTime()],
["2012-01-03", new Date(2012, 0, 3).getTime()],
["2012-01-04", new Date(2012, 0, 4).getTime()],
["2012-01-05", new Date(2012, 0, 5).getTime()],
["2012-01-06", new Date(2012, 0, 6).getTime()]]
],
[
new Date(2012, 0, 1, 0).getTime(),
new Date(2012, 0, 1, 5).getTime(),
[["00:00", new Date(2012, 0, 1, 0).getTime()],
["01:00", new Date(2012, 0, 1, 1).getTime()],
["02:00", new Date(2012, 0, 1, 2).getTime()],
["03:00", new Date(2012, 0, 1, 3).getTime()],
["04:00", new Date(2012, 0, 1, 4).getTime()],
["05:00", new Date(2012, 0, 1, 5).getTime()]]
],
[
new Date(2012, 0, 1, 0, 0).getTime(),
new Date(2012, 0, 1, 2, 30).getTime(),
[["00:00", new Date(2012, 0, 1, 0, 0).getTime()],
["00:30", new Date(2012, 0, 1, 0, 30).getTime()],
["01:00", new Date(2012, 0, 1, 1, 0).getTime()],
["01:30", new Date(2012, 0, 1, 1, 30).getTime()],
["02:00", new Date(2012, 0, 1, 2, 0).getTime()],
["02:30", new Date(2012, 0, 1, 2, 30).getTime()]]
],
[
new Date(2012, 0, 1, 0, 0).getTime(),
new Date(2012, 0, 1, 1, 15).getTime(),
[["00:00", new Date(2012, 0, 1, 0, 0).getTime()],
["00:15", new Date(2012, 0, 1, 0, 15).getTime()],
["00:30", new Date(2012, 0, 1, 0, 30).getTime()],
["00:45", new Date(2012, 0, 1, 0, 45).getTime()],
["01:00", new Date(2012, 0, 1, 1, 0).getTime()],
["01:15", new Date(2012, 0, 1, 1, 15).getTime()]]
],
[
new Date(2012, 4, 12, 0, 0).getTime(),
new Date(2012, 4, 12, 2, 30).getTime(),
[["00:00", new Date(2012, 4, 12, 0, 0).getTime()],
["00:30", new Date(2012, 4, 12, 0, 30).getTime()],
["01:00", new Date(2012, 4, 12, 1, 0).getTime()],
["01:30", new Date(2012, 4, 12, 1, 30).getTime()],
["02:00", new Date(2012, 4, 12, 2, 0).getTime()],
["02:30", new Date(2012, 4, 12, 2, 30).getTime()]]
],
[
new Date(2012, 4, 12, 0, 0).getTime(),
new Date(2012, 4, 12, 1, 15).getTime(),
[["00:00", new Date(2012, 4, 12, 0, 0).getTime()],
["00:15", new Date(2012, 4, 12, 0, 15).getTime()],
["00:30", new Date(2012, 4, 12, 0, 30).getTime()],
["00:45", new Date(2012, 4, 12, 0, 45).getTime()],
["01:00", new Date(2012, 4, 12, 1, 0).getTime()],
["01:15", new Date(2012, 4, 12, 1, 15).getTime()]]
]
];
for (var i = 0; i < expected.length; i++) {
var dmin = expected[i][0],
dmax = expected[i][1],
ret = expected[i][2];
deepEqual(Morris.labelSeries(dmin, dmax, 1000), ret);
}
// test interval override
deepEqual(
Morris.labelSeries(
new Date(2011, 11, 12).getTime(),
new Date(2012, 0, 12).getTime(),
1000, "year"),
[["2012", new Date(2012, 0, 1).getTime()]]);
// test custom formatter
deepEqual(
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),
new Date(2012, 0, 6).getTime(),
1000, "day",
function (d) { return (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear(); }),
[["1/1/2012", new Date(2012, 0, 1).getTime()],
["1/2/2012", new Date(2012, 0, 2).getTime()],
["1/3/2012", new Date(2012, 0, 3).getTime()],
["1/4/2012", new Date(2012, 0, 4).getTime()],
["1/5/2012", new Date(2012, 0, 5).getTime()],
["1/6/2012", new Date(2012, 0, 6).getTime()]]);
});
test("Morris.parseDate", function () {
equal(Morris.parseDate("2012"), new Date(2012, 0, 1).getTime());
equal(Morris.parseDate("2012 Q1"), new Date(2012, 2, 1).getTime());
equal(Morris.parseDate("2012-09"), new Date(2012, 8, 1).getTime());
equal(Morris.parseDate("2012-10"), new Date(2012, 9, 1).getTime());
equal(Morris.parseDate("2012-09-15"), new Date(2012, 8, 15).getTime());
equal(Morris.parseDate("2012-10-15"), new Date(2012, 9, 15).getTime());
equal(Morris.parseDate("2012-10-15 12:34"), new Date(2012, 9, 15, 12, 34).getTime());
equal(Morris.parseDate("2012-10-15T12:34"), new Date(2012, 9, 15, 12, 34).getTime());
equal(Morris.parseDate("2012-10-15T12:34Z"), Date.UTC(2012, 9, 15, 12, 34));
equal(Morris.parseDate("2012-10-15T12:34+0100"), Date.UTC(2012, 9, 15, 11, 34));
equal(Morris.parseDate("2012-10-15T12:34+02:00"), Date.UTC(2012, 9, 15, 10, 34));
equal(Morris.parseDate("2012-10-15T12:34-0100"), Date.UTC(2012, 9, 15, 13, 34));
equal(Morris.parseDate("2012-10-15T12:34-02:00"), Date.UTC(2012, 9, 15, 14, 34));
equal(Morris.parseDate("2012-10-15 12:34:55"), new Date(2012, 9, 15, 12, 34, 55).getTime());
equal(Morris.parseDate("2012-10-15T12:34:55"), new Date(2012, 9, 15, 12, 34, 55).getTime());
equal(Morris.parseDate("2012-10-15T12:34:55Z"), Date.UTC(2012, 9, 15, 12, 34, 55));
equal(Morris.parseDate("2012-10-15T12:34:55+0600"), Date.UTC(2012, 9, 15, 6, 34, 55));
equal(Morris.parseDate("2012-10-15T12:34:55+04:00"), Date.UTC(2012, 9, 15, 8, 34, 55));
equal(Morris.parseDate("2012-10-15T12:34:55-0600"), Date.UTC(2012, 9, 15, 18, 34, 55));
equal(Morris.parseDate("2012-10-15T12:34:55-04:00"), Date.UTC(2012, 9, 15, 16, 34, 55));
equal(Morris.parseDate("2012-10-15 12:34:55.123"), new Date(2012, 9, 15, 12, 34, 55, 123).getTime());
equal(Morris.parseDate("2012-10-15T12:34:55.123"), new Date(2012, 9, 15, 12, 34, 55, 123).getTime());
equal(Morris.parseDate("2012-10-15T12:34:55.123Z"), Date.UTC(2012, 9, 15, 12, 34, 55, 123));
equal(Morris.parseDate(new Date(2012, 9, 15, 12, 34, 55, 123).getTime()),
new Date(2012, 9, 15, 12, 34, 55, 123).getTime());
});
});
<script src="test.unit.js"></script>
<script>
$(function () {
mocha.run()
})
</script>
</head>
<body>
<h1 id="qunit-header">Morris.js tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div id="graph-placeholder" style="width: 100px; height: 50px"></div>
</div>
<div id="mocha"></div>
<div id="test" style="visibility: hidden"></div>
</body>
</html>

250
test/test.unit.coffee Normal file
View File

@ -0,0 +1,250 @@
describe 'Morris.line', ->
beforeEach ->
placeholder = $('<div id="graph" style="width: 100px; height: 50px"></div>')
$('#test').append(placeholder)
afterEach ->
$('#test').empty()
it 'should not alter user-supplied data', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
expected_data = [{x: 1, y: 1}, {x: 2, y: 2}]
Morris.Line
element: 'graph'
data: my_data
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
my_data.should.deep.equal expected_data
it 'should raise an error when the placeholder element is not found', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
fn = ->
Morris.Line(
element: "thisplacedoesnotexist"
data: my_data
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
)
fn.should.throw(/Graph placeholder not found./)
it 'should insert commas into long numbers', ->
# zero
Morris.commas(0).should.equal("0")
# positive integers
Morris.commas(1).should.equal("1")
Morris.commas(12).should.equal("12")
Morris.commas(123).should.equal("123")
Morris.commas(1234).should.equal("1,234")
Morris.commas(12345).should.equal("12,345")
Morris.commas(123456).should.equal("123,456")
Morris.commas(1234567).should.equal("1,234,567")
# negative integers
Morris.commas(-1).should.equal("-1")
Morris.commas(-12).should.equal("-12")
Morris.commas(-123).should.equal("-123")
Morris.commas(-1234).should.equal("-1,234")
Morris.commas(-12345).should.equal("-12,345")
Morris.commas(-123456).should.equal("-123,456")
Morris.commas(-1234567).should.equal("-1,234,567")
# positive decimals
Morris.commas(1.2).should.equal("1.2")
Morris.commas(12.34).should.equal("12.34")
Morris.commas(123.456).should.equal("123.456")
Morris.commas(1234.56).should.equal("1,234.56")
# negative decimals
Morris.commas(-1.2).should.equal("-1.2")
Morris.commas(-12.34).should.equal("-12.34")
Morris.commas(-123.456).should.equal("-123.456")
Morris.commas(-1234.56).should.equal("-1,234.56")
it 'should pad numbers', ->
Morris.pad2(0).should.equal("00")
Morris.pad2(1).should.equal("01")
Morris.pad2(2).should.equal("02")
Morris.pad2(3).should.equal("03")
Morris.pad2(4).should.equal("04")
Morris.pad2(5).should.equal("05")
Morris.pad2(6).should.equal("06")
Morris.pad2(7).should.equal("07")
Morris.pad2(8).should.equal("08")
Morris.pad2(9).should.equal("09")
Morris.pad2(10).should.equal("10")
Morris.pad2(12).should.equal("12")
Morris.pad2(34).should.equal("34")
Morris.pad2(123).should.equal("123")
describe 'parsing timestamp strings', ->
it 'should parse years', ->
Morris.parseDate('2012').should.equal(new Date(2012, 0, 1).getTime())
it 'should parse quarters', ->
Morris.parseDate('2012 Q1').should.equal(new Date(2012, 2, 1).getTime())
it 'should parse months', ->
Morris.parseDate('2012-09').should.equal(new Date(2012, 8, 1).getTime())
Morris.parseDate('2012-10').should.equal(new Date(2012, 9, 1).getTime())
it 'should parse dates', ->
Morris.parseDate('2012-09-15').should.equal(new Date(2012, 8, 15).getTime())
Morris.parseDate('2012-10-15').should.equal(new Date(2012, 9, 15).getTime())
it 'should parse times', ->
Morris.parseDate("2012-10-15 12:34").should.equal(new Date(2012, 9, 15, 12, 34).getTime())
Morris.parseDate("2012-10-15T12:34").should.equal(new Date(2012, 9, 15, 12, 34).getTime())
Morris.parseDate("2012-10-15 12:34:55").should.equal(new Date(2012, 9, 15, 12, 34, 55).getTime())
Morris.parseDate("2012-10-15T12:34:55").should.equal(new Date(2012, 9, 15, 12, 34, 55).getTime())
it 'should parse times with timezones', ->
Morris.parseDate("2012-10-15T12:34+0100").should.equal(Date.UTC(2012, 9, 15, 11, 34))
Morris.parseDate("2012-10-15T12:34+02:00").should.equal(Date.UTC(2012, 9, 15, 10, 34))
Morris.parseDate("2012-10-15T12:34-0100").should.equal(Date.UTC(2012, 9, 15, 13, 34))
Morris.parseDate("2012-10-15T12:34-02:00").should.equal(Date.UTC(2012, 9, 15, 14, 34))
Morris.parseDate("2012-10-15T12:34:55Z").should.equal(Date.UTC(2012, 9, 15, 12, 34, 55))
Morris.parseDate("2012-10-15T12:34:55+0600").should.equal(Date.UTC(2012, 9, 15, 6, 34, 55))
Morris.parseDate("2012-10-15T12:34:55+04:00").should.equal(Date.UTC(2012, 9, 15, 8, 34, 55))
Morris.parseDate("2012-10-15T12:34:55-0600").should.equal(Date.UTC(2012, 9, 15, 18, 34, 55))
it 'should pass-through timestamps', ->
Morris.parseDate(new Date(2012, 9, 15, 12, 34, 55, 123).getTime())
.should.equal(new Date(2012, 9, 15, 12, 34, 55, 123).getTime())
describe 'automatically generating smart x-axis labels', ->
it 'should generate year intervals', ->
Morris.labelSeries(
new Date(2007, 0, 1).getTime(),
new Date(2012, 0, 1).getTime(),
1000
).should.deep.equal([
["2007", new Date(2007, 0, 1).getTime()],
["2008", new Date(2008, 0, 1).getTime()],
["2009", new Date(2009, 0, 1).getTime()],
["2010", new Date(2010, 0, 1).getTime()],
["2011", new Date(2011, 0, 1).getTime()],
["2012", new Date(2012, 0, 1).getTime()]
])
Morris.labelSeries(
new Date(2007, 3, 1).getTime(),
new Date(2012, 3, 1).getTime(),
1000
).should.deep.equal([
["2008", new Date(2008, 0, 1).getTime()],
["2009", new Date(2009, 0, 1).getTime()],
["2010", new Date(2010, 0, 1).getTime()],
["2011", new Date(2011, 0, 1).getTime()],
["2012", new Date(2012, 0, 1).getTime()]
])
it 'should generate month intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),
new Date(2012, 5, 1).getTime(),
1000
).should.deep.equal([
["2012-01", new Date(2012, 0, 1).getTime()],
["2012-02", new Date(2012, 1, 1).getTime()],
["2012-03", new Date(2012, 2, 1).getTime()],
["2012-04", new Date(2012, 3, 1).getTime()],
["2012-05", new Date(2012, 4, 1).getTime()],
["2012-06", new Date(2012, 5, 1).getTime()]
])
it 'should generate day intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),
new Date(2012, 0, 6).getTime(),
1000
).should.deep.equal([
["2012-01-01", new Date(2012, 0, 1).getTime()],
["2012-01-02", new Date(2012, 0, 2).getTime()],
["2012-01-03", new Date(2012, 0, 3).getTime()],
["2012-01-04", new Date(2012, 0, 4).getTime()],
["2012-01-05", new Date(2012, 0, 5).getTime()],
["2012-01-06", new Date(2012, 0, 6).getTime()]
])
it 'should generate hour intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1, 0).getTime(),
new Date(2012, 0, 1, 5).getTime(),
1000
).should.deep.equal([
["00:00", new Date(2012, 0, 1, 0).getTime()],
["01:00", new Date(2012, 0, 1, 1).getTime()],
["02:00", new Date(2012, 0, 1, 2).getTime()],
["03:00", new Date(2012, 0, 1, 3).getTime()],
["04:00", new Date(2012, 0, 1, 4).getTime()],
["05:00", new Date(2012, 0, 1, 5).getTime()]
])
it 'should generate half-hour intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1, 0, 0).getTime(),
new Date(2012, 0, 1, 2, 30).getTime(),
1000
).should.deep.equal([
["00:00", new Date(2012, 0, 1, 0, 0).getTime()],
["00:30", new Date(2012, 0, 1, 0, 30).getTime()],
["01:00", new Date(2012, 0, 1, 1, 0).getTime()],
["01:30", new Date(2012, 0, 1, 1, 30).getTime()],
["02:00", new Date(2012, 0, 1, 2, 0).getTime()],
["02:30", new Date(2012, 0, 1, 2, 30).getTime()]
])
Morris.labelSeries(
new Date(2012, 4, 12, 0, 0).getTime(),
new Date(2012, 4, 12, 2, 30).getTime(),
1000
).should.deep.equal([
["00:00", new Date(2012, 4, 12, 0, 0).getTime()],
["00:30", new Date(2012, 4, 12, 0, 30).getTime()],
["01:00", new Date(2012, 4, 12, 1, 0).getTime()],
["01:30", new Date(2012, 4, 12, 1, 30).getTime()],
["02:00", new Date(2012, 4, 12, 2, 0).getTime()],
["02:30", new Date(2012, 4, 12, 2, 30).getTime()]
])
it 'should generate fifteen-minute intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1, 0, 0).getTime(),
new Date(2012, 0, 1, 1, 15).getTime(),
1000
).should.deep.equal([
["00:00", new Date(2012, 0, 1, 0, 0).getTime()],
["00:15", new Date(2012, 0, 1, 0, 15).getTime()],
["00:30", new Date(2012, 0, 1, 0, 30).getTime()],
["00:45", new Date(2012, 0, 1, 0, 45).getTime()],
["01:00", new Date(2012, 0, 1, 1, 0).getTime()],
["01:15", new Date(2012, 0, 1, 1, 15).getTime()]
])
Morris.labelSeries(
new Date(2012, 4, 12, 0, 0).getTime(),
new Date(2012, 4, 12, 1, 15).getTime(),
1000
).should.deep.equal([
["00:00", new Date(2012, 4, 12, 0, 0).getTime()],
["00:15", new Date(2012, 4, 12, 0, 15).getTime()],
["00:30", new Date(2012, 4, 12, 0, 30).getTime()],
["00:45", new Date(2012, 4, 12, 0, 45).getTime()],
["01:00", new Date(2012, 4, 12, 1, 0).getTime()],
["01:15", new Date(2012, 4, 12, 1, 15).getTime()]
])
it 'should override automatic intervals', ->
Morris.labelSeries(
new Date(2011, 11, 12).getTime(),
new Date(2012, 0, 12).getTime(),
1000,
"year"
).should.deep.equal([
["2012", new Date(2012, 0, 1).getTime()]
])
it 'should apply custom formatters', ->
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),
new Date(2012, 0, 6).getTime(),
1000,
"day",
(d) -> "#{d.getMonth()+1}/#{d.getDate()}/#{d.getFullYear()}"
).should.deep.equal([
["1/1/2012", new Date(2012, 0, 1).getTime()],
["1/2/2012", new Date(2012, 0, 2).getTime()],
["1/3/2012", new Date(2012, 0, 3).getTime()],
["1/4/2012", new Date(2012, 0, 4).getTime()],
["1/5/2012", new Date(2012, 0, 5).getTime()],
["1/6/2012", new Date(2012, 0, 6).getTime()]
])