2011.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. module('Keyboard Navigation 2011', {
  2. setup: function(){
  3. /*
  4. Tests start with picker on March 31, 2011. Fun facts:
  5. * March 1, 2011 was on a Tuesday
  6. * March 31, 2011 was on a Thursday
  7. */
  8. this.input = $('<input type="text" value="31-03-2011">')
  9. .appendTo('#qunit-fixture')
  10. .datetimepicker({format: "dd-mm-yyyy"})
  11. .focus(); // Activate for visibility checks
  12. this.dp = this.input.data('datetimepicker')
  13. this.picker = this.dp.picker;
  14. },
  15. teardown: function(){
  16. this.picker.remove();
  17. }
  18. });
  19. test('Regression: by week (up/down arrows); up from Mar 6, 2011 should go to Feb 27, 2011', function(){
  20. var target;
  21. this.input.val('06-03-2011').datetimepicker('update');
  22. equal(this.dp.viewMode, 2);
  23. target = this.picker.find('.datetimepicker-days thead th.switch');
  24. equal(target.text(), 'March 2011', 'Title is "March 2011"');
  25. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 6));
  26. datesEqual(this.dp.date, UTCDate(2011, 2, 6));
  27. // Navigation: -1 week, up arrow key
  28. this.input.trigger({
  29. type: 'keydown',
  30. keyCode: 38
  31. });
  32. datesEqual(this.dp.viewDate, UTCDate(2011, 1, 27));
  33. datesEqual(this.dp.date, UTCDate(2011, 1, 27));
  34. target = this.picker.find('.datetimepicker-days thead th.switch');
  35. equal(target.text(), 'February 2011', 'Title is "February 2011"');
  36. });
  37. test('Regression: by day (left/right arrows); left from Mar 1, 2011 should go to Feb 28, 2011', function(){
  38. var target;
  39. this.input.val('01-03-2011').datetimepicker('update');
  40. equal(this.dp.viewMode, 2);
  41. target = this.picker.find('.datetimepicker-days thead th.switch');
  42. equal(target.text(), 'March 2011', 'Title is "March 2011"');
  43. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 1));
  44. datesEqual(this.dp.date, UTCDate(2011, 2, 1));
  45. // Navigation: -1 day left arrow key
  46. this.input.trigger({
  47. type: 'keydown',
  48. keyCode: 37
  49. });
  50. datesEqual(this.dp.viewDate, UTCDate(2011, 1, 28));
  51. datesEqual(this.dp.date, UTCDate(2011, 1, 28));
  52. target = this.picker.find('.datetimepicker-days thead th.switch');
  53. equal(target.text(), 'February 2011', 'Title is "February 2011"');
  54. });
  55. test('Regression: by month (shift + left/right arrows); left from Mar 15, 2011 should go to Feb 15, 2011', function(){
  56. var target;
  57. this.input.val('15-03-2011').datetimepicker('update');
  58. equal(this.dp.viewMode, 2);
  59. target = this.picker.find('.datetimepicker-days thead th.switch');
  60. equal(target.text(), 'March 2011', 'Title is "March 2011"');
  61. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 15));
  62. datesEqual(this.dp.date, UTCDate(2011, 2, 15));
  63. // Navigation: -1 month, shift + left arrow key
  64. this.input.trigger({
  65. type: 'keydown',
  66. keyCode: 37,
  67. shiftKey: true
  68. });
  69. datesEqual(this.dp.viewDate, UTCDate(2011, 1, 15));
  70. datesEqual(this.dp.date, UTCDate(2011, 1, 15));
  71. target = this.picker.find('.datetimepicker-days thead th.switch');
  72. equal(target.text(), 'February 2011', 'Title is "February 2011"');
  73. });