Skip to content

Commit 1a763d5

Browse files
author
Dave
committed
Add tests for 'dispose' action
1 parent 3b89571 commit 1a763d5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ <h2>Settings</h2>
188188
<li><abbr id="testMillisSettings8" class="tomillis" title="90"></abbr> [90 sec]</li>
189189
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
190190
</ul>
191+
192+
<h2>Disposal</h2>
193+
<p><abbr class="disposal disposed"></abbr></p>
194+
<p><abbr class="disposal notDisposed"></abbr></p>
191195
</div>
192196

193197
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
@@ -238,6 +242,8 @@ <h2>Settings</h2>
238242
$("abbr.tonumbers").each(toWords);
239243
unloadNumbers();
240244

245+
setupDisposal();
246+
241247
loadYoungOldYears();
242248
$("abbr.toyoungold").each(toWords);
243249

@@ -582,6 +588,28 @@ <h2>Settings</h2>
582588
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
583589
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
584590
});
591+
592+
module("Disposal");
593+
594+
asyncTest("disposal", function() {
595+
$(".disposal.disposed").timeago('dispose');
596+
var initialTime_disposedTimeago = $(".disposal.disposed").html();
597+
var initialTime_activeTimeago = $(".disposal.notDisposed").html();
598+
599+
expect(2);
600+
setTimeout(function() {
601+
var updatedTime_disposedTimeago = $(".disposal.disposed").html();
602+
var updatedTime_activeTimeago = $(".disposal.notDisposed").html();
603+
604+
ok(initialTime_disposedTimeago === updatedTime_disposedTimeago, "A disposed timeago didn't get updated");
605+
ok(initialTime_activeTimeago !== updatedTime_activeTimeago, "A non-disposed timeago continued to be updated");
606+
607+
// Dispose still-active timeago
608+
$(".disposal.notDisposed").timeago('dispose');
609+
resetRefreshMillis();
610+
start();
611+
}, 50);
612+
});
585613
})(jQuery);
586614
//]]>
587615
</script>

test/test_helpers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ function unloadCutoffSetting() {
3030
jQuery.timeago.settings.cutoff = 0;
3131
}
3232

33+
function setupDisposal() {
34+
jQuery.timeago.settings.refreshMillis = 50;
35+
$('abbr.disposal').attr("title", iso8601(new Date())).timeago();
36+
}
37+
3338
function loadPigLatin() {
3439
jQuery.timeago.settings.strings = {
3540
suffixAgo: "ago-hay",
@@ -84,6 +89,10 @@ function loadRussian() {
8489
})();
8590
}
8691

92+
function resetRefreshMillis() {
93+
jQuery.timeago.settings.refreshMillis = 60000;
94+
}
95+
8796
function loadMillis() {
8897
var millisSubstitution = function(number, millis) { return millis + " milliseconds"; };
8998
jQuery.timeago.settings.strings = {

0 commit comments

Comments
 (0)