events.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. module('Events', {
  2. setup: function(){
  3. this.input = $('<input type="text" value="31-03-2011">')
  4. .appendTo('#qunit-fixture')
  5. .datetimepicker({format: "dd-mm-yyyy"})
  6. .focus(); // Activate for visibility checks
  7. this.dp = this.input.data('datetimepicker')
  8. this.picker = this.dp.picker;
  9. },
  10. teardown: function(){
  11. this.picker.remove();
  12. }
  13. });
  14. test('Selecting a year from decade view triggers pickYear', function(){
  15. var target,
  16. triggered = 0;
  17. this.input.on('changeYear', function(){
  18. triggered++;
  19. });
  20. equal(this.dp.viewMode, 2);
  21. target = this.picker.find('.datetimepicker-days thead th.switch');
  22. ok(target.is(':visible'), 'View switcher is visible');
  23. target.click();
  24. ok(this.picker.find('.datetimepicker-months').is(':visible'), 'Month picker is visible');
  25. equal(this.dp.viewMode, 3);
  26. // Not modified when switching modes
  27. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 31));
  28. datesEqual(this.dp.date, UTCDate(2011, 2, 31));
  29. target = this.picker.find('.datetimepicker-months thead th.switch');
  30. ok(target.is(':visible'), 'View switcher is visible');
  31. target.click();
  32. ok(this.picker.find('.datetimepicker-years').is(':visible'), 'Year picker is visible');
  33. equal(this.dp.viewMode, 4);
  34. // Not modified when switching modes
  35. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 31));
  36. datesEqual(this.dp.date, UTCDate(2011, 2, 31));
  37. // Change years to test internal state changes
  38. target = this.picker.find('.datetimepicker-years tbody span:contains(2010)');
  39. target.click();
  40. equal(this.dp.viewMode, 3);
  41. // Only viewDate modified
  42. datesEqual(this.dp.viewDate, UTCDate(2010, 2, 1));
  43. datesEqual(this.dp.date, UTCDate(2011, 2, 31));
  44. equal(triggered, 1);
  45. });
  46. test('Selecting a month from year view triggers pickMonth', function(){
  47. var target,
  48. triggered = 0;
  49. this.input.on('changeMonth', function(){
  50. triggered++;
  51. });
  52. equal(this.dp.viewMode, 2);
  53. target = this.picker.find('.datetimepicker-days thead th.switch');
  54. ok(target.is(':visible'), 'View switcher is visible');
  55. target.click();
  56. ok(this.picker.find('.datetimepicker-months').is(':visible'), 'Month picker is visible');
  57. equal(this.dp.viewMode, 3);
  58. // Not modified when switching modes
  59. datesEqual(this.dp.viewDate, UTCDate(2011, 2, 31));
  60. datesEqual(this.dp.date, UTCDate(2011, 2, 31));
  61. target = this.picker.find('.datetimepicker-months tbody span:contains(Apr)');
  62. target.click();
  63. equal(this.dp.viewMode, 2);
  64. // Only viewDate modified
  65. datesEqual(this.dp.viewDate, UTCDate(2011, 3, 1));
  66. datesEqual(this.dp.date, UTCDate(2011, 2, 31));
  67. equal(triggered, 1);
  68. });