Added a test for allowFuture = false

No change to existing functionality. Just testing existing behavior.
This commit is contained in:
Rich Hildebrand 2014-02-25 11:35:21 -05:00
parent 8946a5eb49
commit 873f0f7c10
2 changed files with 56 additions and 0 deletions

View file

@ -190,6 +190,12 @@
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
</ul>
<h2>Future</h2>
<ul>
<li><abbr id="testAllowFutureFalse1" class="doNotAllowFuture" title="2012-01-01T09:24:17Z">(you shouldn't see this)</abbr></li>
</ul>
<h2>Disposal</h2>
<p><abbr class="disposal disposed"></abbr></p>
<p><abbr class="disposal notDisposed"></abbr></p>
@ -243,6 +249,10 @@
$("abbr.tonumbers").each(toWords);
unloadNumbers();
loadDoNotAllowFuture();
$("abbr.doNotAllowFuture").timeago();
unloadDoNotAllowFuture();
setupDisposal();
loadYoungOldYears();
@ -595,6 +605,20 @@
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
});
module("Do Not Allow Future");
// if allowFuture is false, then a minute into the future is altually reported as a minute in the past.
// we did not want to alter the current behavior and break backwards compatability
test("allow future false with a future date moves time backwards", function () {
equal($("#testAllowFutureFalse1").html(), "2 years ago");
});
module("Allow Future");
// test("allow future false with a future date moves time backwards", function () {
// ok($("#testAllowFutureFalse1").html().match(/years ago$/));
// });
module("Disposal");
asyncTest("disposal", function() {

View file

@ -131,3 +131,35 @@ function loadYoungOldYears() {
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
});
}
function loadDoNotAllowFuture() {
var mockDateToUse = "2010-01-01";
$.timeago.settings.allowFuture = false;
enableMockedDate(mockDateToUse);
}
function unloadDoNotAllowFuture() {
$.timeago.settings.allowFuture = true;
disableMockedDate();
}
function enableMockedDate(dateToReturn) {
var mockDate = dateToReturn;
window.NativeDate = Date;
window.Date = function () {
if(arguments.length === 0) {
return new window.NativeDate(mockDate);
} else if(arguments.length === 1) {
return new window.NativeDate(arguments[0]);
} else if(arguments.length === 7) {
return new window.NativeDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
} else {
throw "Mocking Date with this number of parameters is not implemented.";
}
}
}
function disableMockedDate() {
window.Date = window.NativeDate;
delete window.NativeDate;
}