More unit tests added

This commit is contained in:
Ryan McGeary 2008-07-18 15:58:26 -04:00
parent 93577fd6ec
commit dd707da5d3
3 changed files with 66 additions and 22 deletions

View file

@ -7,22 +7,9 @@
<title>timeago jQuery plugin</title> <title>timeago jQuery plugin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script> <script src="jquery.timeago.js" type="text/javascript"></script>
<script> <script src="test.js" type="text/javascript"></script>
var zeropad = function (num) { return ((num < 10) ? '0' : '') + num; };
var iso8601 = function (date) {
return date.getUTCFullYear() + "-" + zeropad(date.getUTCMonth()+1) + "-" + zeropad(date.getUTCDate())
+ "T" + zeropad(date.getUTCHours()) + ":" + zeropad(date.getUTCMinutes()) + ":" + zeropad(date.getUTCSeconds()) + "Z";
};
</script>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
$('abbr[class*=loaded]').each(function() {
this.title = iso8601(new Date());
});
$('abbr[class*=modified]').each(function() {
this.title = iso8601(new Date(document.lastModified));
});
$('abbr[class*=timeago]').timeago(); $('abbr[class*=timeago]').timeago();
}); });
</script> </script>
@ -38,9 +25,10 @@
p.how, p.last { margin: 0; } p.how, p.last { margin: 0; }
ul { margin: 0 24px 24px; } ul { margin: 0 24px 24px; }
li { line-height: 24px; } li { line-height: 24px; }
pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; } pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; padding: 0 6px; }
pre em { font-style: normal; background-color: #554; } pre em { font-style: normal; background-color: #554; }
pre, tt { font-family: monaco,"courier new",mono; } pre, tt { font-family: monaco,"courier new",mono; }
abbr { border-bottom: 1px dotted #333; }
tt { font-size: 14px; } tt { font-size: 14px; }
a { color: #06e; padding: 1px; } a { color: #06e; padding: 1px; }
a:hover { background-color: #06c; color: #fff; text-decoration: none; } a:hover { background-color: #06c; color: #fff; text-decoration: none; }

View file

@ -6,6 +6,7 @@
<title>Timeago jQuery Plugin Tests</title> <title>Timeago jQuery Plugin Tests</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script> <script src="jquery.timeago.js" type="text/javascript"></script>
<script src="test.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
// functional tests // functional tests
@ -16,12 +17,25 @@
var date = $.timeago.parse(this.title); var date = $.timeago.parse(this.title);
$(this).text(date.toString()); $(this).text(date.toString());
}); });
// unit tests
$('abbr[class*=towords]').each(function() {
var string = $.timeago.inWords(parseInt(this.title) * 1000);
$(this).text(string);
});
}); });
</script> </script>
<style>
abbr { border-bottom: 1px dotted #333; }
</style>
</head> </head>
<body> <body>
<h1>Functional tests:</h1> <h1>Functional tests:</h1>
<h2>Short term</h2>
You opened this page <abbr class="loaded timeago">sometime before now</abbr>.<br />
This page was last modified <abbr class="modified timeago">sometime before now</abbr>.<br />
<h2>Long term</h2> <h2>Long term</h2>
Jett was born <abbr class="timeago" title="2008-02-27T00:23:00Z">bleh</abbr> [from Z]<br /> Jett was born <abbr class="timeago" title="2008-02-27T00:23:00Z">bleh</abbr> [from Z]<br />
Jett was born <abbr class="timeago" title="2008-02-26T19:23:00-0500">bleh</abbr> [from -0500]<br /> Jett was born <abbr class="timeago" title="2008-02-26T19:23:00-0500">bleh</abbr> [from -0500]<br />
@ -32,6 +46,14 @@
Ryan was born <abbr class="timeago" title="1978-12-18T17:17:00Z">bleh</abbr> [from Z]<br /> Ryan was born <abbr class="timeago" title="1978-12-18T17:17:00Z">bleh</abbr> [from Z]<br />
Ryan was born <abbr class="timeago" title="1978-12-18T12:17:00-05:00">bleh</abbr> [from -0500]<br /> Ryan was born <abbr class="timeago" title="1978-12-18T12:17:00-05:00">bleh</abbr> [from -0500]<br />
<h2>Other formats</h2>
Date only: <abbr class="timeago" title="2008-02-26">(you shouldn't see this)</abbr>.<br />
<h2>Errors</h2>
Bad (letters): <abbr class="timeago" title="bleh">(this should be displayed)</abbr>.<br />
Bad (numbers): <abbr class="timeago" title="1234">(this should be displayed)</abbr>.<br />
Bad (missing): <abbr class="timeago">(this should be displayed)</abbr>.<br />
<h1>Parsing unit tests:</h1> <h1>Parsing unit tests:</h1>
<strong>Ryan was born...</strong><br /> <strong>Ryan was born...</strong><br />
<abbr class="todate" title="1978-12-18T17:17:00Z"></abbr> [from Z]<br /> <abbr class="todate" title="1978-12-18T17:17:00Z"></abbr> [from Z]<br />
@ -40,5 +62,23 @@
<abbr class="todate" title="1978-12-18T12:17:00-0500"></abbr> [from -0500]<br /> <abbr class="todate" title="1978-12-18T12:17:00-0500"></abbr> [from -0500]<br />
<abbr class="todate" title="1978-12-19T02:17:00+09:00"></abbr> [from +09:00]<br /> <abbr class="todate" title="1978-12-19T02:17:00+09:00"></abbr> [from +09:00]<br />
<abbr class="todate" title="1978-12-19T02:17:00+0900"></abbr> [from +0900]<br /> <abbr class="todate" title="1978-12-19T02:17:00+0900"></abbr> [from +0900]<br />
<h1>Wording unit tests:</h1>
<abbr class="towords" title="-1"></abbr> [-1 sec]<br />
<abbr class="towords" title="0"></abbr> [0 sec]<br />
<abbr class="towords" title="30"></abbr> [30 sec]<br />
<abbr class="towords" title="45"></abbr> [45 sec]<br />
<abbr class="towords" title="90"></abbr> [90 sec]<br />
<abbr class="towords" title="120"></abbr> [120 sec]<br />
<abbr class="towords" title="2700"></abbr> [45 min]<br />
<abbr class="towords" title="5340"></abbr> [89 min]<br />
<abbr class="towords" title="5400"></abbr> [90 min]<br />
<abbr class="towords" title="7200"></abbr> [120 min]<br />
<abbr class="towords" title="82800"></abbr> [1380 min]<br />
<abbr class="towords" title="2505600"></abbr> [696 hours]<br />
<abbr class="towords" title="2592000"></abbr> [30 days]<br />
<abbr class="towords" title="16416000"></abbr> [190 days]<br />
<abbr class="towords" title="31622400"></abbr> [366 days]<br />
<abbr class="towords" title="94608000"></abbr> [1095 days]<br />
</body> </body>
</html> </html>

16
test.js Normal file
View file

@ -0,0 +1,16 @@
var zeropad = function (num) {
return ((num < 10) ? '0' : '') + num;
};
var iso8601 = function (date) {
return date.getUTCFullYear()
+ "-" + zeropad(date.getUTCMonth()+1)
+ "-" + zeropad(date.getUTCDate())
+ "T" + zeropad(date.getUTCHours())
+ ":" + zeropad(date.getUTCMinutes())
+ ":" + zeropad(date.getUTCSeconds()) + "Z";
};
jQuery(document).ready(function($) {
$('abbr[class*=loaded]').attr("title", iso8601(new Date()));
$('abbr[class*=modified]').attr("title", iso8601(new Date(document.lastModified)));
});