methods.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. module('Methods', {
  2. setup: function(){
  3. this.input = $('<input type="text" value="31-03-2011">')
  4. .appendTo('#qunit-fixture')
  5. .datepicker({format: "dd-mm-yyyy"});
  6. this.dp = this.input.data('datepicker');
  7. this.picker = this.dp.picker;
  8. },
  9. teardown: function(){
  10. this.dp.remove();
  11. }
  12. });
  13. test('remove', function(){
  14. var returnedObject = this.dp.remove();
  15. // ...
  16. strictEqual(returnedObject, this.dp, "is chainable");
  17. });
  18. test('show', function(){
  19. var returnedObject = this.dp.show();
  20. // ...
  21. strictEqual(returnedObject, this.dp, "is chainable");
  22. });
  23. test('hide', function(){
  24. var returnedObject = this.dp.hide();
  25. // ...
  26. strictEqual(returnedObject, this.dp, "is chainable");
  27. });
  28. test('update - String', function(){
  29. var returnedObject = this.dp.update('13-03-2012');
  30. datesEqual(this.dp.dates[0], UTCDate(2012, 2, 13));
  31. var date = this.dp.picker.find('.datepicker-days td:contains(13)');
  32. ok(date.hasClass('active'), 'Date is selected');
  33. strictEqual(returnedObject, this.dp, "is chainable");
  34. });
  35. test('update - Date', function(){
  36. var returnedObject = this.dp.update(new Date(2012, 2, 13));
  37. datesEqual(this.dp.dates[0], UTCDate(2012, 2, 13));
  38. var date = this.dp.picker.find('.datepicker-days td:contains(13)');
  39. ok(date.hasClass('active'), 'Date is selected');
  40. strictEqual(returnedObject, this.dp, "is chainable");
  41. });
  42. test('update - Date with time', function(){
  43. var returnedObject = this.dp.update(new Date(2012, 2, 13, 23, 59, 59, 999));
  44. datesEqual(this.dp.dates[0], UTCDate(2012, 2, 13, 23, 59, 59, 999));
  45. var date = this.dp.picker.find('.datepicker-days td:contains(13)');
  46. ok(date.hasClass('active'), 'Date is selected');
  47. strictEqual(returnedObject, this.dp, "is chainable");
  48. });
  49. test('update - null', function(){
  50. var returnedObject = this.dp.update(null);
  51. equal(this.dp.dates[0], undefined);
  52. var selected = this.dp.picker.find('.datepicker-days td.active');
  53. equal(selected.length, 0, 'No date is selected');
  54. strictEqual(returnedObject, this.dp, "is chainable");
  55. });
  56. test('setDate', function(){
  57. var date_in = new Date(2013, 1, 1),
  58. expected_date = new Date(Date.UTC(2013, 1, 1)),
  59. returnedObject;
  60. notEqual(this.dp.dates[0], date_in);
  61. returnedObject = this.dp.setDate(date_in);
  62. strictEqual(returnedObject, this.dp, "is chainable");
  63. datesEqual(this.dp.dates[0], expected_date);
  64. });
  65. test('setUTCDate', function(){
  66. var date_in = new Date(Date.UTC(2012, 3, 5)),
  67. expected_date = date_in,
  68. returnedObject;
  69. notEqual(this.dp.dates[0], date_in);
  70. returnedObject = this.dp.setUTCDate(date_in);
  71. strictEqual(returnedObject, this.dp, "is chainable");
  72. datesEqual(this.dp.dates[0], expected_date);
  73. });
  74. test('setStartDate', function(){
  75. var date_in = new Date(2012, 3, 5),
  76. expected_date = new Date(Date.UTC(2012, 3, 5)),
  77. returnedObject = this.dp.setStartDate(date_in);
  78. // ...
  79. datesEqual(this.dp.o.startDate, expected_date);
  80. strictEqual(returnedObject, this.dp, "is chainable");
  81. });
  82. test('setEndDate', function(){
  83. var date_in = new Date(2012, 3, 5),
  84. expected_date = new Date(Date.UTC(2012, 3, 5)),
  85. returnedObject = this.dp.setEndDate(date_in);
  86. // ...
  87. datesEqual(this.dp.o.endDate, expected_date);
  88. strictEqual(returnedObject, this.dp, "is chainable");
  89. });
  90. test('getStartDate', function(){
  91. var date_in = new Date(2012, 3, 5),
  92. expected_date = new Date(Date.UTC(2012, 3, 5)),
  93. returnedObject = this.dp.setStartDate(date_in);
  94. // ...
  95. datesEqual(returnedObject.getStartDate(), expected_date);
  96. strictEqual(returnedObject, this.dp, "is chainable");
  97. });
  98. test('getEndDate', function(){
  99. var date_in = new Date(2012, 3, 5),
  100. expected_date = new Date(Date.UTC(2012, 3, 5)),
  101. returnedObject = this.dp.setEndDate(date_in);
  102. // ...
  103. datesEqual(returnedObject.getEndDate(), expected_date);
  104. strictEqual(returnedObject, this.dp, "is chainable");
  105. });
  106. test('setDaysOfWeekDisabled - String', function(){
  107. var days_in = "0,6",
  108. expected_days = [0,6],
  109. returnedObject = this.dp.setDaysOfWeekDisabled(days_in);
  110. // ...
  111. deepEqual(this.dp.o.daysOfWeekDisabled, expected_days);
  112. strictEqual(returnedObject, this.dp, "is chainable");
  113. });
  114. test('setDaysOfWeekDisabled - Array', function(){
  115. var days_in = [0,6],
  116. expected_days = days_in,
  117. returnedObject = this.dp.setDaysOfWeekDisabled(days_in);
  118. // ...
  119. deepEqual(this.dp.o.daysOfWeekDisabled, expected_days);
  120. strictEqual(returnedObject, this.dp, "is chainable");
  121. });
  122. test('setDatesDisabled', function(){
  123. var monthShown = this.picker.find('.datepicker-days thead th.datepicker-switch');
  124. var returnedObject = this.dp.setDatesDisabled(['01-03-2011']);
  125. ok(this.picker.find('.datepicker-days tbody td.day:not(.old):first').hasClass('disabled'), 'day is disabled');
  126. this.dp.setDatesDisabled(['01-01-2011']);
  127. equal(monthShown.text(), 'March 2011', 'should not change viewDate');
  128. strictEqual(returnedObject, this.dp, "is chainable");
  129. });
  130. test('setValue', function(){
  131. var returnedObject = this.dp.setValue();
  132. // ...
  133. strictEqual(returnedObject, this.dp, "is chainable");
  134. });
  135. test('place', function(){
  136. var returnedObject = this.dp.place();
  137. // ...
  138. strictEqual(returnedObject, this.dp, "is chainable");
  139. });
  140. test('moveMonth - can handle invalid date', function(){
  141. // any input which results in an invalid date, f.e. an incorrectly formatted.
  142. var invalidDate = new Date("invalid"),
  143. returnedObject = this.dp.moveMonth(invalidDate, 1);
  144. // ...
  145. equal(this.input.val(), "31-03-2011", "date is reset");
  146. });
  147. test('parseDate - outputs correct value', function(){
  148. var parsedDate = $.fn.datepicker.DPGlobal.parseDate('11/13/2015', $.fn.datepicker.DPGlobal.parseFormat('mm/dd/yyyy'), 'en');
  149. equal(parsedDate.getUTCDate(), "13", "date is correct");
  150. equal(parsedDate.getUTCMonth(), "10", "month is correct");
  151. equal(parsedDate.getUTCFullYear(), "2015", "fullyear is correct");
  152. });
  153. test('parseDate - outputs correct value for yyyy\u5E74mm\u6708dd\u65E5 format', function(){
  154. var parsedDate = $.fn.datepicker.DPGlobal.parseDate('2015\u5E7411\u670813', $.fn.datepicker.DPGlobal.parseFormat('yyyy\u5E74mm\u6708dd\u65E5'), 'ja');
  155. equal(parsedDate.getUTCDate(), "13", "date is correct");
  156. equal(parsedDate.getUTCMonth(), "10", "month is correct");
  157. equal(parsedDate.getUTCFullYear(), "2015", "fullyear is correct");
  158. });
  159. test('parseDate - outputs correct value for dates containing unicodes', function(){
  160. var parsedDate = $.fn.datepicker.DPGlobal.parseDate('\u5341\u4E00\u6708 13 2015', $.fn.datepicker.DPGlobal.parseFormat('MM dd yyyy'), 'zh-CN');
  161. equal(parsedDate.getUTCDate(), "13", "date is correct");
  162. equal(parsedDate.getUTCMonth(), "10", "month is correct");
  163. equal(parsedDate.getUTCFullYear(), "2015", "fullyear is correct");
  164. });