1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
module('datepicker');
function equalsDate(d1, d2, message) {
if (!d1 || !d2) {
ok(false, message + ' - missing date');
return;
}
d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
equals(d1.toString(), d2.toString(), message);
}
test('defaults', function() {
var dp1 = $('#dp1');
dp1.datepicker();
ok(dp1.is('.hasDatepicker'), 'Marker class set');
ok($($.datepicker._datepickerDiv).html() == '', 'Content empty');
dp1.focus();
ok($($.datepicker._datepickerDiv).html() != '', 'Content present');
dp1.blur();
equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn');
$.datepicker.setDefaults({showOn: 'button'});
equals($.datepicker._defaults.showOn, 'button', 'Change default showOn');
$.datepicker.setDefaults({showOn: 'focus'});
equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn');
});
test('remove', function() {
var rem = $('#rem');
rem.datepicker();
ok(rem.is('.hasDatepicker'), 'Marker class set');
ok(rem[0]._calId != null, 'Datepicker ID present');
rem.datepicker('destroy');
ok(!rem.is('.hasDatepicker'), 'Marker class cleared');
ok(rem[0]._calId == null, 'Datepicker ID absent');
});
test('change', function() {
var dp1 = $('#dp1');
dp1.datepicker();
var inst = $.datepicker._inst[dp1[0]._calId];
equals(inst._settings.showOn, null, 'Initial setting showOn');
equals(inst._get('showOn'), 'focus', 'Initial instance showOn');
equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');
dp1.datepicker('change', 'showOn', 'button');
equals(inst._settings.showOn, 'button', 'Change setting showOn');
equals(inst._get('showOn'), 'button', 'Change instance showOn');
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
dp1.datepicker('change', {showOn: 'both'});
equals(inst._settings.showOn, 'both', 'Change setting showOn');
equals(inst._get('showOn'), 'both', 'Change instance showOn');
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
dp1.datepicker('change', 'showOn', undefined);
equals(inst._settings.showOn, null, 'Clear setting showOn');
equals(inst._get('showOn'), 'focus', 'Restore instance showOn');
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
});
test('enableDisable', function() {
var dp1 = $('#dp1');
dp1.datepicker();
ok(!dp1.datepicker('isDisabled'), 'Initially enabled');
dp1.datepicker('disable');
ok(dp1.datepicker('isDisabled'), 'Now disabled');
dp1.datepicker('enable');
ok(!dp1.datepicker('isDisabled'), 'Now enabled');
});
/*
test('keystrokes', function() {
var dp1 = $('#dp1');
dp1.datepicker().val('').focus();
dp1.simulate('keydown', {keyCode: 13});
equalsDate(dp1.datepicker('getDate'), new Date(), 'Select today');
dp1.blur();
});
*/
test('noWeekends', function() {
for (var i = 1; i <= 31; i++) {
var date = new Date(2001, 1 - 1, i);
isObj($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''],
'No weekends ' + date);
}
});
test('iso8601Week', function() {
var date = new Date(2000, 12 - 1, 31);
equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 1);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 7);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 8);
equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
date = new Date(2003, 12 - 1, 28);
equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
date = new Date(2003, 12 - 1, 29);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2004, 1 - 1, 4);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2004, 1 - 1, 5);
equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
date = new Date(2009, 12 - 1, 28);
equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 3);
equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 4);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 10);
equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
});
test('parseDate', function() {
ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty');
equalsDate($.datepicker.parseDate('d m y', '3 2 01'),
new Date(2001, 2 - 1, 3), 'Parse date d m y');
equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'),
new Date(2001, 2 - 1, 3), 'Parse date dd mm yy');
equalsDate($.datepicker.parseDate('d m y', '13 12 01'),
new Date(2001, 12 - 1, 13), 'Parse date d m y');
equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'),
new Date(2001, 12 - 1, 13), 'Parse date dd mm yy');
equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'),
new Date(2001, 2 - 1, 3), 'Parse date D d M y');
equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'),
new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy');
equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'),
new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy');
equalsDate($.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of February (\'Saturday\'), 2001'),
new Date(2001, 2 - 1, 3), 'Parse date \'day\' d of MM (\'\'DD\'\'), yy');
var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];
var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];
var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',
'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];
var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6',
'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];
var settings = {dayNamesShort: daysShort, dayNames: daysLong,
monthNamesShort: monthsShort, monthNames: monthsLong};
equalsDate($.datepicker.parseDate('D d M y', 'D7 3 M2 01', settings),
new Date(2001, 2 - 1, 3), 'Parse date D M y with settings');
equalsDate($.datepicker.parseDate('d MM DD yy', '3 Mon2 Day7 2001', settings),
new Date(2001, 2 - 1, 3), 'Parse date d MM DD yy with settings');
equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Day7, Mon2 3, 2001', settings),
new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy with settings');
equalsDate($.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of Mon2 (\'Day7\'), 2001', settings),
new Date(2001, 2 - 1, 3), 'Parse date \'day\' d of MM (\'\'DD\'\'), yy with settings');
});
test('parseDateErrors', function() {
var expectError = function(expr, value, error) {
try {
expr();
ok(false, 'Parsed error ' + value);
}
catch (e) {
equals(e, error, 'Parsed error ' + value);
}
};
expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); },
'Sat 2 01', 'Invalid arguments');
expectError(function() { $.datepicker.parseDate('d m y', null); },
'null', 'Invalid arguments');
expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); },
'Sat 2 01', 'Missing number at position 0');
expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); },
'3 Feb 01', 'Missing number at position 2');
expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); },
'3 2 AD01', 'Missing number at position 4');
expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01'); },
'D7 3 Feb 01', 'Unknown name at position 0');
expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01'); },
'Sat 3 M2 01', 'Unknown name at position 6');
expectError(function() { $.datepicker.parseDate('DD, MM d, yy', 'Saturday- Feb 3, 2001'); },
'Sat- Feb 3, 2001', 'Unexpected literal at position 8');
expectError(function() { $.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of February ("Saturday"), 2001'); },
'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19');
expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); },
'29 2 01', 'Invalid date');
var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];
var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];
var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',
'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];
var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6',
'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];
var settings = {dayNamesShort: daysShort, dayNames: daysLong,
monthNamesShort: monthsShort, monthNames: monthsLong};
expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01', settings); },
'Sat 3 M2 01', 'Unknown name at position 0');
expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01', settings); },
'D7 3 Feb 01', 'Unknown name at position 5');
});
test('formatDate', function() {
equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)),
'3 2 01', 'Format date d m y');
equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)),
'03 02 2001', 'Format date dd mm yy');
equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)),
'13 12 01', 'Format date d m y');
equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)),
'13 12 2001', 'Format date dd mm yy');
equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)),
'Sat Feb 01', 'Format date D M y');
equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)),
'Saturday February 2001', 'Format date DD MM yy');
equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)),
'Saturday, February 3, 2001', 'Format date DD, MM d, yy');
equals($.datepicker.formatDate('\'day\' d of MM (\'\'DD\'\'), yy', new Date(2001, 2 - 1, 3)),
'day 3 of February (\'Saturday\'), 2001', 'Format date \'day\' d of MM (\'\'DD\'\'), yy');
var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];
var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];
var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',
'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];
var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6',
'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];
var settings = {dayNamesShort: daysShort, dayNames: daysLong,
monthNamesShort: monthsShort, monthNames: monthsLong};
equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3), settings),
'D7 M2 01', 'Format date D M y with settings');
equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3), settings),
'Day7 Mon2 2001', 'Format date DD MM yy with settings');
equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3), settings),
'Day7, Mon2 3, 2001', 'Format date DD, MM d, yy with settings');
equals($.datepicker.formatDate('\'day\' d of MM (\'\'DD\'\'), yy', new Date(2001, 2 - 1, 3), settings),
'day 3 of Mon2 (\'Day7\'), 2001', 'Format date \'day\' d of MM (\'\'DD\'\'), yy with settings');
});
|