Datepicker tests: Remove pass-through options unit tests

Add Test if these options are set on the underlying calendar instance
This commit is contained in:
Felix Nagel 2014-08-29 21:19:30 +02:00 committed by Scott González
parent 50f477f847
commit 95fd20fbf6
2 changed files with 24 additions and 160 deletions

View File

@ -77,13 +77,11 @@ test( "value", function() {
}); });
test( "valueAsDate", function() { test( "valueAsDate", function() {
expect( 13 ); expect( 6 );
var minDate, maxDate, dateAndTimeToSet, dateAndTimeClone, var input = TestHelpers.datepicker.init( "#datepicker" ),
input = TestHelpers.datepicker.init( "#datepicker" ),
picker = input.datepicker( "widget" ), picker = input.datepicker( "widget" ),
date1 = new Date( 2008, 6 - 1, 4 ), date1 = new Date( 2008, 6 - 1, 4 );
date2 = new Date();
input.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) ); input.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) );
equal( input.val(), "1/1/14", "Input's value set" ); equal( input.val(), "1/1/14", "Input's value set" );
@ -99,36 +97,6 @@ test( "valueAsDate", function() {
strictEqual( input.datepicker( "valueAsDate" ), null, "Set date - default" ); strictEqual( input.datepicker( "valueAsDate" ), null, "Set date - default" );
input.datepicker( "valueAsDate", date1 ); input.datepicker( "valueAsDate", date1 );
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date - 2008-06-04" ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date - 2008-06-04" );
// With minimum/maximum
input = TestHelpers.datepicker.init( "#datepicker" );
date1 = new Date( 2008, 1 - 1, 4 );
date2 = new Date( 2008, 6 - 1, 4 );
minDate = new Date( 2008, 2 - 1, 29 );
maxDate = new Date( 2008, 3 - 1, 28 );
input.val( "" ).datepicker( "option", { min: minDate } ).datepicker( "valueAsDate", date2 );
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date2, "Set date min/max - value > min" );
input.datepicker( "valueAsDate", date1 );
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date2, "Set date min/max - value < min" );
input.val( "" ).datepicker( "option", { max: maxDate, min: null } ).datepicker( "valueAsDate", date1 );
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date min/max - value < max" );
input.datepicker( "valueAsDate", date2 );
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date min/max - value > max" );
input.val( "" ).datepicker( "option", { min: minDate } ).datepicker( "valueAsDate", date1 );
ok( input.datepicker( "valueAsDate" ) === null, "Set date min/max - value < min" );
input.datepicker( "valueAsDate", date2 );
ok( input.datepicker( "valueAsDate" ) === null, "Set date min/max - value > max" );
dateAndTimeToSet = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
dateAndTimeClone = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
input.datepicker( "valueAsDate", dateAndTimeToSet );
equal( dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), "Date object passed should not be changed by valueAsDate" );
}); });
test( "isValid", function() { test( "isValid", function() {

View File

@ -40,76 +40,34 @@ test( "appendTo", function() {
input.datepicker( "destroy" ); input.datepicker( "destroy" );
}); });
test("buttons", function() { test( "Pass-through options", function() {
expect( 3 ); expect( 8 );
var button, var options = {
buttons = { "buttons": { "Test": $.noop },
"Ok": function() {}, "dateFormat": { date: "full" },
"Cancel": function() {} "eachDay": function( day ) { day; },
"max": new Date( 2000, 0, 1 ),
"min": new Date( 2000, 0, 2 ),
"numberOfMonths": 3,
"showWeek": true
}, },
element = $( "#datepicker" ).datepicker({ buttons: buttons }); input = $( "#datepicker" ).val( "1/1/14" ).datepicker(),
datepickerInstance = input.datepicker( "instance" );
button = element.datepicker( "widget" ).find( ".ui-calendar-buttonpane button" ); $.each( options, function( key, value ) {
equal( button.length, 2, "number of buttons" ); input.datepicker( "option", key, value );
ok( button.parent().hasClass( "ui-calendar-buttonset" ), "buttons in container");
ok( element.datepicker( "widget" ).hasClass( "ui-calendar-buttons" ), "calendar wrapper adds class about having buttons" );
});
test( "dateFormat", function() { deepEqual(
expect( 2 ); datepickerInstance.calendar.calendar( "option", key ),
var input = $( "#datepicker" ).val( "1/1/14" ).datepicker(), value,
picker = input.datepicker( "widget" ), "option " + key + ": correct value"
firstDayLink = picker.find( "td[id]:first a" ); );
input.datepicker( "open" ); if ( key === "dateFormat" ) {
firstDayLink.trigger( "mousedown" ); equal( input.val(), "Wednesday, January 1, 2014", "option " + key + ": updated format" );
equal( input.val(), "1/1/14", "default formatting" );
input.datepicker( "option", "dateFormat", { date: "full" } );
equal( input.val(), "Wednesday, January 1, 2014", "updated formatting" );
input.datepicker( "destroy" );
});
test( "eachDay", function() {
expect( 5 );
var timestamp,
input = $( "#datepicker" ).datepicker(),
picker = input.datepicker( "widget" ),
firstCell = picker.find( "td[id]:first" );
equal( firstCell.find( "a" ).length, 1, "days are selectable by default" );
timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
equal( new Date( timestamp ).getDate(), 1, "first available day is the 1st by default" );
// Do not render the 1st of the month
input.datepicker( "option", "eachDay", function( day ) {
if ( day.date === 1 ) {
day.render = false;
} }
}); });
firstCell = picker.find( "td[id]:first" );
timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
equal( new Date( timestamp ).getDate(), 2, "first available day is the 2nd" );
// Display the 1st of the month but make it not selectable.
input.datepicker( "option", "eachDay", function( day ) {
if ( day.date === 1 ) {
day.selectable = false;
}
});
firstCell = picker.find( "td[id]:first" );
equal( firstCell.find( "a" ).length, 0, "the 1st is not selectable" );
input.datepicker( "option", "eachDay", function( day ) {
if ( day.date === 1 ) {
day.extraClasses = "ui-custom";
}
});
ok( picker.find( "td[id]:first a" ).hasClass( "ui-custom" ), "extraClasses applied" );
input.datepicker( "destroy" );
}); });
asyncTest( "position", function() { asyncTest( "position", function() {
@ -140,68 +98,6 @@ asyncTest( "position", function() {
}); });
}); });
test( "showWeek", function() {
expect( 7 );
var input = $( "#datepicker" ).datepicker(),
container = input.datepicker( "widget" );
equal( container.find( "thead th" ).length, 7, "just 7 days, no column cell" );
equal( container.find( ".ui-calendar-week-col" ).length, 0,
"no week column cells present" );
input.datepicker( "destroy" );
input = $( "#datepicker" ).datepicker({ showWeek: true });
container = input.datepicker( "widget" );
equal( container.find( "thead th" ).length, 8, "7 days + a column cell" );
ok( container.find( "thead th:first" ).is( ".ui-calendar-week-col" ),
"first cell should have ui-calendar-week-col class name" );
equal( container.find( ".ui-calendar-week-col" ).length,
container.find( "tr" ).length, "one week cell for each week" );
input.datepicker( "destroy" );
input = $( "#datepicker" ).datepicker();
container = input.datepicker( "widget" );
equal( container.find( "thead th" ).length, 7, "no week column" );
input.datepicker( "option", "showWeek", true );
equal( container.find( "thead th" ).length, 8, "supports changing option after init" );
});
test( "min / max", function() {
expect( 14 );
var inp = TestHelpers.datepicker.init( "#datepicker" ),
minDate = new Date( 2008, 2 - 1, 29 ),
maxDate = new Date( 2008, 12 - 1, 7 );
inp.val( "6/4/08" ).datepicker( "option", { min: minDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min" );
ok( inp.datepicker( "isValid" ) );
inp.datepicker( "option", { min: null } ).val( "1/4/08" ).datepicker( "option", { min: minDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 4 ), "Min/max - value < min" );
ok( !inp.datepicker( "isValid" ) );
inp.datepicker( "option", { min: null } ).val( "6/4/08" ).datepicker( "option", { max: maxDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < max" );
ok( inp.datepicker( "isValid" ) );
inp.datepicker( "option", { max: null } ).val( "1/4/09" ).datepicker( "option", { max: maxDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2009, 1 - 1, 4 ), "Min/max - setDate > max" );
ok( !inp.datepicker( "isValid" ) );
inp.datepicker( "option", { max: null } ).val( "1/4/08" ).datepicker( "option", { min: minDate, max: maxDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 4 ), "Min/max - value < min" );
ok( !inp.datepicker( "isValid" ) );
inp.datepicker( "option", { max: null } ).val( "6/4/08" ).datepicker( "option", { min: minDate, max: maxDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min, < max" );
ok( inp.datepicker( "isValid" ) );
inp.datepicker( "option", { max: null } ).val( "1/4/09" ).datepicker( "option", { min: minDate, max: maxDate } );
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2009, 1 - 1, 4 ), "Min/max - value > max" );
ok( !inp.datepicker( "isValid" ) );
});
test( "Stop datepicker from appearing with beforeOpen event handler", function() { test( "Stop datepicker from appearing with beforeOpen event handler", function() {
expect( 3 ); expect( 3 );