1 | /*
|
---|
2 | * datepicker_core.js
|
---|
3 | */
|
---|
4 |
|
---|
5 | function equalsDate(d1, d2, message) {
|
---|
6 | if (!d1 || !d2) {
|
---|
7 | ok(false, message + ' - missing date');
|
---|
8 | return;
|
---|
9 | }
|
---|
10 | d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
|
---|
11 | d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
|
---|
12 | equals(d1.toString(), d2.toString(), message);
|
---|
13 | }
|
---|
14 |
|
---|
15 | function equalsDateArray(a1, a2, message) {
|
---|
16 | if (!a1 || !a2) {
|
---|
17 | ok(false, message + ' - missing dates');
|
---|
18 | return;
|
---|
19 | }
|
---|
20 | a1[0] = (a1[0] ? new Date(a1[0].getFullYear(), a1[0].getMonth(), a1[0].getDate()) : '');
|
---|
21 | a1[1] = (a1[1] ? new Date(a1[1].getFullYear(), a1[1].getMonth(), a1[1].getDate()) : '');
|
---|
22 | a2[0] = (a2[0] ? new Date(a2[0].getFullYear(), a2[0].getMonth(), a2[0].getDate()) : '');
|
---|
23 | a2[1] = (a2[1] ? new Date(a2[1].getFullYear(), a2[1].getMonth(), a2[1].getDate()) : '');
|
---|
24 | same(a1, a2, message);
|
---|
25 | }
|
---|
26 |
|
---|
27 | function addMonths(date, offset) {
|
---|
28 | var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate();
|
---|
29 | date.setDate(Math.min(date.getDate(), maxDay));
|
---|
30 | date.setMonth(date.getMonth() + offset);
|
---|
31 | return date;
|
---|
32 | }
|
---|
33 |
|
---|
34 | function init(id, options) {
|
---|
35 | $.datepicker.setDefaults($.datepicker.regional['']);
|
---|
36 | return $(id).datepicker($.extend({showAnim: ''}, options || {}));
|
---|
37 | }
|
---|
38 |
|
---|
39 | var PROP_NAME = 'datepicker';
|
---|
40 |
|
---|
41 | (function($) {
|
---|
42 |
|
---|
43 | module("datepicker: core", {
|
---|
44 | teardown: function() {
|
---|
45 | stop();
|
---|
46 | setTimeout(start, 13);
|
---|
47 | }
|
---|
48 | });
|
---|
49 |
|
---|
50 | test("widget method", function() {
|
---|
51 | var actual = $("#inp").datepicker().datepicker("widget")[0];
|
---|
52 | same($("body > #ui-datepicker-div:last-child")[0], actual);
|
---|
53 | });
|
---|
54 |
|
---|
55 | test('baseStructure', function() {
|
---|
56 | var inp = init('#inp');
|
---|
57 | inp.focus();
|
---|
58 | var dp = $('#ui-datepicker-div');
|
---|
59 | var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
|
---|
60 | ok(dp.is(':visible'), 'Structure - datepicker visible');
|
---|
61 | ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left');
|
---|
62 | ok(!dp.is('.ui-datepicker-multi'), 'Structure - not multi-month');
|
---|
63 | equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count');
|
---|
64 |
|
---|
65 | var header = dp.children(':first');
|
---|
66 | ok(header.is('div.ui-datepicker-header'), 'Structure - header division');
|
---|
67 | equals(header.children().length, 3, 'Structure - header child count');
|
---|
68 | ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() != '', 'Structure - prev link');
|
---|
69 | ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() != '', 'Structure - next link');
|
---|
70 |
|
---|
71 | var title = header.children(':last');
|
---|
72 | ok(title.is('div.ui-datepicker-title') && title.html() != '','Structure - title division');
|
---|
73 | equals(title.children().length, 2, 'Structure - title child count');
|
---|
74 | ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() != '', 'Structure - month text')
|
---|
75 | ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() != '', 'Structure - year text')
|
---|
76 |
|
---|
77 | var table = dp.children(':eq(1)');
|
---|
78 | ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table');
|
---|
79 | ok(table.children(':first').is('thead'), 'Structure - month table thead');
|
---|
80 | var thead = table.children(':first').children(':first');
|
---|
81 | ok(thead.is('tr'), 'Structure - month table title row');
|
---|
82 | equals(thead.find('th').length, 7, 'Structure - month table title cells');
|
---|
83 | ok(table.children(':eq(1)').is('tbody'), 'Structure - month table body');
|
---|
84 | ok(table.children(':eq(1)').children('tr').length >= 4, 'Structure - month table week count');
|
---|
85 | var week = table.children(':eq(1)').children(':first');
|
---|
86 | ok(week.is('tr'), 'Structure - month table week row');
|
---|
87 | equals(week.children().length, 7, 'Structure - week child count');
|
---|
88 | ok(week.children(':first').is('td.ui-datepicker-week-end'), 'Structure - month table first day cell');
|
---|
89 | ok(week.children(':last').is('td.ui-datepicker-week-end'), 'Structure - month table second day cell');
|
---|
90 | ok(dp.children('iframe').length == (iframe ? 1 : 0), 'Structure - iframe');
|
---|
91 | inp.datepicker('hide').datepicker('destroy');
|
---|
92 |
|
---|
93 | // Editable month/year and button panel
|
---|
94 | inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true});
|
---|
95 | inp.focus();
|
---|
96 |
|
---|
97 | var title = dp.find('div.ui-datepicker-title');
|
---|
98 | ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure - month selector');
|
---|
99 | ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure - year selector');
|
---|
100 |
|
---|
101 | var panel = dp.children(':last');
|
---|
102 | ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division');
|
---|
103 | equals(panel.children().length, 2, 'Structure - button panel child count');
|
---|
104 | ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button');
|
---|
105 | ok(panel.children(':last').is('button.ui-datepicker-close'), 'Structure - close button');
|
---|
106 | inp.datepicker('hide').datepicker('destroy');
|
---|
107 |
|
---|
108 | // Multi-month 2
|
---|
109 | inp = init('#inp', {numberOfMonths: 2});
|
---|
110 | inp.focus();
|
---|
111 | ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
|
---|
112 | equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] - child count');
|
---|
113 | var child = dp.children(':first');
|
---|
114 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division');
|
---|
115 | child = dp.children(':eq(1)');
|
---|
116 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division');
|
---|
117 | child = dp.children(':eq(2)');
|
---|
118 | ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2] - row break');
|
---|
119 | inp.datepicker('hide').datepicker('destroy');
|
---|
120 |
|
---|
121 | // Multi-month [2, 2]
|
---|
122 | inp = init('#inp', {numberOfMonths: [2, 2]});
|
---|
123 | inp.focus();
|
---|
124 | ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month');
|
---|
125 | equals(dp.children().length, 6 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count');
|
---|
126 | child = dp.children(':first');
|
---|
127 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division');
|
---|
128 | child = dp.children(':eq(1)');
|
---|
129 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division');
|
---|
130 | child = dp.children(':eq(2)');
|
---|
131 | ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break');
|
---|
132 | child = dp.children(':eq(3)');
|
---|
133 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division');
|
---|
134 | child = dp.children(':eq(4)');
|
---|
135 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division');
|
---|
136 | child = dp.children(':eq(5)');
|
---|
137 | ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break');
|
---|
138 | inp.datepicker('hide').datepicker('destroy');
|
---|
139 |
|
---|
140 | // Inline
|
---|
141 | var inl = init('#inl');
|
---|
142 | dp = inl.children();
|
---|
143 | ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div');
|
---|
144 | ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left');
|
---|
145 | ok(!dp.is('.ui-datepicker-multi'), 'Structure inline - not multi-month');
|
---|
146 | equals(dp.children().length, 2, 'Structure inline - child count');
|
---|
147 | var header = dp.children(':first');
|
---|
148 | ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division');
|
---|
149 | equals(header.children().length, 3, 'Structure inline - header child count');
|
---|
150 | var table = dp.children(':eq(1)');
|
---|
151 | ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table');
|
---|
152 | ok(table.children(':first').is('thead'), 'Structure inline - month table thead');
|
---|
153 | ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body');
|
---|
154 | inl.datepicker('destroy');
|
---|
155 |
|
---|
156 | // Inline multi-month
|
---|
157 | inl = init('#inl', {numberOfMonths: 2});
|
---|
158 | dp = inl.children();
|
---|
159 | ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div');
|
---|
160 | equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure inline multi - child count');
|
---|
161 | child = dp.children(':first');
|
---|
162 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure inline multi - first month division');
|
---|
163 | child = dp.children(':eq(1)');
|
---|
164 | ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure inline multi - second month division');
|
---|
165 | child = dp.children(':eq(2)');
|
---|
166 | ok(child.is('div.ui-datepicker-row-break'), 'Structure inline multi - row break');
|
---|
167 | inl.datepicker('destroy');
|
---|
168 | });
|
---|
169 |
|
---|
170 | test('customStructure', function() {
|
---|
171 | var dp = $('#ui-datepicker-div');
|
---|
172 | // Check right-to-left localisation
|
---|
173 | var inp = init('#inp', $.datepicker.regional['he']);
|
---|
174 | inp.data('showButtonPanel.datepicker',true);
|
---|
175 | inp.focus();
|
---|
176 | var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
|
---|
177 | ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left');
|
---|
178 | var header = dp.children(':first');
|
---|
179 | ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division');
|
---|
180 | equals(header.children().length, 3, 'Structure RTL - header child count');
|
---|
181 | ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link');
|
---|
182 | ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link');
|
---|
183 | var panel = dp.children(':last');
|
---|
184 | ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division');
|
---|
185 | equals(panel.children().length, 2, 'Structure RTL - button panel child count');
|
---|
186 | ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button');
|
---|
187 | ok(panel.children(':last').is('button.ui-datepicker-current'), 'Structure RTL - today button');
|
---|
188 | inp.datepicker('hide').datepicker('destroy');
|
---|
189 |
|
---|
190 | // Hide prev/next
|
---|
191 | inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)});
|
---|
192 | inp.val('02/10/2008').focus();
|
---|
193 | var header = dp.children(':first');
|
---|
194 | ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division');
|
---|
195 | equals(header.children().length, 1, 'Structure hide prev/next - links child count');
|
---|
196 | ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division');
|
---|
197 | inp.datepicker('hide').datepicker('destroy');
|
---|
198 |
|
---|
199 | // Changeable Month with read-only year
|
---|
200 | inp = init('#inp', {changeMonth: true});
|
---|
201 | inp.focus();
|
---|
202 | var title = dp.children(':first').children(':last');
|
---|
203 | equals(title.children().length, 2, 'Structure changeable month - title child count');
|
---|
204 | ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector');
|
---|
205 | ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year');
|
---|
206 | inp.datepicker('hide').datepicker('destroy');
|
---|
207 |
|
---|
208 | // Changeable year with read-only month
|
---|
209 | inp = init('#inp', {changeYear: true});
|
---|
210 | inp.focus();
|
---|
211 | var title = dp.children(':first').children(':last');
|
---|
212 | equals(title.children().length, 2, 'Structure changeable year - title child count');
|
---|
213 | ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month');
|
---|
214 | ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector');
|
---|
215 | inp.datepicker('hide').datepicker('destroy');
|
---|
216 |
|
---|
217 | // Read-only first day of week
|
---|
218 | inp = init('#inp', {changeFirstDay: false});
|
---|
219 | inp.focus();
|
---|
220 | var thead = dp.find('.ui-datepicker-calendar thead tr');
|
---|
221 | equals(thead.children().length, 7, 'Structure read-only first day - thead child count');
|
---|
222 | equals(thead.find('a').length, 0, 'Structure read-only first day - thead links count');
|
---|
223 | inp.datepicker('hide').datepicker('destroy');
|
---|
224 | });
|
---|
225 |
|
---|
226 | test('keystrokes', function() {
|
---|
227 | var inp = init('#inp');
|
---|
228 | var date = new Date();
|
---|
229 | inp.val('').datepicker('show').
|
---|
230 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
231 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter');
|
---|
232 | inp.val('02/04/2008').datepicker('show').
|
---|
233 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
234 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
235 | 'Keystroke enter - preset');
|
---|
236 | inp.val('02/04/2008').datepicker('show').
|
---|
237 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}).
|
---|
238 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
239 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home');
|
---|
240 | inp.val('02/04/2008').datepicker('show').
|
---|
241 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END});
|
---|
242 | ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end');
|
---|
243 | inp.val('').datepicker('show').
|
---|
244 | simulate('keydown', {keyCode: $.simulate.VK_ESC});
|
---|
245 | ok(inp.datepicker('getDate') == null, 'Keystroke esc');
|
---|
246 | inp.val('02/04/2008').datepicker('show').
|
---|
247 | simulate('keydown', {keyCode: $.simulate.VK_ESC});
|
---|
248 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
249 | 'Keystroke esc - preset');
|
---|
250 | inp.val('02/04/2008').datepicker('show').
|
---|
251 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}).
|
---|
252 | simulate('keydown', {keyCode: $.simulate.VK_ESC});
|
---|
253 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
254 | 'Keystroke esc - abandoned');
|
---|
255 | // Moving by day or week
|
---|
256 | inp.val('').datepicker('show').
|
---|
257 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_LEFT}).
|
---|
258 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
259 | date.setDate(date.getDate() - 1);
|
---|
260 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left');
|
---|
261 | inp.val('').datepicker('show').
|
---|
262 | simulate('keydown', {keyCode: $.simulate.VK_LEFT}).
|
---|
263 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
264 | date.setDate(date.getDate() + 1);
|
---|
265 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke left');
|
---|
266 | inp.val('').datepicker('show').
|
---|
267 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_RIGHT}).
|
---|
268 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
269 | date.setDate(date.getDate() + 1);
|
---|
270 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right');
|
---|
271 | inp.val('').datepicker('show').
|
---|
272 | simulate('keydown', {keyCode: $.simulate.VK_RIGHT}).
|
---|
273 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
274 | date.setDate(date.getDate() - 1);
|
---|
275 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke right');
|
---|
276 | inp.val('').datepicker('show').
|
---|
277 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}).
|
---|
278 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
279 | date.setDate(date.getDate() - 7);
|
---|
280 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up');
|
---|
281 | inp.val('').datepicker('show').
|
---|
282 | simulate('keydown', {keyCode: $.simulate.VK_UP}).
|
---|
283 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
284 | date.setDate(date.getDate() + 7);
|
---|
285 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke up');
|
---|
286 | inp.val('').datepicker('show').
|
---|
287 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}).
|
---|
288 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
289 | date.setDate(date.getDate() + 7);
|
---|
290 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down');
|
---|
291 | inp.val('').datepicker('show').
|
---|
292 | simulate('keydown', {keyCode: $.simulate.VK_DOWN}).
|
---|
293 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
294 | date.setDate(date.getDate() - 7);
|
---|
295 | equalsDate(inp.datepicker('getDate'), date, 'Keystroke down');
|
---|
296 | // Moving by month or year
|
---|
297 | inp.val('02/04/2008').datepicker('show').
|
---|
298 | simulate('keydown', {keyCode: $.simulate.VK_PGUP}).
|
---|
299 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
300 | equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4),
|
---|
301 | 'Keystroke pgup');
|
---|
302 | inp.val('02/04/2008').datepicker('show').
|
---|
303 | simulate('keydown', {keyCode: $.simulate.VK_PGDN}).
|
---|
304 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
305 | equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4),
|
---|
306 | 'Keystroke pgdn');
|
---|
307 | inp.val('02/04/2008').datepicker('show').
|
---|
308 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}).
|
---|
309 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
310 | equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4),
|
---|
311 | 'Keystroke ctrl+pgup');
|
---|
312 | inp.val('02/04/2008').datepicker('show').
|
---|
313 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}).
|
---|
314 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
315 | equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4),
|
---|
316 | 'Keystroke ctrl+pgdn');
|
---|
317 | // Check for moving to short months
|
---|
318 | inp.val('03/31/2008').datepicker('show').
|
---|
319 | simulate('keydown', {keyCode: $.simulate.VK_PGUP}).
|
---|
320 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
321 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
|
---|
322 | 'Keystroke pgup - Feb');
|
---|
323 | inp.val('01/30/2008').datepicker('show').
|
---|
324 | simulate('keydown', {keyCode: $.simulate.VK_PGDN}).
|
---|
325 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
326 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
|
---|
327 | 'Keystroke pgdn - Feb');
|
---|
328 | inp.val('02/29/2008').datepicker('show').
|
---|
329 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}).
|
---|
330 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
331 | equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28),
|
---|
332 | 'Keystroke ctrl+pgup - Feb');
|
---|
333 | inp.val('02/29/2008').datepicker('show').
|
---|
334 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}).
|
---|
335 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
336 | equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28),
|
---|
337 | 'Keystroke ctrl+pgdn - Feb');
|
---|
338 | // Goto current
|
---|
339 | inp.datepicker('option', {gotoCurrent: true}).
|
---|
340 | datepicker('hide').val('02/04/2008').datepicker('show').
|
---|
341 | simulate('keydown', {keyCode: $.simulate.VK_PGDN}).
|
---|
342 | simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}).
|
---|
343 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
344 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
345 | 'Keystroke ctrl+home');
|
---|
346 | // Change steps
|
---|
347 | inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}).
|
---|
348 | datepicker('hide').val('02/04/2008').datepicker('show').
|
---|
349 | simulate('keydown', {keyCode: $.simulate.VK_PGUP}).
|
---|
350 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
351 | equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4),
|
---|
352 | 'Keystroke pgup step 2');
|
---|
353 | inp.val('02/04/2008').datepicker('show').
|
---|
354 | simulate('keydown', {keyCode: $.simulate.VK_PGDN}).
|
---|
355 | simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
---|
356 | equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4),
|
---|
357 | 'Keystroke pgdn step 2');
|
---|
358 | });
|
---|
359 |
|
---|
360 | test('mouse', function() {
|
---|
361 | var inp = init('#inp');
|
---|
362 | var dp = $('#ui-datepicker-div');
|
---|
363 | var date = new Date();
|
---|
364 | inp.val('').datepicker('show');
|
---|
365 | $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
|
---|
366 | date.setDate(10);
|
---|
367 | equalsDate(inp.datepicker('getDate'), date, 'Mouse click');
|
---|
368 | inp.val('02/04/2008').datepicker('show');
|
---|
369 | $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
|
---|
370 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12),
|
---|
371 | 'Mouse click - preset');
|
---|
372 | inp.val('02/04/2008').datepicker('show');
|
---|
373 | inp.val('').datepicker('show');
|
---|
374 | $('button.ui-datepicker-close', dp).simulate('click', {});
|
---|
375 | ok(inp.datepicker('getDate') == null, 'Mouse click - close');
|
---|
376 | inp.val('02/04/2008').datepicker('show');
|
---|
377 | $('button.ui-datepicker-close', dp).simulate('click', {});
|
---|
378 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
379 | 'Mouse click - close + preset');
|
---|
380 | inp.val('02/04/2008').datepicker('show');
|
---|
381 | $('a.ui-datepicker-prev', dp).simulate('click', {});
|
---|
382 | $('button.ui-datepicker-close', dp).simulate('click', {});
|
---|
383 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
---|
384 | 'Mouse click - abandoned');
|
---|
385 | // Current/previous/next
|
---|
386 | inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show');
|
---|
387 | $('.ui-datepicker-current', dp).simulate('click', {});
|
---|
388 | $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
|
---|
389 | date.setDate(14);
|
---|
390 | equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current');
|
---|
391 | inp.val('02/04/2008').datepicker('show');
|
---|
392 | $('.ui-datepicker-prev', dp).simulate('click');
|
---|
393 | $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
---|
394 | equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16),
|
---|
395 | 'Mouse click - previous');
|
---|
396 | inp.val('02/04/2008').datepicker('show');
|
---|
397 | $('.ui-datepicker-next', dp).simulate('click');
|
---|
398 | $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
---|
399 | equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18),
|
---|
400 | 'Mouse click - next');
|
---|
401 | // Previous/next with minimum/maximum
|
---|
402 | inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2),
|
---|
403 | maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show');
|
---|
404 | $('.ui-datepicker-prev', dp).simulate('click');
|
---|
405 | $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
---|
406 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16),
|
---|
407 | 'Mouse click - previous + min/max');
|
---|
408 | inp.val('02/04/2008').datepicker('show');
|
---|
409 | $('.ui-datepicker-next', dp).simulate('click');
|
---|
410 | $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
---|
411 | equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18),
|
---|
412 | 'Mouse click - next + min/max');
|
---|
413 | // Inline
|
---|
414 | var inl = init('#inl');
|
---|
415 | var dp = $('.ui-datepicker-inline', inl);
|
---|
416 | var date = new Date();
|
---|
417 | inl.datepicker('setDate', date);
|
---|
418 | $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
|
---|
419 | date.setDate(10);
|
---|
420 | equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline');
|
---|
421 | inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4));
|
---|
422 | $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
|
---|
423 | equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset');
|
---|
424 | inl.datepicker('option', {showButtonPanel: true});
|
---|
425 | $('.ui-datepicker-current', dp).simulate('click', {});
|
---|
426 | $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
|
---|
427 | date.setDate(14);
|
---|
428 | equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current');
|
---|
429 | inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
|
---|
430 | $('.ui-datepicker-prev', dp).simulate('click');
|
---|
431 | $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
---|
432 | equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16),
|
---|
433 | 'Mouse click inline - previous');
|
---|
434 | inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
|
---|
435 | $('.ui-datepicker-next', dp).simulate('click');
|
---|
436 | $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
---|
437 | equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18),
|
---|
438 | 'Mouse click inline - next');
|
---|
439 | });
|
---|
440 |
|
---|
441 | })(jQuery);
|
---|