mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-27 01:35:40 -05:00
More unit tests added
This commit is contained in:
parent
93577fd6ec
commit
dd707da5d3
3 changed files with 66 additions and 22 deletions
32
index.html
32
index.html
|
@ -7,22 +7,9 @@
|
|||
<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="jquery.timeago.js" type="text/javascript"></script>
|
||||
<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 src="test.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
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();
|
||||
});
|
||||
</script>
|
||||
|
@ -38,9 +25,10 @@
|
|||
p.how, p.last { margin: 0; }
|
||||
ul { margin: 0 24px 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, tt { font-family: monaco,"courier new",mono; }
|
||||
abbr { border-bottom: 1px dotted #333; }
|
||||
tt { font-size: 14px; }
|
||||
a { color: #06e; padding: 1px; }
|
||||
a:hover { background-color: #06c; color: #fff; text-decoration: none; }
|
||||
|
@ -79,17 +67,17 @@
|
|||
</p>
|
||||
|
||||
<pre>
|
||||
<script src="jquery.min.js" type="text/javascript"></script>
|
||||
<script src="jquery.timeago.js" type="text/javascript"></script></pre>
|
||||
<script src="jquery.min.js" type="text/javascript"></script>
|
||||
<script src="jquery.timeago.js" type="text/javascript"></script></pre>
|
||||
|
||||
<p class="how">
|
||||
Now, let's attach it to your timestamps on DOM ready:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('abbr[class*=timeago]').timeago();
|
||||
});</pre>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('abbr[class*=timeago]').timeago();
|
||||
});</pre>
|
||||
|
||||
<p class="how">
|
||||
This will turn all <tt>abbr</tt> elements with a class
|
||||
|
@ -97,14 +85,14 @@
|
|||
</p>
|
||||
|
||||
<pre>
|
||||
<abbr class="<em>timeago</em>" title="<em>2008-07-17T09:24:17Z</em>">July 17, 2008</abbr></pre>
|
||||
<abbr class="<em>timeago</em>" title="<em>2008-07-17T09:24:17Z</em>">July 17, 2008</abbr></pre>
|
||||
|
||||
<p class="how">
|
||||
into something like this:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
<abbr class="timeago" title="2008-07-17T09:24:17Z"><em>6 hours ago</em></abbr></pre>
|
||||
<abbr class="timeago" title="2008-07-17T09:24:17Z"><em>6 hours ago</em></abbr></pre>
|
||||
|
||||
<p class="how">
|
||||
As time passes, the timestamps will automatically update.
|
||||
|
|
40
test.html
40
test.html
|
@ -6,6 +6,7 @@
|
|||
<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="jquery.timeago.js" type="text/javascript"></script>
|
||||
<script src="test.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
// functional tests
|
||||
|
@ -16,12 +17,25 @@
|
|||
var date = $.timeago.parse(this.title);
|
||||
$(this).text(date.toString());
|
||||
});
|
||||
|
||||
// unit tests
|
||||
$('abbr[class*=towords]').each(function() {
|
||||
var string = $.timeago.inWords(parseInt(this.title) * 1000);
|
||||
$(this).text(string);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
abbr { border-bottom: 1px dotted #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
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 />
|
||||
|
@ -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-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>
|
||||
<strong>Ryan was born...</strong><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-19T02:17:00+09:00"></abbr> [from +09:00]<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>
|
||||
</html>
|
||||
|
|
16
test.js
Normal file
16
test.js
Normal 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)));
|
||||
});
|
Loading…
Reference in a new issue