ginkel-calendar_date_select 1.16.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/History.txt +270 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +42 -0
- data/README.txt +16 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/calendar_date_select.gemspec +99 -0
- data/init.rb +1 -0
- data/js_test/functional/.tmp_cds_test.html +306 -0
- data/js_test/functional/cds_test.html +365 -0
- data/js_test/functional/format_iso_date_test.html +52 -0
- data/js_test/prototype.js +4184 -0
- data/js_test/test.css +40 -0
- data/js_test/unit/cds_helper_methods.html +46 -0
- data/js_test/unittest.js +564 -0
- data/lib/calendar_date_select.rb +33 -0
- data/lib/calendar_date_select/calendar_date_select.rb +122 -0
- data/lib/calendar_date_select/form_helpers.rb +240 -0
- data/lib/calendar_date_select/includes_helper.rb +29 -0
- data/public/blank_iframe.html +2 -0
- data/public/images/calendar_date_select/calendar.gif +0 -0
- data/public/javascripts/calendar_date_select/calendar_date_select.js +448 -0
- data/public/javascripts/calendar_date_select/format_american.js +35 -0
- data/public/javascripts/calendar_date_select/format_danish.js +31 -0
- data/public/javascripts/calendar_date_select/format_db.js +27 -0
- data/public/javascripts/calendar_date_select/format_euro_24hr.js +7 -0
- data/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js +7 -0
- data/public/javascripts/calendar_date_select/format_finnish.js +32 -0
- data/public/javascripts/calendar_date_select/format_hyphen_ampm.js +37 -0
- data/public/javascripts/calendar_date_select/format_iso_date.js +29 -0
- data/public/javascripts/calendar_date_select/format_italian.js +24 -0
- data/public/javascripts/calendar_date_select/locale/ar.js +10 -0
- data/public/javascripts/calendar_date_select/locale/da.js +11 -0
- data/public/javascripts/calendar_date_select/locale/de.js +11 -0
- data/public/javascripts/calendar_date_select/locale/es.js +11 -0
- data/public/javascripts/calendar_date_select/locale/fi.js +10 -0
- data/public/javascripts/calendar_date_select/locale/fr.js +11 -0
- data/public/javascripts/calendar_date_select/locale/it.js +9 -0
- data/public/javascripts/calendar_date_select/locale/ja.js +11 -0
- data/public/javascripts/calendar_date_select/locale/nl.js +11 -0
- data/public/javascripts/calendar_date_select/locale/pl.js +11 -0
- data/public/javascripts/calendar_date_select/locale/pt.js +11 -0
- data/public/javascripts/calendar_date_select/locale/ru.js +10 -0
- data/public/javascripts/calendar_date_select/locale/sl.js +11 -0
- data/public/javascripts/calendar_date_select/locale/sv.js +9 -0
- data/public/stylesheets/calendar_date_select/blue.css +130 -0
- data/public/stylesheets/calendar_date_select/default.css +135 -0
- data/public/stylesheets/calendar_date_select/green.css +142 -0
- data/public/stylesheets/calendar_date_select/plain.css +128 -0
- data/public/stylesheets/calendar_date_select/red.css +135 -0
- data/public/stylesheets/calendar_date_select/silver.css +133 -0
- data/spec/calendar_date_select/calendar_date_select_spec.rb +14 -0
- data/spec/calendar_date_select/form_helpers_spec.rb +189 -0
- data/spec/calendar_date_select/includes_helper_spec.rb +46 -0
- data/spec/spec_helper.rb +26 -0
- metadata +130 -0
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/calendar_date_select.rb"
|
@@ -0,0 +1,306 @@
|
|
1
|
+
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>Calendar Date Select Test Cases</title>
|
7
|
+
<script src="../prototype.js" type="text/javascript"></script>
|
8
|
+
<script src="../unittest.js" type="text/javascript"></script>
|
9
|
+
<!-- other JavaScript includes -->
|
10
|
+
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
11
|
+
|
12
|
+
<link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
|
13
|
+
<link rel="stylesheet" href="../test.css" type="text/css" />
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
|
17
|
+
<!-- Log output -->
|
18
|
+
<div id="testlog"> </div>
|
19
|
+
|
20
|
+
<!-- here go any elements you do the testing on -->
|
21
|
+
<div id="cds_test_div">
|
22
|
+
<input type="text" id="cds_test" />
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<!-- Tests -->
|
26
|
+
<script type="text/javascript" language="javascript">
|
27
|
+
// <![CDATA[
|
28
|
+
new Test.Unit.Runner({
|
29
|
+
setup: function() { with(this){
|
30
|
+
$("cds_test").value="";
|
31
|
+
$("cds_test").disabled = false;
|
32
|
+
$("cds_test").readOnly = false;
|
33
|
+
}},
|
34
|
+
teardown: function() { with(this){
|
35
|
+
if (typeof(cds)!="undefined")
|
36
|
+
assert(cds.closed,"all tests should close their calendar control");
|
37
|
+
}},
|
38
|
+
testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
|
39
|
+
$A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
|
40
|
+
$("cds_test").value=d;
|
41
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
42
|
+
assertEqual(true, cds.use_time);
|
43
|
+
cds.close();
|
44
|
+
})
|
45
|
+
|
46
|
+
$("cds_test").value="January 2, 2007";
|
47
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
48
|
+
assertEqual(false, cds.use_time);
|
49
|
+
cds.close();
|
50
|
+
}},
|
51
|
+
testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
|
52
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
53
|
+
today_now = $$(".cds_buttons a[href=#]");
|
54
|
+
today_now[0].onclick();
|
55
|
+
assertEqual(false, cds.use_time, "when clicking today link");
|
56
|
+
|
57
|
+
today_now[1].onclick();
|
58
|
+
assertEqual(true, cds.use_time, "should have been true when clicking now link");
|
59
|
+
cds.close();
|
60
|
+
}},
|
61
|
+
test__selectMar_23_2008__shouldSelectCorrectDate: function() { with(this){
|
62
|
+
$("cds_test").value = "Mar 1, 2008"
|
63
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "true"});
|
64
|
+
cds.updateSelectedDate({month: 2 /*+1*/, day: 23, year: 2008})
|
65
|
+
|
66
|
+
assertEqual("23", $$('td.selected div').first().innerHTML);
|
67
|
+
cds.close();
|
68
|
+
}},
|
69
|
+
test_updateSelectedDate: function() { with(this){
|
70
|
+
$("cds_test").value = "January 1, 2007"
|
71
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
72
|
+
|
73
|
+
cds.use_time=true;
|
74
|
+
cds.updateSelectedDate({hour: ""})
|
75
|
+
assertEqual(false, cds.use_time, "when setting hour to ''");
|
76
|
+
|
77
|
+
cds.use_time=true;
|
78
|
+
cds.updateSelectedDate({minute: ""})
|
79
|
+
assertEqual(false, cds.use_time, "when setting minute to ''");
|
80
|
+
|
81
|
+
cds.use_time=false;
|
82
|
+
cds.updateSelectedDate({hour: 0})
|
83
|
+
assertEqual(true, cds.use_time, "when setting hour to 0");
|
84
|
+
|
85
|
+
cds.use_time=false;
|
86
|
+
cds.updateSelectedDate({minute: 0})
|
87
|
+
assertEqual(true, cds.use_time, "when setting minute to 0");
|
88
|
+
|
89
|
+
cds.close();
|
90
|
+
}},
|
91
|
+
test_navYear: function() { with(this){
|
92
|
+
$("cds_test").value = "January 1, 2007";
|
93
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
94
|
+
cds.navYear(1870);
|
95
|
+
assertEqual(2007, cds.selected_date.getFullYear());
|
96
|
+
assertEqual(1870, cds.date.getFullYear());
|
97
|
+
cds.close();
|
98
|
+
}},
|
99
|
+
test_navMonth: function() { with(this){
|
100
|
+
$("cds_test").value = "January 1, 2007";
|
101
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
102
|
+
cds.navMonth(5);
|
103
|
+
assertEqual(0, cds.selected_date.getMonth());
|
104
|
+
assertEqual(5, cds.date.getMonth())
|
105
|
+
cds.close();
|
106
|
+
}},
|
107
|
+
test_callBacks: function() { with(this){
|
108
|
+
$("cds_test").up().build("div", {id: "global"});
|
109
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
110
|
+
before_show: function() { $("global").before_show_called = true},
|
111
|
+
after_show: function() { $("global").after_show_called = true},
|
112
|
+
before_close: function() { $("global").before_close_called = true},
|
113
|
+
after_close: function() { $("global").after_close_called = true},
|
114
|
+
after_navigate: function() { $("global").after_navigate_called = true},
|
115
|
+
onchange: function() { $("global").onchange_called = true},
|
116
|
+
});
|
117
|
+
cds.navMonth(1);
|
118
|
+
cds.navMonth(10);
|
119
|
+
cds.updateSelectedDate({month: 1, day: 3, year: 2007});
|
120
|
+
cds.close();
|
121
|
+
assert($('global').before_show_called, "before_show wasnt called");
|
122
|
+
assert($('global').after_show_called, "after_show wasnt called");
|
123
|
+
assert($('global').before_close_called, "before_close wasnt called");
|
124
|
+
assert($('global').after_close_called, "after_close wasnt called");
|
125
|
+
assert($('global').after_navigate_called, "after_navigate wasnt called");
|
126
|
+
assert($('global').onchange_called, "onchange wasnt called");
|
127
|
+
$("global").remove();
|
128
|
+
}},
|
129
|
+
test_disabledElement_cantUpdate: function() {with(this){
|
130
|
+
$("cds_test").value = "May 10, 2007";
|
131
|
+
$("cds_test").disabled = true;
|
132
|
+
cds = new CalendarDateSelect($("cds_test"));
|
133
|
+
|
134
|
+
runTest = function() {
|
135
|
+
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
136
|
+
assertEqual(10, cds.selected_date.getDate())
|
137
|
+
}
|
138
|
+
runTest();
|
139
|
+
$("cds_test").disabled = false;
|
140
|
+
$("cds_test").readOnly = true;
|
141
|
+
runTest();
|
142
|
+
|
143
|
+
$("cds_test").readOnly = false;
|
144
|
+
cds.close();
|
145
|
+
}},
|
146
|
+
test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
|
147
|
+
$("cds_test").value = "May 10, 2007";
|
148
|
+
$("cds_test").readOnly = true;
|
149
|
+
cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
|
150
|
+
|
151
|
+
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
152
|
+
assertEqual(1, cds.selected_date.getDate())
|
153
|
+
|
154
|
+
$("cds_test").readOnly = false;
|
155
|
+
cds.close();
|
156
|
+
}},
|
157
|
+
test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
|
158
|
+
$("cds_test").value = "May 10, 2007 5:00 pm";
|
159
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
160
|
+
assert(cds.options.get("close_on_click"), "should set close_on_click to true when not using time")
|
161
|
+
assertEqual(false, cds.use_time, "When parsing time");
|
162
|
+
cds.today();
|
163
|
+
assert(cds.closed, "should close when clicking today");
|
164
|
+
assert(!cds.use_time, "Should not use time when calling today");
|
165
|
+
|
166
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
167
|
+
cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
|
168
|
+
assertEqual(false, cds.use_time, "When setting hour/minute");
|
169
|
+
assert(cds.closed);
|
170
|
+
}},
|
171
|
+
test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
|
172
|
+
$("cds_test").value = "May 10, 2007 5:00 pm";
|
173
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
174
|
+
assertEqual(false, cds.use_time, "When parsing time");
|
175
|
+
cds.setUseTime(true); // this will close the control
|
176
|
+
assert(! cds.use_time, "After calling setUseTime(true)");
|
177
|
+
cds.close();
|
178
|
+
}},
|
179
|
+
test_setMinute_notOnInterval_usesFloor: function() {with(this){
|
180
|
+
$("cds_test").value = "May 10, 2007 5:25 pm";
|
181
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
182
|
+
cds.updateSelectedDate({hour: 1, minute: 4});
|
183
|
+
assertEqual(0, cds.selected_date.getMinutes());
|
184
|
+
assertEqual(1, cds.selected_date.getHours());
|
185
|
+
|
186
|
+
cds.close();
|
187
|
+
}},
|
188
|
+
// this checks for a safari 2 bug where safari parses "" as a date back in 1969
|
189
|
+
test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
|
190
|
+
$("cds_test").value = " ";
|
191
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
192
|
+
assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
|
193
|
+
assertEqual(new Date().getFullYear(), cds.date.getFullYear());
|
194
|
+
assert(! cds.selection_made)
|
195
|
+
cds.close();
|
196
|
+
}},
|
197
|
+
test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
|
198
|
+
$("cds_test").value = "December 1, 2007 ";
|
199
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
200
|
+
assert(cds.use_time)
|
201
|
+
cds.close();
|
202
|
+
}},
|
203
|
+
test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
|
204
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
205
|
+
assertEqual("INPUT", cds.target_element.nodeName)
|
206
|
+
cds.close();
|
207
|
+
}},
|
208
|
+
test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
|
209
|
+
$("cds_test").value = "July 4, 1776";
|
210
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
211
|
+
assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
|
212
|
+
assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
|
213
|
+
cds.close();
|
214
|
+
}},
|
215
|
+
test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
|
216
|
+
$("cds_test").value = "January 1, 2007";
|
217
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
|
218
|
+
|
219
|
+
assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
|
220
|
+
assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
|
221
|
+
assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
|
222
|
+
assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
|
223
|
+
assert(cds.navMonth(1), "should allow me to be in boundary");
|
224
|
+
assert(cds.navYear(2007), "should allow me to be in boundary");
|
225
|
+
cds.close();
|
226
|
+
}},
|
227
|
+
test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
|
228
|
+
$("cds_test").value = "January 1, 2007";
|
229
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
|
230
|
+
assert(cds.year_select.setValue(2007), "should allow me to select 2007");
|
231
|
+
cds.close();
|
232
|
+
}},
|
233
|
+
test__nonflexibleYearRange__initializedWithDateOutsideOfRange__shouldShowNavDateAsClosestToOutsideYear: function() {with(this){
|
234
|
+
$("cds_test").value = "January 1, 1900";
|
235
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [1997, 2007]});
|
236
|
+
assertEqual(1997, cds.date.getFullYear(), "When going lesser than year_range");
|
237
|
+
cds.close();
|
238
|
+
|
239
|
+
$("cds_test").value = "January 1, 2010";
|
240
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [1997, 2007]});
|
241
|
+
assertEqual(2007, cds.date.getFullYear(), "When going greater than year_range");
|
242
|
+
|
243
|
+
cds.close();
|
244
|
+
}},
|
245
|
+
test__nonflexibleYearRange__initializedWithDateInsideOfRange__shouldShowNavDateAsYear: function() {with(this){
|
246
|
+
$("cds_test").value = "January 1, 2005";
|
247
|
+
cds = new CalendarDateSelect($("cds_test_div"), {year_range: [1997, 2007]});
|
248
|
+
assertEqual(2005, cds.date.getFullYear(), "When going lesser than year_range");
|
249
|
+
cds.close();
|
250
|
+
}},
|
251
|
+
test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
|
252
|
+
$("cds_test").value = "January 1, 2007";
|
253
|
+
cds = new CalendarDateSelect($("cds_test_div"), {year_range: 10});
|
254
|
+
cds.navYear(1997);
|
255
|
+
assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
|
256
|
+
cds.navYear(2017);
|
257
|
+
assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
|
258
|
+
cds.close();
|
259
|
+
}},
|
260
|
+
test__should_show_iframe_only_in_ie: function() {with(this){
|
261
|
+
cds = new CalendarDateSelect($("cds_test_div"));
|
262
|
+
|
263
|
+
if (navigator.appName=="Microsoft Internet Explorer")
|
264
|
+
assertEqual(1, $$('iframe.ie6_blocker').length)
|
265
|
+
else
|
266
|
+
assertEqual(0, $$('iframe.ie6_blocker').length)
|
267
|
+
|
268
|
+
cds.close();
|
269
|
+
}},
|
270
|
+
test__should_populate_minute_box_according_to_minute_interval: function() {with(this){
|
271
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time: true, minute_interval: 10});
|
272
|
+
assert(cds.minute_select.setValue(0), "should allow me to select 0 minutes" );
|
273
|
+
assert(!cds.minute_select.setValue(5), "should NOT allow me to select 5 minutes");
|
274
|
+
assert(cds.minute_select.setValue(10), "should allow me to select 10 minutes" );
|
275
|
+
cds.close();
|
276
|
+
}},
|
277
|
+
test__shouldnt_leak_variables: function() {with (this) {
|
278
|
+
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")
|
279
|
+
vars.each(function(v) {eval(v + " = -100");});
|
280
|
+
|
281
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time: true});
|
282
|
+
cds.navMonth(1);
|
283
|
+
cds.navYear(2);
|
284
|
+
cds.dayHover($$('.cds_body td').first());
|
285
|
+
cds.updateSelectedDate({day:1, month:1, year:2007});
|
286
|
+
cds.close();
|
287
|
+
|
288
|
+
vars.each(function(v) {
|
289
|
+
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
290
|
+
});
|
291
|
+
}},
|
292
|
+
test__valid_date__shouldnt_allow_selection_of_invalid_dates_and_should_apply_css: function() {with (this) {
|
293
|
+
$('cds_test').value = "December 11, 2007";
|
294
|
+
cds = new CalendarDateSelect($("cds_test_div"), {valid_date_check: function(date) { date < new Date("December 13, 2007")}});
|
295
|
+
cds.updateSelectedDate({day:13, month:12-1, year:2007});
|
296
|
+
cds.close();
|
297
|
+
|
298
|
+
vars.each(function(v) {
|
299
|
+
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
300
|
+
});
|
301
|
+
}}
|
302
|
+
});
|
303
|
+
// ]]>
|
304
|
+
</script>
|
305
|
+
</body>
|
306
|
+
</html>
|
@@ -0,0 +1,365 @@
|
|
1
|
+
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>Calendar Date Select Test Cases</title>
|
7
|
+
<script src="../prototype.js" type="text/javascript"></script>
|
8
|
+
<script src="../unittest.js" type="text/javascript"></script>
|
9
|
+
<!-- other JavaScript includes -->
|
10
|
+
<script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
|
11
|
+
|
12
|
+
<link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
|
13
|
+
<link rel="stylesheet" href="../test.css" type="text/css" />
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
|
17
|
+
<!-- Log output -->
|
18
|
+
<div id="testlog"> </div>
|
19
|
+
|
20
|
+
<!-- here go any elements you do the testing on -->
|
21
|
+
<div id="cds_test_div">
|
22
|
+
<input type="text" id="cds_test" />
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<!-- Tests -->
|
26
|
+
<script type="text/javascript" language="javascript">
|
27
|
+
// <![CDATA[
|
28
|
+
new Test.Unit.Runner({
|
29
|
+
setup: function() { with(this){
|
30
|
+
$("cds_test").value="";
|
31
|
+
$("cds_test").disabled = false;
|
32
|
+
$("cds_test").readOnly = false;
|
33
|
+
}},
|
34
|
+
teardown: function() { with(this){
|
35
|
+
if (typeof(cds)!="undefined") assert(cds.closed,"all tests should close their calendar control");
|
36
|
+
Date.first_day_of_week = 0;
|
37
|
+
Date.weekdays = $w("S M T W T F S")
|
38
|
+
}},
|
39
|
+
testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
|
40
|
+
$A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
|
41
|
+
$("cds_test").value=d;
|
42
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
43
|
+
assertEqual(true, cds.use_time);
|
44
|
+
cds.close();
|
45
|
+
})
|
46
|
+
|
47
|
+
$("cds_test").value="January 2, 2007";
|
48
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
49
|
+
assertEqual(false, cds.use_time);
|
50
|
+
cds.close();
|
51
|
+
}},
|
52
|
+
testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
|
53
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
54
|
+
today_now = $$(".cds_buttons a[href=#]");
|
55
|
+
today_now[0].onclick();
|
56
|
+
assertEqual(false, cds.use_time, "when clicking today link");
|
57
|
+
|
58
|
+
today_now[1].onclick();
|
59
|
+
assertEqual(true, cds.use_time, "should have been true when clicking now link");
|
60
|
+
cds.close();
|
61
|
+
}},
|
62
|
+
test__selectMar_23_2008__shouldSelectCorrectDate: function() { with(this){
|
63
|
+
$("cds_test").value = "Mar 1, 2008"
|
64
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "true"});
|
65
|
+
cds.updateSelectedDate({month: 2 /*+1*/, day: 23, year: 2008})
|
66
|
+
|
67
|
+
assertEqual("23", $$('td.selected div').first().innerHTML);
|
68
|
+
cds.close();
|
69
|
+
}},
|
70
|
+
test_updateSelectedDate: function() { with(this){
|
71
|
+
$("cds_test").value = "January 1, 2007"
|
72
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
73
|
+
|
74
|
+
cds.use_time=true;
|
75
|
+
cds.updateSelectedDate({hour: ""})
|
76
|
+
assertEqual(false, cds.use_time, "when setting hour to ''");
|
77
|
+
|
78
|
+
cds.use_time=true;
|
79
|
+
cds.updateSelectedDate({minute: ""})
|
80
|
+
assertEqual(false, cds.use_time, "when setting minute to ''");
|
81
|
+
|
82
|
+
cds.use_time=false;
|
83
|
+
cds.updateSelectedDate({hour: 0})
|
84
|
+
assertEqual(true, cds.use_time, "when setting hour to 0");
|
85
|
+
|
86
|
+
cds.use_time=false;
|
87
|
+
cds.updateSelectedDate({minute: 0})
|
88
|
+
assertEqual(true, cds.use_time, "when setting minute to 0");
|
89
|
+
|
90
|
+
cds.close();
|
91
|
+
}},
|
92
|
+
test_navYear: function() { with(this){
|
93
|
+
$("cds_test").value = "January 1, 2007";
|
94
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
95
|
+
cds.navYear(1870);
|
96
|
+
assertEqual(2007, cds.selected_date.getFullYear());
|
97
|
+
assertEqual(1870, cds.date.getFullYear());
|
98
|
+
cds.close();
|
99
|
+
}},
|
100
|
+
test_navMonth: function() { with(this){
|
101
|
+
$("cds_test").value = "January 1, 2007";
|
102
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
|
103
|
+
cds.navMonth(5);
|
104
|
+
assertEqual(0, cds.selected_date.getMonth());
|
105
|
+
assertEqual(5, cds.date.getMonth())
|
106
|
+
cds.close();
|
107
|
+
}},
|
108
|
+
test_callBacks: function() { with(this){
|
109
|
+
$("cds_test").up().build("div", {id: "global"});
|
110
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
111
|
+
before_show: function() { $("global").before_show_called = true},
|
112
|
+
after_show: function() { $("global").after_show_called = true},
|
113
|
+
before_close: function() { $("global").before_close_called = true},
|
114
|
+
after_close: function() { $("global").after_close_called = true},
|
115
|
+
after_navigate: function() { $("global").after_navigate_called = true},
|
116
|
+
onchange: function() { $("global").onchange_called = true},
|
117
|
+
});
|
118
|
+
cds.navMonth(1);
|
119
|
+
cds.navMonth(10);
|
120
|
+
cds.updateSelectedDate({month: 1, day: 3, year: 2007});
|
121
|
+
cds.close();
|
122
|
+
assert($('global').before_show_called, "before_show wasnt called");
|
123
|
+
assert($('global').after_show_called, "after_show wasnt called");
|
124
|
+
assert($('global').before_close_called, "before_close wasnt called");
|
125
|
+
assert($('global').after_close_called, "after_close wasnt called");
|
126
|
+
assert($('global').after_navigate_called, "after_navigate wasnt called");
|
127
|
+
assert($('global').onchange_called, "onchange wasnt called");
|
128
|
+
$("global").remove();
|
129
|
+
}},
|
130
|
+
test_onchangeCallbackChangedOnclear: function() { with(this){
|
131
|
+
$("cds_test").up().build("div", {id: "global"});
|
132
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
133
|
+
onchange: function() { $("global").onchange_called = true},
|
134
|
+
});
|
135
|
+
$("cds_test").value = "";
|
136
|
+
cds.clearDate();
|
137
|
+
assert( ! $('global').onchange_called, "onchange was called, when the value wasn't actually changed");
|
138
|
+
$("cds_test").value = "boogy";
|
139
|
+
cds.clearDate();
|
140
|
+
assert( $('global').onchange_called, "onchange wasnt called, but should ahve been");
|
141
|
+
cds.close();
|
142
|
+
$("global").remove();
|
143
|
+
}},
|
144
|
+
|
145
|
+
test_disabledElement_cantUpdate: function() {with(this){
|
146
|
+
$("cds_test").value = "May 10, 2007";
|
147
|
+
$("cds_test").disabled = true;
|
148
|
+
cds = new CalendarDateSelect($("cds_test"));
|
149
|
+
|
150
|
+
runTest = function() {
|
151
|
+
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
152
|
+
assertEqual(10, cds.selected_date.getDate())
|
153
|
+
}
|
154
|
+
runTest();
|
155
|
+
$("cds_test").disabled = false;
|
156
|
+
$("cds_test").readOnly = true;
|
157
|
+
runTest();
|
158
|
+
|
159
|
+
$("cds_test").readOnly = false;
|
160
|
+
cds.close();
|
161
|
+
}},
|
162
|
+
test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
|
163
|
+
$("cds_test").value = "May 10, 2007";
|
164
|
+
$("cds_test").readOnly = true;
|
165
|
+
cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
|
166
|
+
|
167
|
+
cds.updateSelectedDate({day: 1, month:0, year: 2007});
|
168
|
+
assertEqual(1, cds.selected_date.getDate())
|
169
|
+
|
170
|
+
$("cds_test").readOnly = false;
|
171
|
+
cds.close();
|
172
|
+
}},
|
173
|
+
test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
|
174
|
+
$("cds_test").value = "May 10, 2007 5:00 pm";
|
175
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
176
|
+
assert(cds.closeOnClick(), "should set close_on_click to true when not using time")
|
177
|
+
assertEqual(false, cds.use_time, "When parsing time");
|
178
|
+
cds.today();
|
179
|
+
assert(cds.closed, "should close when clicking today");
|
180
|
+
assert(!cds.use_time, "Should not use time when calling today");
|
181
|
+
|
182
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
183
|
+
cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
|
184
|
+
assertEqual(false, cds.use_time, "When setting hour/minute");
|
185
|
+
assert(cds.closed);
|
186
|
+
}},
|
187
|
+
test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
|
188
|
+
$("cds_test").value = "May 10, 2007 5:00 pm";
|
189
|
+
cds = new CalendarDateSelect($("cds_test"), {time:false});
|
190
|
+
assertEqual(false, cds.use_time, "When parsing time");
|
191
|
+
cds.setUseTime(true); // this will close the control
|
192
|
+
assert(! cds.use_time, "After calling setUseTime(true)");
|
193
|
+
cds.close();
|
194
|
+
}},
|
195
|
+
test_setMinute_notOnInterval_usesFloor: function() {with(this){
|
196
|
+
$("cds_test").value = "May 10, 2007 5:25 pm";
|
197
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
198
|
+
cds.updateSelectedDate({hour: 1, minute: 4});
|
199
|
+
assertEqual(0, cds.selected_date.getMinutes());
|
200
|
+
assertEqual(1, cds.selected_date.getHours());
|
201
|
+
|
202
|
+
cds.close();
|
203
|
+
}},
|
204
|
+
// this checks for a safari 2 bug where safari parses "" as a date back in 1969
|
205
|
+
test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
|
206
|
+
$("cds_test").value = " ";
|
207
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
208
|
+
assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
|
209
|
+
assertEqual(new Date().getFullYear(), cds.date.getFullYear());
|
210
|
+
assert(! cds.selection_made)
|
211
|
+
cds.close();
|
212
|
+
}},
|
213
|
+
test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
|
214
|
+
$("cds_test").value = "December 1, 2007 ";
|
215
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true});
|
216
|
+
assert(cds.use_time)
|
217
|
+
cds.close();
|
218
|
+
}},
|
219
|
+
test_parseDate_defaultTime_javaScriptFunctionPassed_shouldReturnDateFromJavaScriptFunction: function() {with(this){
|
220
|
+
$("cds_test").value = " ";
|
221
|
+
cds = new CalendarDateSelect($("cds_test"), {default_time:function() { return new Date('January 02, 2008 2:00 PM') }});
|
222
|
+
assertEqual('2008', cds.selected_date.getFullYear());
|
223
|
+
assertEqual('2008', cds.date.getFullYear());
|
224
|
+
assert(cds.selection_made)
|
225
|
+
cds.close();
|
226
|
+
}},
|
227
|
+
test_parseDate_defaultTime_javaScriptDatePassed_shouldReturnJavaScriptDate: function() {with(this){
|
228
|
+
$("cds_test").value = " ";
|
229
|
+
cds = new CalendarDateSelect($("cds_test"), {default_time:new Date('January 02, 2007 05:45 PM') });
|
230
|
+
assertEqual('2007', cds.selected_date.getFullYear());
|
231
|
+
assertEqual('2007', cds.date.getFullYear());
|
232
|
+
assert(cds.selection_made)
|
233
|
+
cds.close();
|
234
|
+
}},
|
235
|
+
test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
|
236
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
237
|
+
assertEqual("INPUT", cds.target_element.nodeName)
|
238
|
+
cds.close();
|
239
|
+
}},
|
240
|
+
test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
|
241
|
+
$("cds_test").value = "July 4, 1776";
|
242
|
+
cds = new CalendarDateSelect($("cds_test_div"), {time:true});
|
243
|
+
assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
|
244
|
+
assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
|
245
|
+
cds.close();
|
246
|
+
}},
|
247
|
+
test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
|
248
|
+
$("cds_test").value = "January 1, 2007";
|
249
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
|
250
|
+
|
251
|
+
assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
|
252
|
+
assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
|
253
|
+
assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
|
254
|
+
assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
|
255
|
+
assert(cds.navMonth(1), "should allow me to be in boundary");
|
256
|
+
assert(cds.navYear(2007), "should allow me to be in boundary");
|
257
|
+
cds.close();
|
258
|
+
}},
|
259
|
+
test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
|
260
|
+
$("cds_test").value = "January 1, 2007";
|
261
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
|
262
|
+
assert(cds.year_select.setValue(2007), "should allow me to select 2007");
|
263
|
+
cds.close();
|
264
|
+
}},
|
265
|
+
test__nonflexibleYearRange__initializedWithDateOutsideOfRange__shouldShowNavDateAsClosestToOutsideYear: function() {with(this){
|
266
|
+
$("cds_test").value = "January 1, 1900";
|
267
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
|
268
|
+
assertEqual(1997, cds.date.getFullYear(), "When going lesser than year_range");
|
269
|
+
cds.close();
|
270
|
+
|
271
|
+
$("cds_test").value = "January 1, 2010";
|
272
|
+
cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
|
273
|
+
assertEqual(2007, cds.date.getFullYear(), "When going greater than year_range");
|
274
|
+
|
275
|
+
cds.close();
|
276
|
+
}},
|
277
|
+
test__nonflexibleYearRange__initializedWithDateInsideOfRange__shouldShowNavDateAsYear: function() {with(this){
|
278
|
+
$("cds_test").value = "January 1, 2005";
|
279
|
+
cds = new CalendarDateSelect($("cds_test"), {year_range: [1997, 2007]});
|
280
|
+
assertEqual(2005, cds.date.getFullYear(), "When going lesser than year_range");
|
281
|
+
cds.close();
|
282
|
+
}},
|
283
|
+
test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
|
284
|
+
$("cds_test").value = "January 1, 2007";
|
285
|
+
cds = new CalendarDateSelect($("cds_test"), {year_range: 10});
|
286
|
+
cds.navYear(1997);
|
287
|
+
assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
|
288
|
+
cds.navYear(2017);
|
289
|
+
assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
|
290
|
+
cds.close();
|
291
|
+
}},
|
292
|
+
test__should_show_iframe_only_in_ie: function() {with(this){
|
293
|
+
cds = new CalendarDateSelect($("cds_test"));
|
294
|
+
|
295
|
+
if (navigator.appName=="Microsoft Internet Explorer")
|
296
|
+
assertEqual(1, $$('iframe.ie6_blocker').length)
|
297
|
+
else
|
298
|
+
assertEqual(0, $$('iframe.ie6_blocker').length)
|
299
|
+
|
300
|
+
cds.close();
|
301
|
+
}},
|
302
|
+
test__should_populate_minute_box_according_to_minute_interval: function() {with(this){
|
303
|
+
cds = new CalendarDateSelect($("cds_test"), {time: true, minute_interval: 10});
|
304
|
+
assert(cds.minute_select.setValue(0), "should allow me to select 0 minutes" );
|
305
|
+
assert(!cds.minute_select.setValue(5), "should NOT allow me to select 5 minutes");
|
306
|
+
assert(cds.minute_select.setValue(10), "should allow me to select 10 minutes" );
|
307
|
+
cds.close();
|
308
|
+
}},
|
309
|
+
test__shouldnt_leak_variables: function() {with (this) {
|
310
|
+
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")
|
311
|
+
vars.each(function(v) {eval(v + " = -100");});
|
312
|
+
|
313
|
+
cds = new CalendarDateSelect($("cds_test"), {time: true});
|
314
|
+
cds.navMonth(1);
|
315
|
+
cds.navYear(2);
|
316
|
+
cds.dayHover($$('.cds_body td').first());
|
317
|
+
cds.updateSelectedDate({day:1, month:1, year:2007});
|
318
|
+
cds.close();
|
319
|
+
|
320
|
+
vars.each(function(v) {
|
321
|
+
assert(-100 == eval(v), "Variable " + v + " was leaked");
|
322
|
+
});
|
323
|
+
}},
|
324
|
+
test__valid_date__shouldnt_allow_selection_of_invalid_dates_and_should_apply_css: function() {with (this) {
|
325
|
+
$('cds_test').value = "December 11, 2007";
|
326
|
+
cds = new CalendarDateSelect($("cds_test"), {valid_date_check: function(date) { return date < new Date("December 13, 2007")}, time: "mixed"});
|
327
|
+
assertEqual("December 11, 2007", $F('cds_test'));
|
328
|
+
cds.updateSelectedDate({day:13, month:12-1, year:2007});
|
329
|
+
assertEqual("December 11, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
|
330
|
+
cds.updateSelectedDate({day:10, month:12-1, year:2007});
|
331
|
+
assertEqual("December 10, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
|
332
|
+
|
333
|
+
day_12_element = $$('.calendar_date_select td')[17];
|
334
|
+
day_13_element = $$('.calendar_date_select td')[18];
|
335
|
+
assertEqual(12, day_12_element.day); // make sure we have th right one
|
336
|
+
assertEqual(13, day_13_element.day); // make sure we have th right one
|
337
|
+
assert( ! day_12_element.hasClassName("disabled"), "Day 12 shouldnt be disabled");
|
338
|
+
assert(day_13_element.hasClassName("disabled"), "Day 13 should be disabled");
|
339
|
+
|
340
|
+
cds.close();
|
341
|
+
}},
|
342
|
+
test__valid_date_check_is_nil__should_show_all_cells_as_enabled: function() {with (this) {
|
343
|
+
$('cds_test').value = "December 11, 2007";
|
344
|
+
cds = new CalendarDateSelect($("cds_test"));
|
345
|
+
|
346
|
+
$$('.calendar_date_select td').each(function(e){
|
347
|
+
assert( ! e.hasClassName("disabled"));
|
348
|
+
});
|
349
|
+
|
350
|
+
cds.close();
|
351
|
+
}},
|
352
|
+
test__should_pull_up_dec_07_when_first_day_of_week_is_1: function() {with (this) {
|
353
|
+
Date.first_day_of_week = 1;
|
354
|
+
Date.weekdays = $w("M T W T F S S");
|
355
|
+
$('cds_test').value = "December 1, 2007";
|
356
|
+
cds = new CalendarDateSelect($("cds_test"));
|
357
|
+
|
358
|
+
assertEqual(1, $$(".calendar_date_select").length);
|
359
|
+
cds.close();
|
360
|
+
}}
|
361
|
+
});
|
362
|
+
// ]]>
|
363
|
+
</script>
|
364
|
+
</body>
|
365
|
+
</html>
|