module('Events', {
setup: function(){
this.input = $('<input type="text" value="31-03-2011">')
.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 a year from decade view triggers pickYear', function(){
var target,
triggered = 0;
this.input.on('changeYear', function(){
triggered++;
});
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.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(2011, 2, 31));
datesEqual(this.dp.date, UTCDate(2011, 2, 31));
target = this.picker.find('.datepicker-months thead th.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(2011, 2, 31));
datesEqual(this.dp.date, UTCDate(2011, 2, 31));
// Change years to test internal state changes
target = this.picker.find('.datepicker-years tbody span:contains(2010)');
target.click();
equal(this.dp.viewMode, 1);
// Only viewDate modified
datesEqual(this.dp.viewDate, UTCDate(2010, 2, 1));
datesEqual(this.dp.date, UTCDate(2011, 2, 31));
equal(triggered, 1);
});
test('Selecting a month from year view triggers pickMonth', function(){
var target,
triggered = 0;
this.input.on('changeMonth', function(){
triggered++;
});
equal(this.dp.viewMode, 0);
target = this.picker.find('.datepicker-days thead th.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(2011, 2, 31));
datesEqual(this.dp.date, UTCDate(2011, 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.date, UTCDate(2011, 2, 31));
equal(triggered, 1);
});
|