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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
module('Mouse Navigation 2012', {
setup: function(){
/*
Tests start with picker on March 31, 2012. Fun facts:
* February 1, 2012 was on a Wednesday
* February 29, 2012 was on a Wednesday
* March 1, 2012 was on a Thursday
* March 31, 2012 was on a Saturday
*/
this.input = $('<input type="text" value="31-03-2012">')
.appendTo('#qunit-fixture')
.datepicker({format: "dd-mm-yyyy"})
.focus(); // Activate for visibility checks
this.dp = this.input.data('datepicker');
this.picker = this.dp.picker;
},
teardown: function(){
this.picker.remove();
}
});
test('Selecting date resets viewDate and date', function(){
var target;
// Rendered correctly
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days tbody td:nth(7)');
equal(target.text(), '4'); // Should be Mar 4
// Updated internally on click
target.click();
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 4));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 4));
// Re-rendered on click
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '26'); // Should be Feb 29
});
test('Navigating next/prev by month', function(){
var target;
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.prev');
ok(target.is(':visible'), 'Month:prev nav is visible');
// Updated internally on click
target.click();
// Should handle month-length changes gracefully
datesEqual(this.dp.viewDate, UTCDate(2012, 1, 29));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Re-rendered on click
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '29'); // Should be Jan 29
target = this.picker.find('.datepicker-days thead th.next');
ok(target.is(':visible'), 'Month:next nav is visible');
// Updated internally on click
target.click().click();
// Graceful moonth-end handling carries over
datesEqual(this.dp.viewDate, UTCDate(2012, 3, 29));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Re-rendered on click
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '25'); // Should be Mar 25
// (includes "old" days at start of month, even if that's all the first week-row consists of)
});
test('Navigating to/from year view', function(){
var target;
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
equal(this.dp.viewMode, 1);
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Change months to test internal state
target = this.picker.find('.datepicker-months tbody span:contains(Apr)');
target.click();
equal(this.dp.viewMode, 0);
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2012, 3, 1)); // Apr 30
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
});
test('Navigating to/from decade view', function(){
var target;
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
equal(this.dp.viewMode, 1);
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
target = this.picker.find('.datepicker-months thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-years').is(':visible'), 'Year picker is visible');
equal(this.dp.viewMode, 2);
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Change years to test internal state changes
target = this.picker.find('.datepicker-years tbody span:contains(2011)');
target.click();
equal(this.dp.viewMode, 1);
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2011, 2, 1));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
target = this.picker.find('.datepicker-months tbody span:contains(Apr)');
target.click();
equal(this.dp.viewMode, 0);
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2011, 3, 1));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
});
test('Navigating prev/next in year view', function(){
var target;
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
equal(this.dp.viewMode, 1);
equal(this.picker.find('.datepicker-months thead th.datepicker-switch').text(), '2012');
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Go to next year (2013)
target = this.picker.find('.datepicker-months thead th.next');
target.click();
equal(this.picker.find('.datepicker-months thead th.datepicker-switch').text(), '2013');
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2013, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Go to prev year (x2 == 2011)
target = this.picker.find('.datepicker-months thead th.prev');
target.click().click();
equal(this.picker.find('.datepicker-months thead th.datepicker-switch').text(), '2011');
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2011, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
});
test('Navigating prev/next in decade view', function(){
var target;
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
equal(this.dp.viewMode, 1);
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
target = this.picker.find('.datepicker-months thead th.datepicker-switch');
ok(target.is(':visible'), 'View switcher is visible');
target.click();
ok(this.picker.find('.datepicker-years').is(':visible'), 'Year picker is visible');
equal(this.dp.viewMode, 2);
equal(this.picker.find('.datepicker-years thead th.datepicker-switch').text(), '2010-2019');
// Not modified when switching modes
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Go to next decade (2020-29)
target = this.picker.find('.datepicker-years thead th.next');
target.click();
equal(this.picker.find('.datepicker-years thead th.datepicker-switch').text(), '2020-2029');
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2022, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
// Go to prev year (x2 == 2000-09)
target = this.picker.find('.datepicker-years thead th.prev');
target.click().click();
equal(this.picker.find('.datepicker-years thead th.datepicker-switch').text(), '2000-2009');
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2002, 2, 31));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 2, 31));
});
test('Selecting date from previous month resets viewDate and date, changing month displayed', function(){
var target;
// Rendered correctly
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '26'); // Should be Feb 26
equal(this.picker.find('.datepicker-days thead th.datepicker-switch').text(), 'March 2012');
// Updated internally on click
target.click();
equal(this.picker.find('.datepicker-days thead th.datepicker-switch').text(), 'February 2012');
datesEqual(this.dp.viewDate, UTCDate(2012, 1, 26));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 1, 26));
// Re-rendered on click
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '29'); // Should be Jan 29
});
test('Selecting date from next month resets viewDate and date, changing month displayed', function(){
var target;
this.input.val('01-04-2012');
this.dp.update();
// Rendered correctly
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days tbody td:last');
equal(target.text(), '5'); // Should be May 5
equal(this.picker.find('.datepicker-days thead th.datepicker-switch').text(), 'April 2012');
// Updated internally on click
target.click();
equal(this.picker.find('.datepicker-days thead th.datepicker-switch').text(), 'May 2012');
datesEqual(this.dp.viewDate, UTCDate(2012, 4, 5));
datesEqual(this.dp.dates.get(-1), UTCDate(2012, 4, 5));
// Re-rendered on click
target = this.picker.find('.datepicker-days tbody td:first');
equal(target.text(), '29'); // Should be Apr 29
});
test('Selecting today from next month', patch_date(function(Date){
var target;
this.dp.o.todayHighlight = true;
Date.now = new Date(2012, 2, 3); // Mar 3
this.input.val('01-02-2012'); // Feb 1
this.dp.update();
// Click the today button
target = this.picker.find('.datepicker-days tbody td.today');
equal(target.text(), '3'); // Should be Mar 3
target.click();
datesEqual(this.dp.viewDate, UTCDate(2012, 2, 3));
}));
|