options.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. module('Options', {
  2. setup: function(){},
  3. teardown: function(){
  4. return
  5. $('#qunit-fixture *').each(function(){
  6. var t = $(this);
  7. if ('datetimepicker' in t.data())
  8. t.data('datetimepicker').picker.remove();
  9. });
  10. }
  11. });
  12. test('Autoclose', function(){
  13. var input = $('<input />')
  14. .appendTo('#qunit-fixture')
  15. .val('2012-03-05')
  16. .datetimepicker({
  17. format: 'yyyy-mm-dd',
  18. autoclose: true,
  19. minView: 2,
  20. viewSelect: 2
  21. }),
  22. dp = input.data('datetimepicker'),
  23. picker = dp.picker,
  24. target;
  25. input.focus();
  26. ok(picker.is(':visible'), 'Picker is visible');
  27. target = picker.find('.datetimepicker-days tbody td:nth(7)');
  28. equal(target.text(), '4'); // Mar 4
  29. target.click();
  30. ok(picker.is(':not(:visible)'), 'Picker is hidden');
  31. datesEqual(dp.date, UTCDate(2012, 2, 4));
  32. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  33. });
  34. test('Startview: year view (integer)', function(){
  35. var input = $('<input />')
  36. .appendTo('#qunit-fixture')
  37. .val('2012-03-05')
  38. .datetimepicker({
  39. format: 'yyyy-mm-dd',
  40. startView: 3,
  41. viewSelect: 2
  42. }),
  43. dp = input.data('datetimepicker'),
  44. picker = dp.picker,
  45. target;
  46. input.focus();
  47. ok(picker.find('.datetimepicker-days').is(':not(:visible)'), 'Days view hidden');
  48. ok(picker.find('.datetimepicker-months').is(':visible'), 'Months view visible');
  49. ok(picker.find('.datetimepicker-years').is(':not(:visible)'), 'Years view hidden');
  50. });
  51. test('Startview: year view (string)', function(){
  52. var input = $('<input />')
  53. .appendTo('#qunit-fixture')
  54. .val('2012-03-05')
  55. .datetimepicker({
  56. format: 'yyyy-mm-dd',
  57. startView: 'year',
  58. viewSelect: 2
  59. }),
  60. dp = input.data('datetimepicker'),
  61. picker = dp.picker,
  62. target;
  63. input.focus();
  64. ok(picker.find('.datetimepicker-days').is(':not(:visible)'), 'Days view hidden');
  65. ok(picker.find('.datetimepicker-months').is(':visible'), 'Months view visible');
  66. ok(picker.find('.datetimepicker-years').is(':not(:visible)'), 'Years view hidden');
  67. });
  68. test('Startview: decade view (integer)', function(){
  69. var input = $('<input />')
  70. .appendTo('#qunit-fixture')
  71. .val('2012-03-05')
  72. .datetimepicker({
  73. format: 'yyyy-mm-dd',
  74. startView: 4
  75. }),
  76. dp = input.data('datetimepicker'),
  77. picker = dp.picker,
  78. target;
  79. input.focus();
  80. ok(picker.find('.datetimepicker-days').is(':not(:visible)'), 'Days view hidden');
  81. ok(picker.find('.datetimepicker-months').is(':not(:visible)'), 'Months view hidden');
  82. ok(picker.find('.datetimepicker-years').is(':visible'), 'Years view visible');
  83. });
  84. test('Startview: decade view (string)', function(){
  85. var input = $('<input />')
  86. .appendTo('#qunit-fixture')
  87. .val('2012-03-05')
  88. .datetimepicker({
  89. format: 'yyyy-mm-dd',
  90. startView: 'decade'
  91. }),
  92. dp = input.data('datetimepicker'),
  93. picker = dp.picker,
  94. target;
  95. input.focus();
  96. ok(picker.find('.datetimepicker-days').is(':not(:visible)'), 'Days view hidden');
  97. ok(picker.find('.datetimepicker-months').is(':not(:visible)'), 'Months view hidden');
  98. ok(picker.find('.datetimepicker-years').is(':visible'), 'Years view visible');
  99. });
  100. test('Today Button: today button not default', function(){
  101. var input = $('<input />')
  102. .appendTo('#qunit-fixture')
  103. .val('2012-03-05')
  104. .datetimepicker({
  105. format: 'yyyy-mm-dd'
  106. }),
  107. dp = input.data('datetimepicker'),
  108. picker = dp.picker,
  109. target;
  110. input.focus();
  111. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  112. ok(picker.find('.datetimepicker-days tfoot .today').is(':not(:visible)'), 'Today button not visible');
  113. });
  114. test('Today Button: today visibility when enabled', function(){
  115. var input = $('<input />')
  116. .appendTo('#qunit-fixture')
  117. .val('2012-03-05')
  118. .datetimepicker({
  119. format: 'yyyy-mm-dd',
  120. todayBtn: true
  121. }),
  122. dp = input.data('datetimepicker'),
  123. picker = dp.picker,
  124. target;
  125. input.focus();
  126. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  127. ok(picker.find('.datetimepicker-days tfoot .today').is(':visible'), 'Today button visible');
  128. picker.find('.datetimepicker-days thead th.switch').click();
  129. ok(picker.find('.datetimepicker-months').is(':visible'), 'Months view visible');
  130. ok(picker.find('.datetimepicker-months tfoot .today').is(':visible'), 'Today button visible');
  131. picker.find('.datetimepicker-months thead th.switch').click();
  132. ok(picker.find('.datetimepicker-years').is(':visible'), 'Years view visible');
  133. ok(picker.find('.datetimepicker-years tfoot .today').is(':visible'), 'Today button visible');
  134. });
  135. test('Today Button: data-api', function(){
  136. var input = $('<input data-date-today-btn="true" />')
  137. .appendTo('#qunit-fixture')
  138. .val('2012-03-05')
  139. .datetimepicker({
  140. format: 'yyyy-mm-dd'
  141. }),
  142. dp = input.data('datetimepicker'),
  143. picker = dp.picker,
  144. target;
  145. input.focus();
  146. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  147. ok(picker.find('.datetimepicker-days tfoot .today').is(':visible'), 'Today button visible');
  148. });
  149. test('Today Button: moves to today\'s date', function(){
  150. var input = $('<input />')
  151. .appendTo('#qunit-fixture')
  152. .val('2012-03-05')
  153. .datetimepicker({
  154. format: 'yyyy-mm-dd',
  155. todayBtn: true
  156. }),
  157. dp = input.data('datetimepicker'),
  158. picker = dp.picker,
  159. target;
  160. input.focus();
  161. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  162. ok(picker.find('.datetimepicker-days tfoot .today').is(':visible'), 'Today button visible');
  163. target = picker.find('.datetimepicker-days tfoot .today');
  164. target.click();
  165. var d = new Date(),
  166. today = UTCDate(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
  167. datesEqual(dp.viewDate, today);
  168. //datesEqual(dp.date, UTCDate(2012, 2, 5));
  169. });
  170. test('Today Button: "linked" selects today\'s date', function(){
  171. var input = $('<input />')
  172. .appendTo('#qunit-fixture')
  173. .val('2012-03-05')
  174. .datetimepicker({
  175. format: 'yyyy-mm-dd',
  176. todayBtn: "linked"
  177. }),
  178. dp = input.data('datetimepicker'),
  179. picker = dp.picker,
  180. target;
  181. input.focus();
  182. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  183. ok(picker.find('.datetimepicker-days tfoot .today').is(':visible'), 'Today button visible');
  184. target = picker.find('.datetimepicker-days tfoot .today');
  185. target.click();
  186. var d = new Date(),
  187. today = UTCDate(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
  188. datesEqual(dp.viewDate, today);
  189. datesEqual(dp.date, today);
  190. });
  191. test('Today Highlight: today\'s date is not highlighted by default', patch_date(function(Date){
  192. Date.now = UTCDate(2012, 2, 15);
  193. var input = $('<input />')
  194. .appendTo('#qunit-fixture')
  195. .val('2012-03-05')
  196. .datetimepicker({
  197. format: 'yyyy-mm-dd'
  198. }),
  199. dp = input.data('datetimepicker'),
  200. picker = dp.picker,
  201. target;
  202. input.focus();
  203. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  204. equal(picker.find('.datetimepicker-days thead .switch').text(), 'March 2012', 'Title is "March 2012"');
  205. target = picker.find('.datetimepicker-days tbody td:contains(15)');
  206. ok(!target.hasClass('today'), 'Today is not marked with "today" class');
  207. target = picker.find('.datetimepicker-days tbody td:contains(14)');
  208. ok(!target.hasClass('today'), 'Yesterday is not marked with "today" class');
  209. target = picker.find('.datetimepicker-days tbody td:contains(16)');
  210. ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
  211. }));
  212. test('Today Highlight: today\'s date is highlighted when not active', patch_date(function(Date){
  213. Date.now = new Date(2012, 2, 15);
  214. var input = $('<input />')
  215. .appendTo('#qunit-fixture')
  216. .val('2012-03-05')
  217. .datetimepicker({
  218. format: 'yyyy-mm-dd',
  219. todayHighlight: true
  220. }),
  221. dp = input.data('datetimepicker'),
  222. picker = dp.picker,
  223. target;
  224. input.focus();
  225. ok(picker.find('.datetimepicker-days').is(':visible'), 'Days view visible');
  226. equal(picker.find('.datetimepicker-days thead .switch').text(), 'March 2012', 'Title is "March 2012"');
  227. target = picker.find('.datetimepicker-days tbody td:contains(15)');
  228. ok(target.hasClass('today'), 'Today is marked with "today" class');
  229. target = picker.find('.datetimepicker-days tbody td:contains(14)');
  230. ok(!target.hasClass('today'), 'Yesterday is not marked with "today" class');
  231. target = picker.find('.datetimepicker-days tbody td:contains(16)');
  232. ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
  233. }));
  234. test('DaysOfWeekDisabled', function(){
  235. var input = $('<input />')
  236. .appendTo('#qunit-fixture')
  237. .val('2012-10-26')
  238. .datetimepicker({
  239. format: 'yyyy-mm-dd',
  240. daysOfWeekDisabled: '1,5'
  241. }),
  242. dp = input.data('datetimepicker'),
  243. picker = dp.picker,
  244. target;
  245. input.focus();
  246. target = picker.find('.datetimepicker-days tbody td:nth(22)');
  247. ok(target.hasClass('disabled'), 'Day of week is disabled');
  248. target = picker.find('.datetimepicker-days tbody td:nth(24)');
  249. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  250. target = picker.find('.datetimepicker-days tbody td:nth(26)');
  251. ok(target.hasClass('disabled'), 'Day of week is disabled');
  252. });
  253. test('startDate: Custom value', function(){
  254. var input = $('<input />')
  255. .appendTo('#qunit-fixture')
  256. .val('2013-01-25')
  257. .datetimepicker({
  258. format: 'yyyy-mm-dd',
  259. startView: 2,
  260. startDate: "2013-01-24 15:30",
  261. viewSelect: 2
  262. }),
  263. dp = input.data('datetimepicker'),
  264. picker = dp.picker,
  265. target;
  266. input.focus();
  267. ok(picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(2)').hasClass('disabled'), 'The previous day is disabled');
  268. target = picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(4)')
  269. ok(!target.hasClass('disabled'), 'The starting day is enabled');
  270. target.click()
  271. ok(picker.find('.datetimepicker-hours tbody span:nth(14)').hasClass('disabled'), 'The previous hour is disabled');
  272. target = picker.find('.datetimepicker-hours tbody span:nth(15)')
  273. ok(!target.hasClass('disabled'), 'The starting hour is enabled');
  274. target.click()
  275. ok(picker.find('.datetimepicker-minutes tbody span:nth(5)').hasClass('disabled'), 'The previous minute is disabled');
  276. ok(!picker.find('.datetimepicker-minutes tbody span:nth(6)').hasClass('disabled'), 'The starting minute is enabled');
  277. });
  278. test('startDate: Custom value', function(){
  279. var input = $('<input />')
  280. .appendTo('#qunit-fixture')
  281. .val('2013-01-25')
  282. .datetimepicker({
  283. format: 'yyyy-mm-dd',
  284. startView: 2,
  285. startDate: "2013-01-24 15:30",
  286. viewSelect: 2
  287. }),
  288. dp = input.data('datetimepicker'),
  289. picker = dp.picker,
  290. target;
  291. input.focus();
  292. ok(picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(3)').hasClass('disabled'), 'The previous day is disabled');
  293. target = picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(4)')
  294. ok(!target.hasClass('disabled'), 'The starting day is enabled');
  295. target.click()
  296. ok(picker.find('.datetimepicker-hours tbody span:nth(14)').hasClass('disabled'), 'The previous hour is disabled');
  297. target = picker.find('.datetimepicker-hours tbody span:nth(15)')
  298. ok(!target.hasClass('disabled'), 'The starting hour is enabled');
  299. target.click()
  300. ok(picker.find('.datetimepicker-minutes tbody span:nth(5)').hasClass('disabled'), 'The previous minute is disabled');
  301. ok(!picker.find('.datetimepicker-minutes tbody span:nth(6)').hasClass('disabled'), 'The starting minute is enabled');
  302. });
  303. test('endDate: Custom value', function(){
  304. var input = $('<input />')
  305. .appendTo('#qunit-fixture')
  306. .val('2013-01-25')
  307. .datetimepicker({
  308. format: 'yyyy-mm-dd',
  309. startView: 2,
  310. endDate: "2013-01-24 15:30",
  311. viewSelect: 2
  312. }),
  313. dp = input.data('datetimepicker'),
  314. picker = dp.picker,
  315. target;
  316. input.focus();
  317. ok(picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(5)').hasClass('disabled'), 'The next day is disabled');
  318. target = picker.find('.datetimepicker-days tbody tr:nth(3) td:nth(4)')
  319. ok(!target.hasClass('disabled'), 'The last day is enabled');
  320. target.click()
  321. ok(picker.find('.datetimepicker-hours tbody span:nth(16)').hasClass('disabled'), 'The next hour is disabled');
  322. target = picker.find('.datetimepicker-hours tbody span:nth(15)')
  323. ok(!target.hasClass('disabled'), 'The last hour is enabled');
  324. target.click()
  325. ok(picker.find('.datetimepicker-minutes tbody span:nth(7)').hasClass('disabled'), 'The next minute is disabled');
  326. ok(!picker.find('.datetimepicker-minutes tbody span:nth(6)').hasClass('disabled'), 'The last minute is enabled');
  327. });
  328. test('zIndex: set in options', function(){
  329. var zIndex = 77;
  330. var input = $('<input />')
  331. .appendTo('#qunit-fixture')
  332. .val('2013-01-25')
  333. .datetimepicker({
  334. format: 'yyyy-mm-dd',
  335. startView: 2,
  336. endDate: "2013-01-24 15:30",
  337. viewSelect: 2,
  338. zIndex: zIndex
  339. }),
  340. dp = input.data('datetimepicker'),
  341. picker = dp.picker;
  342. ok(parseInt(picker.css('z-index'), 10) == zIndex, 'has a value defined in the options');
  343. });