Initial Commit
This commit is contained in:
306
timcharper-calendar_date_select-d3b2b8c/js_test/functional/.tmp_cds_test.html
Executable file
306
timcharper-calendar_date_select-d3b2b8c/js_test/functional/.tmp_cds_test.html
Executable file
@@ -0,0 +1,306 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Calendar Date Select Test Cases</title>
|
||||
<script src="../prototype.js" type="text/javascript"></script>
|
||||
<script src="../unittest.js" type="text/javascript"></script>
|
||||
<!-- other JavaScript includes -->
|
||||
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
||||
|
||||
<link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../test.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- here go any elements you do the testing on -->
|
||||
<div id="cds_test_div">
|
||||
<input type="text" id="cds_test" />
|
||||
</div>
|
||||
|
||||
<!-- Tests -->
|
||||
<script type="text/javascript" language="javascript">
|
||||
// <![CDATA[
|
||||
new Test.Unit.Runner({
|
||||
setup: function() { with(this){
|
||||
$("cds_test").value="";
|
||||
$("cds_test").disabled = false;
|
||||
$("cds_test").readOnly = false;
|
||||
}},
|
||||
teardown: function() { with(this){
|
||||
if (typeof(cds)!="undefined")
|
||||
assert(cds.closed,"all tests should close their calendar control");
|
||||
}},
|
||||
testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
|
||||
$A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
|
||||
$("cds_test").value=d;
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
assertEqual(true, cds.use_time);
|
||||
cds.close();
|
||||
})
|
||||
|
||||
$("cds_test").value="January 2, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
assertEqual(false, cds.use_time);
|
||||
cds.close();
|
||||
}},
|
||||
testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
today_now = $$(".cds_buttons a[href=#]");
|
||||
today_now[0].onclick();
|
||||
assertEqual(false, cds.use_time, "when clicking today link");
|
||||
|
||||
today_now[1].onclick();
|
||||
assertEqual(true, cds.use_time, "should have been true when clicking now link");
|
||||
cds.close();
|
||||
}},
|
||||
test__selectMar_23_2008__shouldSelectCorrectDate: function() { with(this){
|
||||
$("cds_test").value = "Mar 1, 2008"
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "true"});
|
||||
cds.updateSelectedDate({month: 2 /*+1*/, day: 23, year: 2008})
|
||||
|
||||
assertEqual("23", $$('td.selected div').first().innerHTML);
|
||||
cds.close();
|
||||
}},
|
||||
test_updateSelectedDate: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007"
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
|
||||
cds.use_time=true;
|
||||
cds.updateSelectedDate({hour: ""})
|
||||
assertEqual(false, cds.use_time, "when setting hour to ''");
|
||||
|
||||
cds.use_time=true;
|
||||
cds.updateSelectedDate({minute: ""})
|
||||
assertEqual(false, cds.use_time, "when setting minute to ''");
|
||||
|
||||
cds.use_time=false;
|
||||
cds.updateSelectedDate({hour: 0})
|
||||
assertEqual(true, cds.use_time, "when setting hour to 0");
|
||||
|
||||
cds.use_time=false;
|
||||
cds.updateSelectedDate({minute: 0})
|
||||
assertEqual(true, cds.use_time, "when setting minute to 0");
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test_navYear: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
cds.navYear(1870);
|
||||
assertEqual(2007, cds.selected_date.getFullYear());
|
||||
assertEqual(1870, cds.date.getFullYear());
|
||||
cds.close();
|
||||
}},
|
||||
test_navMonth: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
cds.navMonth(5);
|
||||
assertEqual(0, cds.selected_date.getMonth());
|
||||
assertEqual(5, cds.date.getMonth())
|
||||
cds.close();
|
||||
}},
|
||||
test_callBacks: function() { with(this){
|
||||
$("cds_test").up().build("div", {id: "global"});
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
||||
before_show: function() { $("global").before_show_called = true},
|
||||
after_show: function() { $("global").after_show_called = true},
|
||||
before_close: function() { $("global").before_close_called = true},
|
||||
after_close: function() { $("global").after_close_called = true},
|
||||
after_navigate: function() { $("global").after_navigate_called = true},
|
||||
onchange: function() { $("global").onchange_called = true},
|
||||
});
|
||||
cds.navMonth(1);
|
||||
cds.navMonth(10);
|
||||
cds.updateSelectedDate({month: 1, day: 3, year: 2007});
|
||||
cds.close();
|
||||
assert($('global').before_show_called, "before_show wasnt called");
|
||||
assert($('global').after_show_called, "after_show wasnt called");
|
||||
assert($('global').before_close_called, "before_close wasnt called");
|
||||
assert($('global').after_close_called, "after_close wasnt called");
|
||||
assert($('global').after_navigate_called, "after_navigate wasnt called");
|
||||
assert($('global').onchange_called, "onchange wasnt called");
|
||||
$("global").remove();
|
||||
}},
|
||||
test_disabledElement_cantUpdate: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007";
|
||||
$("cds_test").disabled = true;
|
||||
cds = new CalendarDateSelect($("cds_test"));
|
||||
|
||||
runTest = function() {
|
||||
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
||||
assertEqual(10, cds.selected_date.getDate())
|
||||
}
|
||||
runTest();
|
||||
$("cds_test").disabled = false;
|
||||
$("cds_test").readOnly = true;
|
||||
runTest();
|
||||
|
||||
$("cds_test").readOnly = false;
|
||||
cds.close();
|
||||
}},
|
||||
test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007";
|
||||
$("cds_test").readOnly = true;
|
||||
cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
|
||||
|
||||
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
||||
assertEqual(1, cds.selected_date.getDate())
|
||||
|
||||
$("cds_test").readOnly = false;
|
||||
cds.close();
|
||||
}},
|
||||
test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
|
||||
$("cds_test").value = "May 10, 2007 5:00 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
assert(cds.options.get("close_on_click"), "should set close_on_click to true when not using time")
|
||||
assertEqual(false, cds.use_time, "When parsing time");
|
||||
cds.today();
|
||||
assert(cds.closed, "should close when clicking today");
|
||||
assert(!cds.use_time, "Should not use time when calling today");
|
||||
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
|
||||
assertEqual(false, cds.use_time, "When setting hour/minute");
|
||||
assert(cds.closed);
|
||||
}},
|
||||
test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
|
||||
$("cds_test").value = "May 10, 2007 5:00 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
assertEqual(false, cds.use_time, "When parsing time");
|
||||
cds.setUseTime(true); // this will close the control
|
||||
assert(! cds.use_time, "After calling setUseTime(true)");
|
||||
cds.close();
|
||||
}},
|
||||
test_setMinute_notOnInterval_usesFloor: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007 5:25 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
cds.updateSelectedDate({hour: 1, minute: 4});
|
||||
assertEqual(0, cds.selected_date.getMinutes());
|
||||
assertEqual(1, cds.selected_date.getHours());
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
// this checks for a safari 2 bug where safari parses "" as a date back in 1969
|
||||
test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
|
||||
$("cds_test").value = " ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
|
||||
assertEqual(new Date().getFullYear(), cds.date.getFullYear());
|
||||
assert(! cds.selection_made)
|
||||
cds.close();
|
||||
}},
|
||||
test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
|
||||
$("cds_test").value = "December 1, 2007 ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
assert(cds.use_time)
|
||||
cds.close();
|
||||
}},
|
||||
test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
||||
assertEqual("INPUT", cds.target_element.nodeName)
|
||||
cds.close();
|
||||
}},
|
||||
test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
|
||||
$("cds_test").value = "July 4, 1776";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
||||
assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
|
||||
assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
|
||||
|
||||
assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
|
||||
assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
|
||||
assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
|
||||
assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
|
||||
assert(cds.navMonth(1), "should allow me to be in boundary");
|
||||
assert(cds.navYear(2007), "should allow me to be in boundary");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
|
||||
assert(cds.year_select.setValue(2007), "should allow me to select 2007");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__initializedWithDateOutsideOfRange__shouldShowNavDateAsClosestToOutsideYear: function() {with(this){
|
||||
$("cds_test").value = "January 1, 1900";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [1997, 2007]});
|
||||
assertEqual(1997, cds.date.getFullYear(), "When going lesser than year_range");
|
||||
cds.close();
|
||||
|
||||
$("cds_test").value = "January 1, 2010";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [1997, 2007]});
|
||||
assertEqual(2007, cds.date.getFullYear(), "When going greater than year_range");
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__initializedWithDateInsideOfRange__shouldShowNavDateAsYear: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2005";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {year_range: [1997, 2007]});
|
||||
assertEqual(2005, cds.date.getFullYear(), "When going lesser than year_range");
|
||||
cds.close();
|
||||
}},
|
||||
test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {year_range: 10});
|
||||
cds.navYear(1997);
|
||||
assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
|
||||
cds.navYear(2017);
|
||||
assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
|
||||
cds.close();
|
||||
}},
|
||||
test__should_show_iframe_only_in_ie: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test_div"));
|
||||
|
||||
if (navigator.appName=="Microsoft Internet Explorer")
|
||||
assertEqual(1, $$('iframe.ie6_blocker').length)
|
||||
else
|
||||
assertEqual(0, $$('iframe.ie6_blocker').length)
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__should_populate_minute_box_according_to_minute_interval: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time: true, minute_interval: 10});
|
||||
assert(cds.minute_select.setValue(0), "should allow me to select 0 minutes" );
|
||||
assert(!cds.minute_select.setValue(5), "should NOT allow me to select 5 minutes");
|
||||
assert(cds.minute_select.setValue(10), "should allow me to select 10 minutes" );
|
||||
cds.close();
|
||||
}},
|
||||
test__shouldnt_leak_variables: function() {with (this) {
|
||||
var vars = $w("padded2 compare_date str minute hour value e above e_dim e_top e_left matched e_bottom e_height c_pos c_left c_top c_height left_px top_px top_div header_div body_div buttons_div footer_div bottom_div days_tbody row_number cell_index weekday that pre_days use_time m y hover_date x d o")
|
||||
vars.each(function(v) {eval(v + " = -100");});
|
||||
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time: true});
|
||||
cds.navMonth(1);
|
||||
cds.navYear(2);
|
||||
cds.dayHover($$('.cds_body td').first());
|
||||
cds.updateSelectedDate({day:1, month:1, year:2007});
|
||||
cds.close();
|
||||
|
||||
vars.each(function(v) {
|
||||
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
||||
});
|
||||
}},
|
||||
test__valid_date__shouldnt_allow_selection_of_invalid_dates_and_should_apply_css: function() {with (this) {
|
||||
$('cds_test').value = "December 11, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {valid_date_check: function(date) { date < new Date("December 13, 2007")}});
|
||||
cds.updateSelectedDate({day:13, month:12-1, year:2007});
|
||||
cds.close();
|
||||
|
||||
vars.each(function(v) {
|
||||
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
||||
});
|
||||
}}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
365
timcharper-calendar_date_select-d3b2b8c/js_test/functional/cds_test.html
Executable file
365
timcharper-calendar_date_select-d3b2b8c/js_test/functional/cds_test.html
Executable file
@@ -0,0 +1,365 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Calendar Date Select Test Cases</title>
|
||||
<script src="../prototype.js" type="text/javascript"></script>
|
||||
<script src="../unittest.js" type="text/javascript"></script>
|
||||
<!-- other JavaScript includes -->
|
||||
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
||||
|
||||
<link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../test.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- here go any elements you do the testing on -->
|
||||
<div id="cds_test_div">
|
||||
<input type="text" id="cds_test" />
|
||||
</div>
|
||||
|
||||
<!-- Tests -->
|
||||
<script type="text/javascript" language="javascript">
|
||||
// <![CDATA[
|
||||
new Test.Unit.Runner({
|
||||
setup: function() { with(this){
|
||||
$("cds_test").value="";
|
||||
$("cds_test").disabled = false;
|
||||
$("cds_test").readOnly = false;
|
||||
}},
|
||||
teardown: function() { with(this){
|
||||
if (typeof(cds)!="undefined") assert(cds.closed,"all tests should close their calendar control");
|
||||
Date.first_day_of_week = 0;
|
||||
Date.weekdays = $w("S M T W T F S")
|
||||
}},
|
||||
testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
|
||||
$A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
|
||||
$("cds_test").value=d;
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
assertEqual(true, cds.use_time);
|
||||
cds.close();
|
||||
})
|
||||
|
||||
$("cds_test").value="January 2, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
assertEqual(false, cds.use_time);
|
||||
cds.close();
|
||||
}},
|
||||
testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
today_now = $$(".cds_buttons a[href=#]");
|
||||
today_now[0].onclick();
|
||||
assertEqual(false, cds.use_time, "when clicking today link");
|
||||
|
||||
today_now[1].onclick();
|
||||
assertEqual(true, cds.use_time, "should have been true when clicking now link");
|
||||
cds.close();
|
||||
}},
|
||||
test__selectMar_23_2008__shouldSelectCorrectDate: function() { with(this){
|
||||
$("cds_test").value = "Mar 1, 2008"
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "true"});
|
||||
cds.updateSelectedDate({month: 2 /*+1*/, day: 23, year: 2008})
|
||||
|
||||
assertEqual("23", $$('td.selected div').first().innerHTML);
|
||||
cds.close();
|
||||
}},
|
||||
test_updateSelectedDate: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007"
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
|
||||
cds.use_time=true;
|
||||
cds.updateSelectedDate({hour: ""})
|
||||
assertEqual(false, cds.use_time, "when setting hour to ''");
|
||||
|
||||
cds.use_time=true;
|
||||
cds.updateSelectedDate({minute: ""})
|
||||
assertEqual(false, cds.use_time, "when setting minute to ''");
|
||||
|
||||
cds.use_time=false;
|
||||
cds.updateSelectedDate({hour: 0})
|
||||
assertEqual(true, cds.use_time, "when setting hour to 0");
|
||||
|
||||
cds.use_time=false;
|
||||
cds.updateSelectedDate({minute: 0})
|
||||
assertEqual(true, cds.use_time, "when setting minute to 0");
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test_navYear: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
cds.navYear(1870);
|
||||
assertEqual(2007, cds.selected_date.getFullYear());
|
||||
assertEqual(1870, cds.date.getFullYear());
|
||||
cds.close();
|
||||
}},
|
||||
test_navMonth: function() { with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
||||
cds.navMonth(5);
|
||||
assertEqual(0, cds.selected_date.getMonth());
|
||||
assertEqual(5, cds.date.getMonth())
|
||||
cds.close();
|
||||
}},
|
||||
test_callBacks: function() { with(this){
|
||||
$("cds_test").up().build("div", {id: "global"});
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
||||
before_show: function() { $("global").before_show_called = true},
|
||||
after_show: function() { $("global").after_show_called = true},
|
||||
before_close: function() { $("global").before_close_called = true},
|
||||
after_close: function() { $("global").after_close_called = true},
|
||||
after_navigate: function() { $("global").after_navigate_called = true},
|
||||
onchange: function() { $("global").onchange_called = true},
|
||||
});
|
||||
cds.navMonth(1);
|
||||
cds.navMonth(10);
|
||||
cds.updateSelectedDate({month: 1, day: 3, year: 2007});
|
||||
cds.close();
|
||||
assert($('global').before_show_called, "before_show wasnt called");
|
||||
assert($('global').after_show_called, "after_show wasnt called");
|
||||
assert($('global').before_close_called, "before_close wasnt called");
|
||||
assert($('global').after_close_called, "after_close wasnt called");
|
||||
assert($('global').after_navigate_called, "after_navigate wasnt called");
|
||||
assert($('global').onchange_called, "onchange wasnt called");
|
||||
$("global").remove();
|
||||
}},
|
||||
test_onchangeCallbackChangedOnclear: function() { with(this){
|
||||
$("cds_test").up().build("div", {id: "global"});
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
||||
onchange: function() { $("global").onchange_called = true},
|
||||
});
|
||||
$("cds_test").value = "";
|
||||
cds.clearDate();
|
||||
assert( ! $('global').onchange_called, "onchange was called, when the value wasn't actually changed");
|
||||
$("cds_test").value = "boogy";
|
||||
cds.clearDate();
|
||||
assert( $('global').onchange_called, "onchange wasnt called, but should ahve been");
|
||||
cds.close();
|
||||
$("global").remove();
|
||||
}},
|
||||
|
||||
test_disabledElement_cantUpdate: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007";
|
||||
$("cds_test").disabled = true;
|
||||
cds = new CalendarDateSelect($("cds_test"));
|
||||
|
||||
runTest = function() {
|
||||
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
||||
assertEqual(10, cds.selected_date.getDate())
|
||||
}
|
||||
runTest();
|
||||
$("cds_test").disabled = false;
|
||||
$("cds_test").readOnly = true;
|
||||
runTest();
|
||||
|
||||
$("cds_test").readOnly = false;
|
||||
cds.close();
|
||||
}},
|
||||
test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007";
|
||||
$("cds_test").readOnly = true;
|
||||
cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
|
||||
|
||||
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
||||
assertEqual(1, cds.selected_date.getDate())
|
||||
|
||||
$("cds_test").readOnly = false;
|
||||
cds.close();
|
||||
}},
|
||||
test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
|
||||
$("cds_test").value = "May 10, 2007 5:00 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
assert(cds.closeOnClick(), "should set close_on_click to true when not using time")
|
||||
assertEqual(false, cds.use_time, "When parsing time");
|
||||
cds.today();
|
||||
assert(cds.closed, "should close when clicking today");
|
||||
assert(!cds.use_time, "Should not use time when calling today");
|
||||
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
|
||||
assertEqual(false, cds.use_time, "When setting hour/minute");
|
||||
assert(cds.closed);
|
||||
}},
|
||||
test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
|
||||
$("cds_test").value = "May 10, 2007 5:00 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
||||
assertEqual(false, cds.use_time, "When parsing time");
|
||||
cds.setUseTime(true); // this will close the control
|
||||
assert(! cds.use_time, "After calling setUseTime(true)");
|
||||
cds.close();
|
||||
}},
|
||||
test_setMinute_notOnInterval_usesFloor: function() {with(this){
|
||||
$("cds_test").value = "May 10, 2007 5:25 pm";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
cds.updateSelectedDate({hour: 1, minute: 4});
|
||||
assertEqual(0, cds.selected_date.getMinutes());
|
||||
assertEqual(1, cds.selected_date.getHours());
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
// this checks for a safari 2 bug where safari parses "" as a date back in 1969
|
||||
test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
|
||||
$("cds_test").value = " ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
|
||||
assertEqual(new Date().getFullYear(), cds.date.getFullYear());
|
||||
assert(! cds.selection_made)
|
||||
cds.close();
|
||||
}},
|
||||
test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
|
||||
$("cds_test").value = "December 1, 2007 ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
||||
assert(cds.use_time)
|
||||
cds.close();
|
||||
}},
|
||||
test_parseDate_defaultTime_javaScriptFunctionPassed_shouldReturnDateFromJavaScriptFunction: function() {with(this){
|
||||
$("cds_test").value = " ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {default_time:function() { return new Date('January 02, 2008 2:00 PM') }});
|
||||
assertEqual('2008', cds.selected_date.getFullYear());
|
||||
assertEqual('2008', cds.date.getFullYear());
|
||||
assert(cds.selection_made)
|
||||
cds.close();
|
||||
}},
|
||||
test_parseDate_defaultTime_javaScriptDatePassed_shouldReturnJavaScriptDate: function() {with(this){
|
||||
$("cds_test").value = " ";
|
||||
cds = new CalendarDateSelect($("cds_test"), {default_time:new Date('January 02, 2007 05:45 PM') });
|
||||
assertEqual('2007', cds.selected_date.getFullYear());
|
||||
assertEqual('2007', cds.date.getFullYear());
|
||||
assert(cds.selection_made)
|
||||
cds.close();
|
||||
}},
|
||||
test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
||||
assertEqual("INPUT", cds.target_element.nodeName)
|
||||
cds.close();
|
||||
}},
|
||||
test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
|
||||
$("cds_test").value = "July 4, 1776";
|
||||
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
||||
assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
|
||||
assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
|
||||
|
||||
assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
|
||||
assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
|
||||
assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
|
||||
assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
|
||||
assert(cds.navMonth(1), "should allow me to be in boundary");
|
||||
assert(cds.navYear(2007), "should allow me to be in boundary");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
|
||||
assert(cds.year_select.setValue(2007), "should allow me to select 2007");
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__initializedWithDateOutsideOfRange__shouldShowNavDateAsClosestToOutsideYear: function() {with(this){
|
||||
$("cds_test").value = "January 1, 1900";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
|
||||
assertEqual(1997, cds.date.getFullYear(), "When going lesser than year_range");
|
||||
cds.close();
|
||||
|
||||
$("cds_test").value = "January 1, 2010";
|
||||
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
|
||||
assertEqual(2007, cds.date.getFullYear(), "When going greater than year_range");
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__nonflexibleYearRange__initializedWithDateInsideOfRange__shouldShowNavDateAsYear: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2005";
|
||||
cds = new CalendarDateSelect($("cds_test"), {year_range: [1997, 2007]});
|
||||
assertEqual(2005, cds.date.getFullYear(), "When going lesser than year_range");
|
||||
cds.close();
|
||||
}},
|
||||
test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
|
||||
$("cds_test").value = "January 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {year_range: 10});
|
||||
cds.navYear(1997);
|
||||
assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
|
||||
cds.navYear(2017);
|
||||
assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
|
||||
cds.close();
|
||||
}},
|
||||
test__should_show_iframe_only_in_ie: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test"));
|
||||
|
||||
if (navigator.appName=="Microsoft Internet Explorer")
|
||||
assertEqual(1, $$('iframe.ie6_blocker').length)
|
||||
else
|
||||
assertEqual(0, $$('iframe.ie6_blocker').length)
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__should_populate_minute_box_according_to_minute_interval: function() {with(this){
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: true, minute_interval: 10});
|
||||
assert(cds.minute_select.setValue(0), "should allow me to select 0 minutes" );
|
||||
assert(!cds.minute_select.setValue(5), "should NOT allow me to select 5 minutes");
|
||||
assert(cds.minute_select.setValue(10), "should allow me to select 10 minutes" );
|
||||
cds.close();
|
||||
}},
|
||||
test__shouldnt_leak_variables: function() {with (this) {
|
||||
var vars = $w("padded2 compare_date str minute hour value e above e_dim e_top e_left matched e_bottom e_height c_pos c_left c_top c_height left_px top_px top_div header_div body_div buttons_div footer_div bottom_div days_tbody row_number cell_index weekday that pre_days use_time m y hover_date x d o")
|
||||
vars.each(function(v) {eval(v + " = -100");});
|
||||
|
||||
cds = new CalendarDateSelect($("cds_test"), {time: true});
|
||||
cds.navMonth(1);
|
||||
cds.navYear(2);
|
||||
cds.dayHover($$('.cds_body td').first());
|
||||
cds.updateSelectedDate({day:1, month:1, year:2007});
|
||||
cds.close();
|
||||
|
||||
vars.each(function(v) {
|
||||
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
||||
});
|
||||
}},
|
||||
test__valid_date__shouldnt_allow_selection_of_invalid_dates_and_should_apply_css: function() {with (this) {
|
||||
$('cds_test').value = "December 11, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"), {valid_date_check: function(date) { return date < new Date("December 13, 2007")}, time: "mixed"});
|
||||
assertEqual("December 11, 2007", $F('cds_test'));
|
||||
cds.updateSelectedDate({day:13, month:12-1, year:2007});
|
||||
assertEqual("December 11, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
|
||||
cds.updateSelectedDate({day:10, month:12-1, year:2007});
|
||||
assertEqual("December 10, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
|
||||
|
||||
day_12_element = $$('.calendar_date_select td')[17];
|
||||
day_13_element = $$('.calendar_date_select td')[18];
|
||||
assertEqual(12, day_12_element.day); // make sure we have th right one
|
||||
assertEqual(13, day_13_element.day); // make sure we have th right one
|
||||
assert( ! day_12_element.hasClassName("disabled"), "Day 12 shouldnt be disabled");
|
||||
assert(day_13_element.hasClassName("disabled"), "Day 13 should be disabled");
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__valid_date_check_is_nil__should_show_all_cells_as_enabled: function() {with (this) {
|
||||
$('cds_test').value = "December 11, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"));
|
||||
|
||||
$$('.calendar_date_select td').each(function(e){
|
||||
assert( ! e.hasClassName("disabled"));
|
||||
});
|
||||
|
||||
cds.close();
|
||||
}},
|
||||
test__should_pull_up_dec_07_when_first_day_of_week_is_1: function() {with (this) {
|
||||
Date.first_day_of_week = 1;
|
||||
Date.weekdays = $w("M T W T F S S");
|
||||
$('cds_test').value = "December 1, 2007";
|
||||
cds = new CalendarDateSelect($("cds_test"));
|
||||
|
||||
assertEqual(1, $$(".calendar_date_select").length);
|
||||
cds.close();
|
||||
}}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Format ISO Date Test Cases</title>
|
||||
<script src="../prototype.js" type="text/javascript"></script>
|
||||
<script src="../unittest.js" type="text/javascript"></script>
|
||||
<!-- other JavaScript includes -->
|
||||
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
||||
<script src="../../public/javascripts/calendar_date_select/format_iso_date.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" href="../test.css" type="text/css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- here go any elements you do the testing on -->
|
||||
<div id="cds_test_div">
|
||||
<input type="text" id="cds_test" />
|
||||
</div>
|
||||
|
||||
<!-- Tests -->
|
||||
<script type="text/javascript" language="javascript">
|
||||
// <![CDATA[
|
||||
new Test.Unit.Runner({
|
||||
setup: function() { with(this){
|
||||
}},
|
||||
teardown: function() { with(this){
|
||||
}},
|
||||
testParsing_withTime: function() { with(this) {
|
||||
time = Date.parseFormattedString("2009-01-05 12:30")
|
||||
assertEqual(2009, time.getFullYear());
|
||||
assertEqual(0, time.getMonth());
|
||||
assertEqual(5, time.getDate());
|
||||
assertEqual(12, time.getHours());
|
||||
assertEqual(30, time.getMinutes());
|
||||
}},
|
||||
testParsing_withoutTime: function() { with(this) {
|
||||
time = Date.parseFormattedString("2009-01-05")
|
||||
assertEqual(2009, time.getFullYear());
|
||||
assertEqual(0, time.getMonth());
|
||||
assertEqual(5, time.getDate());
|
||||
}}
|
||||
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
4184
timcharper-calendar_date_select-d3b2b8c/js_test/prototype.js
vendored
Executable file
4184
timcharper-calendar_date_select-d3b2b8c/js_test/prototype.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
40
timcharper-calendar_date_select-d3b2b8c/js_test/test.css
Executable file
40
timcharper-calendar_date_select-d3b2b8c/js_test/test.css
Executable file
@@ -0,0 +1,40 @@
|
||||
body, div, p, h1, h2, h3, ul, ol, span, a, table, td, form, img, li {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size:0.8em;
|
||||
}
|
||||
|
||||
#log {
|
||||
padding-bottom: 1em;
|
||||
border-bottom: 2px solid #000;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
#logsummary {
|
||||
margin-bottom: 1em;
|
||||
padding: 1ex;
|
||||
border: 1px solid #000;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#logtable {
|
||||
width:100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px dotted #666;
|
||||
}
|
||||
|
||||
#logtable td, #logtable th {
|
||||
text-align: left;
|
||||
padding: 3px 8px;
|
||||
border: 1px dotted #666;
|
||||
}
|
||||
|
||||
#logtable .passed {
|
||||
background-color: #cfc;
|
||||
}
|
||||
|
||||
#logtable .failed, #logtable .error {
|
||||
background-color: #fcc;
|
||||
}
|
||||
46
timcharper-calendar_date_select-d3b2b8c/js_test/unit/cds_helper_methods.html
Executable file
46
timcharper-calendar_date_select-d3b2b8c/js_test/unit/cds_helper_methods.html
Executable file
@@ -0,0 +1,46 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Calendar Date Select Test Cases</title>
|
||||
<script src="../prototype.js" type="text/javascript"></script>
|
||||
<script src="../unittest.js" type="text/javascript"></script>
|
||||
<!-- other JavaScript includes -->
|
||||
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
||||
|
||||
<link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../test.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- here go any elements you do the testing on -->
|
||||
<input type="text" id="cds_test" />
|
||||
|
||||
<!-- Tests -->
|
||||
<script type="text/javascript" language="javascript">
|
||||
// <![CDATA[
|
||||
new Test.Unit.Runner({
|
||||
setup: function() { with(this){
|
||||
$("cds_test").value="";
|
||||
$("cds_test").disabled = false;
|
||||
$("cds_test").readOnly = false;
|
||||
}},
|
||||
test_math_floor_to_interval: function() { with(this) {
|
||||
assertEqual(5, Math.floor_to_interval(9,5));
|
||||
assertEqual(5, Math.floor_to_interval(5,5));
|
||||
assertEqual(0, Math.floor_to_interval(1,5));
|
||||
}},
|
||||
test_padded2__should_pad_properly_and_interpret_base_10: function() {with(this) {
|
||||
assertEqual("11", Date.padded2("011"));
|
||||
assertEqual("09", Date.padded2("09"));
|
||||
assertEqual("09", Date.padded2("9"));
|
||||
}}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
564
timcharper-calendar_date_select-d3b2b8c/js_test/unittest.js
Executable file
564
timcharper-calendar_date_select-d3b2b8c/js_test/unittest.js
Executable file
@@ -0,0 +1,564 @@
|
||||
// script.aculo.us unittest.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
|
||||
|
||||
// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
// (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
|
||||
// (c) 2005, 2006 Michael Schuerig (http://www.schuerig.de/michael/)
|
||||
//
|
||||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||||
|
||||
// experimental, Firefox-only
|
||||
Event.simulateMouse = function(element, eventName) {
|
||||
var options = Object.extend({
|
||||
pointerX: 0,
|
||||
pointerY: 0,
|
||||
buttons: 0,
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
shiftKey: false,
|
||||
metaKey: false
|
||||
}, arguments[2] || {});
|
||||
var oEvent = document.createEvent("MouseEvents");
|
||||
oEvent.initMouseEvent(eventName, true, true, document.defaultView,
|
||||
options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
|
||||
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
|
||||
|
||||
if(this.mark) Element.remove(this.mark);
|
||||
this.mark = document.createElement('div');
|
||||
this.mark.appendChild(document.createTextNode(" "));
|
||||
document.body.appendChild(this.mark);
|
||||
this.mark.style.position = 'absolute';
|
||||
this.mark.style.top = options.pointerY + "px";
|
||||
this.mark.style.left = options.pointerX + "px";
|
||||
this.mark.style.width = "5px";
|
||||
this.mark.style.height = "5px;";
|
||||
this.mark.style.borderTop = "1px solid red;"
|
||||
this.mark.style.borderLeft = "1px solid red;"
|
||||
|
||||
if(this.step)
|
||||
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
|
||||
|
||||
$(element).dispatchEvent(oEvent);
|
||||
};
|
||||
|
||||
// Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2.
|
||||
// You need to downgrade to 1.0.4 for now to get this working
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much
|
||||
Event.simulateKey = function(element, eventName) {
|
||||
var options = Object.extend({
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
shiftKey: false,
|
||||
metaKey: false,
|
||||
keyCode: 0,
|
||||
charCode: 0
|
||||
}, arguments[2] || {});
|
||||
|
||||
var oEvent = document.createEvent("KeyEvents");
|
||||
oEvent.initKeyEvent(eventName, true, true, window,
|
||||
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
|
||||
options.keyCode, options.charCode );
|
||||
$(element).dispatchEvent(oEvent);
|
||||
};
|
||||
|
||||
Event.simulateKeys = function(element, command) {
|
||||
for(var i=0; i<command.length; i++) {
|
||||
Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
|
||||
}
|
||||
};
|
||||
|
||||
var Test = {}
|
||||
Test.Unit = {};
|
||||
|
||||
// security exception workaround
|
||||
Test.Unit.inspect = Object.inspect;
|
||||
|
||||
Test.Unit.Logger = Class.create();
|
||||
Test.Unit.Logger.prototype = {
|
||||
initialize: function(log) {
|
||||
this.log = $(log);
|
||||
if (this.log) {
|
||||
this._createLogTable();
|
||||
}
|
||||
},
|
||||
start: function(testName) {
|
||||
if (!this.log) return;
|
||||
this.testName = testName;
|
||||
this.lastLogLine = document.createElement('tr');
|
||||
this.statusCell = document.createElement('td');
|
||||
this.nameCell = document.createElement('td');
|
||||
this.nameCell.className = "nameCell";
|
||||
this.nameCell.appendChild(document.createTextNode(testName));
|
||||
this.messageCell = document.createElement('td');
|
||||
this.lastLogLine.appendChild(this.statusCell);
|
||||
this.lastLogLine.appendChild(this.nameCell);
|
||||
this.lastLogLine.appendChild(this.messageCell);
|
||||
this.loglines.appendChild(this.lastLogLine);
|
||||
},
|
||||
finish: function(status, summary) {
|
||||
if (!this.log) return;
|
||||
this.lastLogLine.className = status;
|
||||
this.statusCell.innerHTML = status;
|
||||
this.messageCell.innerHTML = this._toHTML(summary);
|
||||
this.addLinksToResults();
|
||||
},
|
||||
message: function(message) {
|
||||
if (!this.log) return;
|
||||
this.messageCell.innerHTML = this._toHTML(message);
|
||||
},
|
||||
summary: function(summary) {
|
||||
if (!this.log) return;
|
||||
this.logsummary.innerHTML = this._toHTML(summary);
|
||||
},
|
||||
_createLogTable: function() {
|
||||
this.log.innerHTML =
|
||||
'<div id="logsummary"></div>' +
|
||||
'<table id="logtable">' +
|
||||
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
|
||||
'<tbody id="loglines"></tbody>' +
|
||||
'</table>';
|
||||
this.logsummary = $('logsummary')
|
||||
this.loglines = $('loglines');
|
||||
},
|
||||
_toHTML: function(txt) {
|
||||
return txt.escapeHTML().replace(/\n/g,"<br/>");
|
||||
},
|
||||
addLinksToResults: function(){
|
||||
$$("tr.failed .nameCell").each( function(td){ // todo: limit to children of this.log
|
||||
td.title = "Run only this test"
|
||||
Event.observe(td, 'click', function(){ window.location.search = "?tests=" + td.innerHTML;});
|
||||
});
|
||||
$$("tr.passed .nameCell").each( function(td){ // todo: limit to children of this.log
|
||||
td.title = "Run all tests"
|
||||
Event.observe(td, 'click', function(){ window.location.search = "";});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Test.Unit.Runner = Class.create();
|
||||
Test.Unit.Runner.prototype = {
|
||||
initialize: function(testcases) {
|
||||
this.options = Object.extend({
|
||||
testLog: 'testlog'
|
||||
}, arguments[1] || {});
|
||||
this.options.resultsURL = this.parseResultsURLQueryParameter();
|
||||
this.options.tests = this.parseTestsQueryParameter();
|
||||
if (this.options.testLog) {
|
||||
this.options.testLog = $(this.options.testLog) || null;
|
||||
}
|
||||
if(this.options.tests) {
|
||||
this.tests = [];
|
||||
for(var i = 0; i < this.options.tests.length; i++) {
|
||||
if(/^test/.test(this.options.tests[i])) {
|
||||
this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.options.test) {
|
||||
this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
|
||||
} else {
|
||||
this.tests = [];
|
||||
for(var testcase in testcases) {
|
||||
if(/^test/.test(testcase)) {
|
||||
this.tests.push(
|
||||
new Test.Unit.Testcase(
|
||||
this.options.context ? ' -> ' + this.options.titles[testcase] : testcase,
|
||||
testcases[testcase], testcases["setup"], testcases["teardown"]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.currentTest = 0;
|
||||
this.logger = new Test.Unit.Logger(this.options.testLog);
|
||||
setTimeout(this.runTests.bind(this), 1000);
|
||||
},
|
||||
parseResultsURLQueryParameter: function() {
|
||||
return window.location.search.parseQuery()["resultsURL"];
|
||||
},
|
||||
parseTestsQueryParameter: function(){
|
||||
if (window.location.search.parseQuery()["tests"]){
|
||||
return window.location.search.parseQuery()["tests"].split(',');
|
||||
};
|
||||
},
|
||||
// Returns:
|
||||
// "ERROR" if there was an error,
|
||||
// "FAILURE" if there was a failure, or
|
||||
// "SUCCESS" if there was neither
|
||||
getResult: function() {
|
||||
var hasFailure = false;
|
||||
for(var i=0;i<this.tests.length;i++) {
|
||||
if (this.tests[i].errors > 0) {
|
||||
return "ERROR";
|
||||
}
|
||||
if (this.tests[i].failures > 0) {
|
||||
hasFailure = true;
|
||||
}
|
||||
}
|
||||
if (hasFailure) {
|
||||
return "FAILURE";
|
||||
} else {
|
||||
return "SUCCESS";
|
||||
}
|
||||
},
|
||||
postResults: function() {
|
||||
if (this.options.resultsURL) {
|
||||
new Ajax.Request(this.options.resultsURL,
|
||||
{ method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false });
|
||||
}
|
||||
},
|
||||
runTests: function() {
|
||||
var test = this.tests[this.currentTest];
|
||||
if (!test) {
|
||||
// finished!
|
||||
this.postResults();
|
||||
this.logger.summary(this.summary());
|
||||
return;
|
||||
}
|
||||
if(!test.isWaiting) {
|
||||
this.logger.start(test.name);
|
||||
}
|
||||
test.run();
|
||||
if(test.isWaiting) {
|
||||
this.logger.message("Waiting for " + test.timeToWait + "ms");
|
||||
setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
|
||||
} else {
|
||||
this.logger.finish(test.status(), test.summary());
|
||||
this.currentTest++;
|
||||
// tail recursive, hopefully the browser will skip the stackframe
|
||||
this.runTests();
|
||||
}
|
||||
},
|
||||
summary: function() {
|
||||
var assertions = 0;
|
||||
var failures = 0;
|
||||
var errors = 0;
|
||||
var messages = [];
|
||||
for(var i=0;i<this.tests.length;i++) {
|
||||
assertions += this.tests[i].assertions;
|
||||
failures += this.tests[i].failures;
|
||||
errors += this.tests[i].errors;
|
||||
}
|
||||
return (
|
||||
(this.options.context ? this.options.context + ': ': '') +
|
||||
this.tests.length + " tests, " +
|
||||
assertions + " assertions, " +
|
||||
failures + " failures, " +
|
||||
errors + " errors");
|
||||
}
|
||||
}
|
||||
|
||||
Test.Unit.Assertions = Class.create();
|
||||
Test.Unit.Assertions.prototype = {
|
||||
initialize: function() {
|
||||
this.assertions = 0;
|
||||
this.failures = 0;
|
||||
this.errors = 0;
|
||||
this.messages = [];
|
||||
},
|
||||
summary: function() {
|
||||
return (
|
||||
this.assertions + " assertions, " +
|
||||
this.failures + " failures, " +
|
||||
this.errors + " errors" + "\n" +
|
||||
this.messages.join("\n"));
|
||||
},
|
||||
pass: function() {
|
||||
this.assertions++;
|
||||
},
|
||||
fail: function(message) {
|
||||
this.failures++;
|
||||
this.messages.push("Failure: " + message);
|
||||
},
|
||||
info: function(message) {
|
||||
this.messages.push("Info: " + message);
|
||||
},
|
||||
error: function(error) {
|
||||
this.errors++;
|
||||
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) +")");
|
||||
},
|
||||
status: function() {
|
||||
if (this.failures > 0) return 'failed';
|
||||
if (this.errors > 0) return 'error';
|
||||
return 'passed';
|
||||
},
|
||||
assert: function(expression, message) {
|
||||
var message = arguments[1] || 'assert: got "' + Test.Unit.inspect(expression) + '"' + (message||"");
|
||||
try { expression ? this.pass() :
|
||||
this.fail(message); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertEqual: function(expected, actual, message) {
|
||||
var message = arguments[2] || "assertEqual";
|
||||
try { (expected == actual) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + Test.Unit.inspect(actual) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertInspect: function(expected, actual) {
|
||||
var message = arguments[2] || "assertInspect";
|
||||
try { (expected == actual.inspect()) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + Test.Unit.inspect(actual) + '"'); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertEnumEqual: function(expected, actual) {
|
||||
var message = arguments[2] || "assertEnumEqual";
|
||||
try { $A(expected).length == $A(actual).length &&
|
||||
expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ?
|
||||
this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) +
|
||||
', actual ' + Test.Unit.inspect(actual)); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertNotEqual: function(expected, actual, message) {
|
||||
var message = arguments[2] || "assertNotEqual";
|
||||
try { (expected != actual) ? this.pass() :
|
||||
this.fail(message + ': got "' + Test.Unit.inspect(actual) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertIdentical: function(expected, actual, message) {
|
||||
var message = arguments[2] || "assertIdentical";
|
||||
try { (expected === actual) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + Test.Unit.inspect(actual) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertNotIdentical: function(expected, actual,message) {
|
||||
var message = arguments[2] || "assertNotIdentical";
|
||||
try { !(expected === actual) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + Test.Unit.inspect(actual) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertNull: function(obj, message) {
|
||||
var message = arguments[1] || 'assertNull'
|
||||
try { (obj==null) ? this.pass() :
|
||||
this.fail(message + ': got "' + Test.Unit.inspect(obj) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertMatch: function(expected, actual, message) {
|
||||
var message = arguments[2] || 'assertMatch';
|
||||
var regex = new RegExp(expected);
|
||||
try { (regex.exec(actual)) ? this.pass() :
|
||||
this.fail(message + ' : regex: "' + Test.Unit.inspect(expected) + ' did not match: ' + Test.Unit.inspect(actual) + '"' + (message||"")); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertHidden: function(element) {
|
||||
var message = arguments[1] || 'assertHidden';
|
||||
this.assertEqual("none", element.style.display, message);
|
||||
},
|
||||
assertNotNull: function(object) {
|
||||
var message = arguments[1] || 'assertNotNull';
|
||||
this.assert(object != null, message);
|
||||
},
|
||||
assertType: function(expected, actual) {
|
||||
var message = arguments[2] || 'assertType';
|
||||
try {
|
||||
(actual.constructor == expected) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + (actual.constructor) + '"'); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertNotOfType: function(expected, actual) {
|
||||
var message = arguments[2] || 'assertNotOfType';
|
||||
try {
|
||||
(actual.constructor != expected) ? this.pass() :
|
||||
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
|
||||
'", actual "' + (actual.constructor) + '"'); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertInstanceOf: function(expected, actual) {
|
||||
var message = arguments[2] || 'assertInstanceOf';
|
||||
try {
|
||||
(actual instanceof expected) ? this.pass() :
|
||||
this.fail(message + ": object was not an instance of the expected type"); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertNotInstanceOf: function(expected, actual) {
|
||||
var message = arguments[2] || 'assertNotInstanceOf';
|
||||
try {
|
||||
!(actual instanceof expected) ? this.pass() :
|
||||
this.fail(message + ": object was an instance of the not expected type"); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertRespondsTo: function(method, obj) {
|
||||
var message = arguments[2] || 'assertRespondsTo';
|
||||
try {
|
||||
(obj[method] && typeof obj[method] == 'function') ? this.pass() :
|
||||
this.fail(message + ": object doesn't respond to [" + method + "]"); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertReturnsTrue: function(method, obj) {
|
||||
var message = arguments[2] || 'assertReturnsTrue';
|
||||
try {
|
||||
var m = obj[method];
|
||||
if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
m() ? this.pass() :
|
||||
this.fail(message + ": method returned false"); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertReturnsFalse: function(method, obj) {
|
||||
var message = arguments[2] || 'assertReturnsFalse';
|
||||
try {
|
||||
var m = obj[method];
|
||||
if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
!m() ? this.pass() :
|
||||
this.fail(message + ": method returned true"); }
|
||||
catch(e) { this.error(e); }
|
||||
},
|
||||
assertRaise: function(exceptionName, method) {
|
||||
var message = arguments[2] || 'assertRaise';
|
||||
try {
|
||||
method();
|
||||
this.fail(message + ": exception expected but none was raised"); }
|
||||
catch(e) {
|
||||
((exceptionName == null) || (e.name==exceptionName)) ? this.pass() : this.error(e);
|
||||
}
|
||||
},
|
||||
assertElementsMatch: function() {
|
||||
var expressions = $A(arguments), elements = $A(expressions.shift());
|
||||
if (elements.length != expressions.length) {
|
||||
this.fail('assertElementsMatch: size mismatch: ' + elements.length + ' elements, ' + expressions.length + ' expressions');
|
||||
return false;
|
||||
}
|
||||
elements.zip(expressions).all(function(pair, index) {
|
||||
var element = $(pair.first()), expression = pair.last();
|
||||
if (element.match(expression)) return true;
|
||||
this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect());
|
||||
}.bind(this)) && this.pass();
|
||||
},
|
||||
assertElementMatches: function(element, expression) {
|
||||
this.assertElementsMatch([element], expression);
|
||||
},
|
||||
benchmark: function(operation, iterations) {
|
||||
var startAt = new Date();
|
||||
(iterations || 1).times(operation);
|
||||
var timeTaken = ((new Date())-startAt);
|
||||
this.info((arguments[2] || 'Operation') + ' finished ' +
|
||||
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
|
||||
return timeTaken;
|
||||
},
|
||||
_isVisible: function(element) {
|
||||
element = $(element);
|
||||
if(!element.parentNode) return true;
|
||||
this.assertNotNull(element);
|
||||
if(element.style && Element.getStyle(element, 'display') == 'none')
|
||||
return false;
|
||||
|
||||
return this._isVisible(element.parentNode);
|
||||
},
|
||||
assertNotVisible: function(element) {
|
||||
this.assert(!this._isVisible(element), Test.Unit.inspect(element) + " was not hidden and didn't have a hidden parent either. " + ("" || arguments[1]));
|
||||
},
|
||||
assertVisible: function(element) {
|
||||
this.assert(this._isVisible(element), Test.Unit.inspect(element) + " was not visible. " + ("" || arguments[1]));
|
||||
},
|
||||
benchmark: function(operation, iterations) {
|
||||
var startAt = new Date();
|
||||
(iterations || 1).times(operation);
|
||||
var timeTaken = ((new Date())-startAt);
|
||||
this.info((arguments[2] || 'Operation') + ' finished ' +
|
||||
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
|
||||
return timeTaken;
|
||||
}
|
||||
}
|
||||
|
||||
Test.Unit.Testcase = Class.create();
|
||||
Object.extend(Object.extend(Test.Unit.Testcase.prototype, Test.Unit.Assertions.prototype), {
|
||||
initialize: function(name, test, setup, teardown) {
|
||||
Test.Unit.Assertions.prototype.initialize.bind(this)();
|
||||
this.name = name;
|
||||
|
||||
if(typeof test == 'string') {
|
||||
test = test.gsub(/(\.should[^\(]+\()/,'#{0}this,');
|
||||
test = test.gsub(/(\.should[^\(]+)\(this,\)/,'#{1}(this)');
|
||||
this.test = function() {
|
||||
eval('with(this){'+test+'}');
|
||||
}
|
||||
} else {
|
||||
this.test = test || function() {};
|
||||
}
|
||||
|
||||
this.setup = setup || function() {};
|
||||
this.teardown = teardown || function() {};
|
||||
this.isWaiting = false;
|
||||
this.timeToWait = 1000;
|
||||
},
|
||||
wait: function(time, nextPart) {
|
||||
this.isWaiting = true;
|
||||
this.test = nextPart;
|
||||
this.timeToWait = time;
|
||||
},
|
||||
run: function() {
|
||||
try {
|
||||
try {
|
||||
if (!this.isWaiting) this.setup.bind(this)();
|
||||
this.isWaiting = false;
|
||||
this.test.bind(this)();
|
||||
} finally {
|
||||
if(!this.isWaiting) {
|
||||
this.teardown.bind(this)();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e) { this.error(e); }
|
||||
}
|
||||
});
|
||||
|
||||
// *EXPERIMENTAL* BDD-style testing to please non-technical folk
|
||||
// This draws many ideas from RSpec http://rspec.rubyforge.org/
|
||||
|
||||
Test.setupBDDExtensionMethods = function(){
|
||||
var METHODMAP = {
|
||||
shouldEqual: 'assertEqual',
|
||||
shouldNotEqual: 'assertNotEqual',
|
||||
shouldEqualEnum: 'assertEnumEqual',
|
||||
shouldBeA: 'assertType',
|
||||
shouldNotBeA: 'assertNotOfType',
|
||||
shouldBeAn: 'assertType',
|
||||
shouldNotBeAn: 'assertNotOfType',
|
||||
shouldBeNull: 'assertNull',
|
||||
shouldNotBeNull: 'assertNotNull',
|
||||
|
||||
shouldBe: 'assertReturnsTrue',
|
||||
shouldNotBe: 'assertReturnsFalse',
|
||||
shouldRespondTo: 'assertRespondsTo'
|
||||
};
|
||||
Test.BDDMethods = {};
|
||||
for(m in METHODMAP) {
|
||||
Test.BDDMethods[m] = eval(
|
||||
'function(){'+
|
||||
'var args = $A(arguments);'+
|
||||
'var scope = args.shift();'+
|
||||
'scope.'+METHODMAP[m]+'.apply(scope,(args || []).concat([this])); }');
|
||||
}
|
||||
[Array.prototype, String.prototype, Number.prototype].each(
|
||||
function(p){ Object.extend(p, Test.BDDMethods) }
|
||||
);
|
||||
}
|
||||
|
||||
Test.context = function(name, spec, log){
|
||||
Test.setupBDDExtensionMethods();
|
||||
|
||||
var compiledSpec = {};
|
||||
var titles = {};
|
||||
for(specName in spec) {
|
||||
switch(specName){
|
||||
case "setup":
|
||||
case "teardown":
|
||||
compiledSpec[specName] = spec[specName];
|
||||
break;
|
||||
default:
|
||||
var testName = 'test'+specName.gsub(/\s+/,'-').camelize();
|
||||
var body = spec[specName].toString().split('\n').slice(1);
|
||||
if(/^\{/.test(body[0])) body = body.slice(1);
|
||||
body.pop();
|
||||
body = body.map(function(statement){
|
||||
return statement.strip()
|
||||
});
|
||||
compiledSpec[testName] = body.join('\n');
|
||||
titles[testName] = specName;
|
||||
}
|
||||
}
|
||||
new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
|
||||
};
|
||||
Reference in New Issue
Block a user