Tests: Test only valid values for Datepicker defaultDate, min/maxDate

The docs say that valid periods when using string value and
period pairs as relative dates are "y", "m", "w", and "d"
https://api.jqueryui.com/datepicker/

Closes gh-2143
This commit is contained in:
Kenneth DeBacker 2023-03-30 07:05:41 -04:00 committed by GitHub
parent 988b73d20f
commit f8990e68e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,49 +303,49 @@ QUnit.test( "defaultDate", function( assert ) {
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date.setDate( date.getDate() - 1 ); date.setDate( date.getDate() - 1 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -1d" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -1d" );
inp.datepicker( "option", { defaultDate: "+3D" } ). inp.datepicker( "option", { defaultDate: "+3d" } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date.setDate( date.getDate() + 4 ); date.setDate( date.getDate() + 4 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +3D" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +3d" );
inp.datepicker( "option", { defaultDate: " -2 w " } ). inp.datepicker( "option", { defaultDate: " -2 w " } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date = new Date(); date = new Date();
date.setDate( date.getDate() - 14 ); date.setDate( date.getDate() - 14 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -2 w" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -2 w" );
inp.datepicker( "option", { defaultDate: "+1 W" } ). inp.datepicker( "option", { defaultDate: "+1 w" } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date.setDate( date.getDate() + 21 ); date.setDate( date.getDate() + 21 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1 W" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1 w" );
inp.datepicker( "option", { defaultDate: " -1 m " } ). inp.datepicker( "option", { defaultDate: " -1 m " } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date = testHelper.addMonths( new Date(), -1 ); date = testHelper.addMonths( new Date(), -1 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -1 m" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -1 m" );
inp.datepicker( "option", { defaultDate: "+2M" } ). inp.datepicker( "option", { defaultDate: "+2m" } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date = testHelper.addMonths( new Date(), 2 ); date = testHelper.addMonths( new Date(), 2 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +2M" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +2m" );
inp.datepicker( "option", { defaultDate: "-2y" } ). inp.datepicker( "option", { defaultDate: "-2y" } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date = new Date(); date = new Date();
date.setFullYear( date.getFullYear() - 2 ); date.setFullYear( date.getFullYear() - 2 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -2y" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date -2y" );
inp.datepicker( "option", { defaultDate: "+1 Y " } ). inp.datepicker( "option", { defaultDate: "+1 y " } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date.setFullYear( date.getFullYear() + 3 ); date.setFullYear( date.getFullYear() + 3 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1 Y" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1 y" );
inp.datepicker( "option", { defaultDate: "+1M +10d" } ). inp.datepicker( "option", { defaultDate: "+1m +10d" } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ). datepicker( "hide" ).val( "" ).datepicker( "show" ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
date = testHelper.addMonths( new Date(), 1 ); date = testHelper.addMonths( new Date(), 1 );
date.setDate( date.getDate() + 10 ); date.setDate( date.getDate() + 10 );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1M +10d" ); testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Default date +1m +10d" );
// String date values // String date values
inp.datepicker( "option", { defaultDate: "07/04/2007" } ). inp.datepicker( "option", { defaultDate: "07/04/2007" } ).
@ -486,19 +486,19 @@ QUnit.test( "minMax", function( assert ) {
// Relative dates // Relative dates
date = new Date(); date = new Date();
date.setDate( date.getDate() - 7 ); date.setDate( date.getDate() - 7 );
inp.datepicker( "option", { minDate: "-1w", maxDate: "+1 M +10 D " } ). inp.datepicker( "option", { minDate: "-1w", maxDate: "+1 m +10 d " } ).
datepicker( "hide" ).val( "" ).datepicker( "show" ); datepicker( "hide" ).val( "" ).datepicker( "show" );
inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ). inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date,
"Min/max - -1w, +1 M +10 D - ctrl+pgup" ); "Min/max - -1w, +1 m +10 d - ctrl+pgup" );
date = testHelper.addMonths( new Date(), 1 ); date = testHelper.addMonths( new Date(), 1 );
date.setDate( date.getDate() + 10 ); date.setDate( date.getDate() + 10 );
inp.val( "" ).datepicker( "show" ); inp.val( "" ).datepicker( "show" );
inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ). inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ).
simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date,
"Min/max - -1w, +1 M +10 D - ctrl+pgdn" ); "Min/max - -1w, +1 m +10 d - ctrl+pgdn" );
// With existing date // With existing date
inp = testHelper.init( "#inp" ); inp = testHelper.init( "#inp" );
@ -524,7 +524,7 @@ QUnit.test( "minMax", function( assert ) {
inp.val( "" ).datepicker( "option", { inp.val( "" ).datepicker( "option", {
minDate: new Date( 1900, 0, 1 ), minDate: new Date( 1900, 0, 1 ),
maxDate: "-7Y", maxDate: "-7y",
yearRange: "1900:-7" yearRange: "1900:-7"
} ); } );
assert.ok( dp.find( ".ui-datepicker-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - relative - next button disabled" ); assert.ok( dp.find( ".ui-datepicker-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - relative - next button disabled" );