calendar_date_select_rails3 1.16.2

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