mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Added tests for 3191 - handling NaN and other invalid values for relative dates
This commit is contained in:
parent
c5635d6350
commit
732c7fb7d5
@ -744,63 +744,84 @@ test('mouse', function() {
|
|||||||
test('defaultDate', function() {
|
test('defaultDate', function() {
|
||||||
var inp = init('#inp');
|
var inp = init('#inp');
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
inp.val('').datepicker('show');
|
inp.val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date null');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date null');
|
||||||
|
// numeric values
|
||||||
|
inp.datepicker('change', {defaultDate: -2}).
|
||||||
|
datepicker('hide').val('').datepicker('show').
|
||||||
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
|
date.setDate(date.getDate() - 2);
|
||||||
|
equalsDate(inp.datepicker('getDate'), date, 'Default date -2');
|
||||||
|
inp.datepicker('change', {defaultDate: 3}).
|
||||||
|
datepicker('hide').val('').datepicker('show').
|
||||||
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
|
date.setDate(date.getDate() + 5);
|
||||||
|
equalsDate(inp.datepicker('getDate'), date, 'Default date 3');
|
||||||
|
inp.datepicker('change', {defaultDate: 1 / 0}).
|
||||||
|
datepicker('hide').val('').datepicker('show').
|
||||||
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
|
date.setDate(date.getDate() - 3);
|
||||||
|
equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity');
|
||||||
|
inp.datepicker('change', {defaultDate: 1 / 'a'}).
|
||||||
|
datepicker('hide').val('').datepicker('show').
|
||||||
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
|
equalsDate(inp.datepicker('getDate'), date, 'Default date NaN');
|
||||||
|
// string values
|
||||||
inp.datepicker('change', {defaultDate: '-1d'}).
|
inp.datepicker('change', {defaultDate: '-1d'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date.setDate(date.getDate() - 1);
|
date.setDate(date.getDate() - 1);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date -1d');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date -1d');
|
||||||
inp.datepicker('change', {defaultDate: '+3D'}).
|
inp.datepicker('change', {defaultDate: '+3D'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date.setDate(date.getDate() + 4);
|
date.setDate(date.getDate() + 4);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date +3D');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date +3D');
|
||||||
inp.datepicker('change', {defaultDate: ' -2 w '}).
|
inp.datepicker('change', {defaultDate: ' -2 w '}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date = new Date();
|
date = new Date();
|
||||||
date.setDate(date.getDate() - 14);
|
date.setDate(date.getDate() - 14);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w');
|
||||||
inp.datepicker('change', {defaultDate: '+1 W'}).
|
inp.datepicker('change', {defaultDate: '+1 W'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date.setDate(date.getDate() + 21);
|
date.setDate(date.getDate() + 21);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W');
|
||||||
inp.datepicker('change', {defaultDate: ' -1 m '}).
|
inp.datepicker('change', {defaultDate: ' -1 m '}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date = new Date();
|
date = new Date();
|
||||||
date.setMonth(date.getMonth() - 1);
|
date.setMonth(date.getMonth() - 1);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m');
|
||||||
inp.datepicker('change', {defaultDate: '+2M'}).
|
inp.datepicker('change', {defaultDate: '+2M'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date.setMonth(date.getMonth() + 3);
|
date.setMonth(date.getMonth() + 3);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date +2M');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date +2M');
|
||||||
inp.datepicker('change', {defaultDate: '-2y'}).
|
inp.datepicker('change', {defaultDate: '-2y'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date = new Date();
|
date = new Date();
|
||||||
date.setFullYear(date.getFullYear() - 2);
|
date.setFullYear(date.getFullYear() - 2);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date -2y');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date -2y');
|
||||||
inp.datepicker('change', {defaultDate: '+1 Y '}).
|
inp.datepicker('change', {defaultDate: '+1 Y '}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date.setFullYear(date.getFullYear() + 3);
|
date.setFullYear(date.getFullYear() + 3);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y');
|
||||||
inp.datepicker('change', {defaultDate: '+1M +10d'}).
|
inp.datepicker('change', {defaultDate: '+1M +10d'}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
date = new Date();
|
date = new Date();
|
||||||
date.setMonth(date.getMonth() + 1);
|
date.setMonth(date.getMonth() + 1);
|
||||||
date.setDate(date.getDate() + 10);
|
date.setDate(date.getDate() + 10);
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d');
|
||||||
date = new Date(2007, 1 - 1, 26);
|
date = new Date(2007, 1 - 1, 26);
|
||||||
inp.datepicker('change', {defaultDate: date}).
|
inp.datepicker('change', {defaultDate: date}).
|
||||||
datepicker('hide').val('').datepicker('show');
|
datepicker('hide').val('').datepicker('show').
|
||||||
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
|
||||||
equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007');
|
equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user