options.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. module('Options', {
  2. setup: function(){},
  3. teardown: function(){
  4. $('#qunit-fixture *').each(function(){
  5. var t = $(this);
  6. if ('datepicker' in t.data())
  7. t.datepicker('remove');
  8. });
  9. }
  10. });
  11. test('Autoclose', function(){
  12. var input = $('<input />')
  13. .appendTo('#qunit-fixture')
  14. .val('2012-03-05')
  15. .datepicker({
  16. format: 'yyyy-mm-dd',
  17. autoclose: true
  18. }),
  19. dp = input.data('datepicker'),
  20. picker = dp.picker,
  21. target;
  22. input.focus();
  23. ok(picker.is(':visible'), 'Picker is visible');
  24. target = picker.find('.datepicker-days tbody td:nth(7)');
  25. equal(target.text(), '4'); // Mar 4
  26. target.click();
  27. ok(picker.is(':not(:visible)'), 'Picker is hidden');
  28. datesEqual(dp.dates[0], UTCDate(2012, 2, 4));
  29. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  30. });
  31. test('Custom date formatter functions', function(){
  32. var input = $('<input />')
  33. .appendTo('#qunit-fixture')
  34. .val('2015-09-18T00:00:00.000Z')
  35. .datepicker({
  36. format: {
  37. /*
  38. Say our UI should display a week ahead,
  39. but textbox should store the actual date.
  40. This is useful if we need UI to select local dates,
  41. but store in UTC
  42. */
  43. toDisplay: function (date, format, language) {
  44. var d = new Date(date);
  45. d.setDate(d.getDate() - 7);
  46. return d.toISOString();
  47. },
  48. toValue: function (date, format, language) {
  49. var d = new Date(date);
  50. d.setDate(d.getDate() + 7);
  51. return new Date(d);
  52. }
  53. },
  54. autoclose: true
  55. }),
  56. dp = input.data('datepicker'),
  57. picker = dp.picker,
  58. target;
  59. //Value is ISO format and is 7 days older than UI
  60. equal(input.val(), '2015-09-18T00:00:00.000Z');
  61. datesEqual(dp.dates[0], UTCDate(2015, 8, 25));
  62. datesEqual(dp.viewDate, UTCDate(2015, 8, 25));
  63. input.focus();
  64. ok(picker.is(':visible'), 'Picker is visible');
  65. target = picker.find('.datepicker-days tbody td:nth(5)');
  66. equal(target.text(), '4'); // Sep 4
  67. target.click();
  68. ok(picker.is(':not(:visible)'), 'Picker is hidden');
  69. //Value is now 28th Aug 2015 in ISO format
  70. //and is 7 days older than UI
  71. equal(input.val(), '2015-08-28T00:00:00.000Z');
  72. datesEqual(dp.dates[0], UTCDate(2015, 8, 4));
  73. datesEqual(dp.viewDate, UTCDate(2015, 8, 4));
  74. });
  75. test('Startview: year view (integer)', function(){
  76. var input = $('<input />')
  77. .appendTo('#qunit-fixture')
  78. .val('2012-03-05')
  79. .datepicker({
  80. format: 'yyyy-mm-dd',
  81. startView: 1
  82. }),
  83. dp = input.data('datepicker'),
  84. picker = dp.picker,
  85. target;
  86. input.focus();
  87. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  88. ok(picker.find('.datepicker-months').is(':visible'), 'Months view visible');
  89. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  90. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  91. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  92. });
  93. test('Startview: year view (string)', function(){
  94. var input = $('<input />')
  95. .appendTo('#qunit-fixture')
  96. .val('2012-03-05')
  97. .datepicker({
  98. format: 'yyyy-mm-dd',
  99. startView: 'year'
  100. }),
  101. dp = input.data('datepicker'),
  102. picker = dp.picker,
  103. target;
  104. input.focus();
  105. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  106. ok(picker.find('.datepicker-months').is(':visible'), 'Months view visible');
  107. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  108. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  109. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  110. });
  111. test('Startview: decade view (integer)', function(){
  112. var input = $('<input />')
  113. .appendTo('#qunit-fixture')
  114. .val('2012-03-05')
  115. .datepicker({
  116. format: 'yyyy-mm-dd',
  117. startView: 2
  118. }),
  119. dp = input.data('datepicker'),
  120. picker = dp.picker,
  121. target;
  122. input.focus();
  123. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  124. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  125. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  126. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  127. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  128. });
  129. test('Startview: decade view (string)', function(){
  130. var input = $('<input />')
  131. .appendTo('#qunit-fixture')
  132. .val('2012-03-05')
  133. .datepicker({
  134. format: 'yyyy-mm-dd',
  135. startView: 'decade'
  136. }),
  137. dp = input.data('datepicker'),
  138. picker = dp.picker,
  139. target;
  140. input.focus();
  141. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  142. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  143. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  144. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  145. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  146. });
  147. test('Startview: century view (integer)', function(){
  148. var input = $('<input />')
  149. .appendTo('#qunit-fixture')
  150. .val('2012-03-05')
  151. .datepicker({
  152. format: 'yyyy-mm-dd',
  153. startView: 3
  154. }),
  155. dp = input.data('datepicker'),
  156. picker = dp.picker,
  157. target;
  158. input.focus();
  159. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  160. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  161. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  162. ok(picker.find('.datepicker-decades').is(':visible'), 'Decades view visible');
  163. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  164. });
  165. test('Startview: century view (string)', function(){
  166. var input = $('<input />')
  167. .appendTo('#qunit-fixture')
  168. .val('2012-03-05')
  169. .datepicker({
  170. format: 'yyyy-mm-dd',
  171. startView: 'century'
  172. }),
  173. dp = input.data('datepicker'),
  174. picker = dp.picker,
  175. target;
  176. input.focus();
  177. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  178. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  179. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  180. ok(picker.find('.datepicker-decades').is(':visible'), 'Decades view visible');
  181. ok(picker.find('.datepicker-centuries').is(':not(:visible)'), 'Centuries view hidden');
  182. });
  183. test('Startview: millennium view (integer)', function(){
  184. var input = $('<input />')
  185. .appendTo('#qunit-fixture')
  186. .val('2012-03-05')
  187. .datepicker({
  188. format: 'yyyy-mm-dd',
  189. startView: 4
  190. }),
  191. dp = input.data('datepicker'),
  192. picker = dp.picker,
  193. target;
  194. input.focus();
  195. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  196. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  197. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  198. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  199. ok(picker.find('.datepicker-centuries').is(':visible'), 'Centuries view visible');
  200. });
  201. test('Startview: millennium view (string)', function(){
  202. var input = $('<input />')
  203. .appendTo('#qunit-fixture')
  204. .val('2012-03-05')
  205. .datepicker({
  206. format: 'yyyy-mm-dd',
  207. startView: 'millennium'
  208. }),
  209. dp = input.data('datepicker'),
  210. picker = dp.picker,
  211. target;
  212. input.focus();
  213. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  214. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  215. ok(picker.find('.datepicker-years').is(':not(:visible)'), 'Years view hidden');
  216. ok(picker.find('.datepicker-decades').is(':not(:visible)'), 'Decades view hidden');
  217. ok(picker.find('.datepicker-centuries').is(':visible'), 'Centuries view visible');
  218. });
  219. test('Today Button: today button not default', function(){
  220. var input = $('<input />')
  221. .appendTo('#qunit-fixture')
  222. .val('2012-03-05')
  223. .datepicker({
  224. format: 'yyyy-mm-dd'
  225. }),
  226. dp = input.data('datepicker'),
  227. picker = dp.picker,
  228. target;
  229. input.focus();
  230. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  231. ok(picker.find('.datepicker-days tfoot .today').is(':not(:visible)'), 'Today button not visible');
  232. });
  233. test('Today Button: today visibility when enabled', function(){
  234. var input = $('<input />')
  235. .appendTo('#qunit-fixture')
  236. .val('2012-03-05')
  237. .datepicker({
  238. format: 'yyyy-mm-dd',
  239. todayBtn: true
  240. }),
  241. dp = input.data('datepicker'),
  242. picker = dp.picker,
  243. target;
  244. input.focus();
  245. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  246. ok(picker.find('.datepicker-days tfoot .today').is(':visible'), 'Today button visible');
  247. picker.find('.datepicker-days thead th.datepicker-switch').click();
  248. ok(picker.find('.datepicker-months').is(':visible'), 'Months view visible');
  249. ok(picker.find('.datepicker-months tfoot .today').is(':visible'), 'Today button visible');
  250. picker.find('.datepicker-months thead th.datepicker-switch').click();
  251. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  252. ok(picker.find('.datepicker-years tfoot .today').is(':visible'), 'Today button visible');
  253. });
  254. test('Today Button: data-api', function(){
  255. var input = $('<input data-date-today-btn="true" />')
  256. .appendTo('#qunit-fixture')
  257. .val('2012-03-05')
  258. .datepicker({
  259. format: 'yyyy-mm-dd'
  260. }),
  261. dp = input.data('datepicker'),
  262. picker = dp.picker,
  263. target;
  264. input.focus();
  265. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  266. ok(picker.find('.datepicker-days tfoot .today').is(':visible'), 'Today button visible');
  267. });
  268. test('Today Button: moves to today\'s date', function(){
  269. var input = $('<input />')
  270. .appendTo('#qunit-fixture')
  271. .val('2012-03-05')
  272. .datepicker({
  273. format: 'yyyy-mm-dd',
  274. todayBtn: true
  275. }),
  276. dp = input.data('datepicker'),
  277. picker = dp.picker,
  278. target;
  279. input.focus();
  280. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  281. ok(picker.find('.datepicker-days tfoot .today').is(':visible'), 'Today button visible');
  282. target = picker.find('.datepicker-days tfoot .today');
  283. target.click();
  284. var d = new Date(),
  285. today = UTCDate(d.getFullYear(), d.getMonth(), d.getDate());
  286. datesEqual(dp.viewDate, today);
  287. datesEqual(dp.dates[0], UTCDate(2012, 2, 5));
  288. });
  289. test('Today Button: moves to days view', function(){
  290. var viewModes = $.fn.datepicker.DPGlobal.viewModes;
  291. var input = $('<input />')
  292. .appendTo('#qunit-fixture')
  293. .val('2012-03-05')
  294. .datepicker({
  295. format: 'yyyy-mm-dd',
  296. startView: viewModes.length - 1,
  297. todayBtn: true
  298. }),
  299. dp = input.data('datepicker'),
  300. picker = dp.picker,
  301. target;
  302. input.focus();
  303. target = picker.find('tfoot .today').filter(':visible');
  304. target.click();
  305. ok(picker.find('.datepicker-days tfoot .today').is(':visible'), 'Today button visible');
  306. });
  307. test('Today Button: "linked" selects today\'s date', function(){
  308. var input = $('<input />')
  309. .appendTo('#qunit-fixture')
  310. .val('2012-03-05')
  311. .datepicker({
  312. format: 'yyyy-mm-dd',
  313. todayBtn: "linked"
  314. }),
  315. dp = input.data('datepicker'),
  316. picker = dp.picker,
  317. target;
  318. input.focus();
  319. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  320. ok(picker.find('.datepicker-days tfoot .today').is(':visible'), 'Today button visible');
  321. target = picker.find('.datepicker-days tfoot .today');
  322. target.click();
  323. var d = new Date(),
  324. today = UTCDate(d.getFullYear(), d.getMonth(), d.getDate());
  325. datesEqual(dp.viewDate, today);
  326. datesEqual(dp.dates[0], today);
  327. });
  328. test('Today Highlight: today\'s date is not highlighted by default', patch_date(function(Date){
  329. Date.now = UTCDate(2012, 2, 15);
  330. var input = $('<input />')
  331. .appendTo('#qunit-fixture')
  332. .val('2012-03-05')
  333. .datepicker({
  334. format: 'yyyy-mm-dd'
  335. }),
  336. dp = input.data('datepicker'),
  337. picker = dp.picker,
  338. target;
  339. input.focus();
  340. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  341. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'March 2012', 'Title is "March 2012"');
  342. target = picker.find('.datepicker-days tbody td:contains(15)');
  343. ok(!target.hasClass('today'), 'Today is not marked with "today" class');
  344. target = picker.find('.datepicker-days tbody td:contains(14)');
  345. ok(!target.hasClass('today'), 'Yesterday is not marked with "today" class');
  346. target = picker.find('.datepicker-days tbody td:contains(16)');
  347. ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
  348. }));
  349. test('Today Highlight: today\'s date is highlighted when not active', patch_date(function(Date){
  350. Date.now = new Date(2012, 2, 15);
  351. var input = $('<input />')
  352. .appendTo('#qunit-fixture')
  353. .val('2012-03-05')
  354. .datepicker({
  355. format: 'yyyy-mm-dd',
  356. todayHighlight: true
  357. }),
  358. dp = input.data('datepicker'),
  359. picker = dp.picker,
  360. target;
  361. input.focus();
  362. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  363. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'March 2012', 'Title is "March 2012"');
  364. target = picker.find('.datepicker-days tbody td:contains(15)');
  365. ok(target.hasClass('today'), 'Today is marked with "today" class');
  366. target = picker.find('.datepicker-days tbody td:contains(14)');
  367. ok(!target.hasClass('today'), 'Yesterday is not marked with "today" class');
  368. target = picker.find('.datepicker-days tbody td:contains(16)');
  369. ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
  370. }));
  371. test('Clear Button: clear visibility when enabled', function(){
  372. var input = $('<input />')
  373. .appendTo('#qunit-fixture')
  374. .val('2012-03-05')
  375. .datepicker({
  376. format: 'yyyy-mm-dd',
  377. clearBtn: true
  378. }),
  379. dp = input.data('datepicker'),
  380. picker = dp.picker,
  381. target;
  382. input.focus();
  383. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  384. ok(picker.find('.datepicker-days tfoot .clear').is(':visible'), 'Clear button visible');
  385. picker.find('.datepicker-days thead th.datepicker-switch').click();
  386. ok(picker.find('.datepicker-months').is(':visible'), 'Months view visible');
  387. ok(picker.find('.datepicker-months tfoot .clear').is(':visible'), 'Clear button visible');
  388. picker.find('.datepicker-months thead th.datepicker-switch').click();
  389. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  390. ok(picker.find('.datepicker-years tfoot .clear').is(':visible'), 'Clear button visible');
  391. });
  392. test('Clear Button: clears input value', function(){
  393. var input = $('<input />')
  394. .appendTo('#qunit-fixture')
  395. .val('2012-03-05')
  396. .datepicker({
  397. format: 'yyyy-mm-dd',
  398. clearBtn: true
  399. }),
  400. dp = input.data('datepicker'),
  401. picker = dp.picker,
  402. target;
  403. input.focus();
  404. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  405. ok(picker.find('.datepicker-days tfoot .clear').is(':visible'), 'Today button visible');
  406. target = picker.find('.datepicker-days tfoot .clear');
  407. target.click();
  408. equal(input.val(),'',"Input value has been cleared.");
  409. ok(picker.is(':visible'), 'Picker is visible');
  410. });
  411. test('Clear Button: hides datepicker if autoclose is on', function(){
  412. var input = $('<input />')
  413. .appendTo('#qunit-fixture')
  414. .val('2012-03-05')
  415. .datepicker({
  416. format: 'yyyy-mm-dd',
  417. clearBtn: true,
  418. autoclose: true
  419. }),
  420. dp = input.data('datepicker'),
  421. picker = dp.picker,
  422. target;
  423. input.focus();
  424. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  425. ok(picker.find('.datepicker-days tfoot .clear').is(':visible'), 'Today button visible');
  426. target = picker.find('.datepicker-days tfoot .clear');
  427. target.click();
  428. equal(input.val(),'',"Input value has been cleared.");
  429. ok(picker.is(':not(:visible)'), 'Picker is hidden');
  430. });
  431. test('Active Toggle Default: when active date is selected it is not unset', function(){
  432. var input = $('<input />')
  433. .appendTo('#qunit-fixture')
  434. .val('2012-03-05')
  435. .datepicker({
  436. format: 'yyyy-mm-dd'
  437. }),
  438. dp = input.data('datepicker'),
  439. picker = dp.picker,
  440. target;
  441. // open our datepicker
  442. input.focus();
  443. // Initial value is selected
  444. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 selected');
  445. // click on our active date
  446. target = picker.find('.datepicker-days .day.active');
  447. target.click();
  448. // make sure it's still set
  449. equal(input.val(), '2012-03-05', "Input value has not been cleared.");
  450. });
  451. test('Active Toggle Enabled (single date): when active date is selected it is unset', function(){
  452. var input = $('<input />')
  453. .appendTo('#qunit-fixture')
  454. .val('2012-03-05')
  455. .datepicker({
  456. format: 'yyyy-mm-dd',
  457. toggleActive: true
  458. }),
  459. dp = input.data('datepicker'),
  460. picker = dp.picker,
  461. target;
  462. // open our datepicker
  463. input.focus();
  464. // Initial value is selected
  465. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 selected');
  466. // click on our active date
  467. target = picker.find('.datepicker-days .day.active');
  468. target.click();
  469. // make sure it's no longer set
  470. equal(input.val(), '', "Input value has been cleared.");
  471. });
  472. test('Active Toggle Multidate Default: when one of the active dates is selected it is unset', function(){
  473. var input = $('<input />')
  474. .appendTo('#qunit-fixture')
  475. .val('2012-03-05')
  476. .datepicker({
  477. format: 'yyyy-mm-dd',
  478. multidate: true
  479. }),
  480. dp = input.data('datepicker'),
  481. picker = dp.picker,
  482. target;
  483. // open our datepicker
  484. input.focus();
  485. // Initial value is selected
  486. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 in dates');
  487. // Select additional date
  488. target = picker.find('.datepicker-days tbody td:nth(7)');
  489. target.click();
  490. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
  491. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  492. equal(input.val(), '2012-03-05,2012-03-04');
  493. // Unselect additional date
  494. target = picker.find('.datepicker-days tbody td:nth(7)');
  495. target.click();
  496. ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
  497. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  498. equal(input.val(), '2012-03-05');
  499. });
  500. test('Active Toggle Disabled: when active date is selected it remains', function(){
  501. var input = $('<input />')
  502. .appendTo('#qunit-fixture')
  503. .val('2012-03-05')
  504. .datepicker({
  505. format: 'yyyy-mm-dd',
  506. toggleActive: false
  507. }),
  508. dp = input.data('datepicker'),
  509. picker = dp.picker,
  510. target;
  511. // open our datepicker
  512. input.focus();
  513. // Initial value is selected
  514. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 selected');
  515. // click on our active date
  516. target = picker.find('.datepicker-days .day.active');
  517. target.click();
  518. // make sure it's still set
  519. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 still selected');
  520. datesEqual(dp.viewDate, UTCDate(2012, 2, 5));
  521. equal(input.val(), '2012-03-05');
  522. });
  523. test('Active Toggle Multidate Disabled: when activeToggle is set to false, but multidate is set, the option is ignored and selecting an active date it is unset', function(){
  524. var input = $('<input />')
  525. .appendTo('#qunit-fixture')
  526. .val('2012-03-05')
  527. .datepicker({
  528. format: 'yyyy-mm-dd',
  529. multidate: true,
  530. toggleActive: false
  531. }),
  532. dp = input.data('datepicker'),
  533. picker = dp.picker,
  534. target;
  535. // open our datepicker
  536. input.focus();
  537. // Initial value is selected
  538. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 in dates');
  539. // Select additional date
  540. target = picker.find('.datepicker-days tbody td:nth(7)');
  541. target.click();
  542. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
  543. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  544. equal(input.val(), '2012-03-05,2012-03-04');
  545. // Unselect additional date
  546. target = picker.find('.datepicker-days tbody td:nth(7)');
  547. target.click();
  548. ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
  549. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  550. equal(input.val(), '2012-03-05');
  551. });
  552. test('DaysOfWeekDisabled', function(){
  553. var input = $('<input />')
  554. .appendTo('#qunit-fixture')
  555. .val('2012-10-26')
  556. .datepicker({
  557. format: 'yyyy-mm-dd',
  558. daysOfWeekDisabled: '1,5'
  559. }),
  560. dp = input.data('datepicker'),
  561. picker = dp.picker,
  562. target;
  563. input.focus();
  564. target = picker.find('.datepicker-days tbody td:nth(22)');
  565. ok(target.hasClass('disabled'), 'Day of week is disabled');
  566. target = picker.find('.datepicker-days tbody td:nth(24)');
  567. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  568. target = picker.find('.datepicker-days tbody td:nth(26)');
  569. ok(target.hasClass('disabled'), 'Day of week is disabled');
  570. });
  571. test('DaysOfWeekHighlighted', function(){
  572. var input = $('<input />')
  573. .appendTo('#qunit-fixture')
  574. .val('2012-10-26')
  575. .datepicker({
  576. format: 'yyyy-mm-dd',
  577. startDate: '2012-10-02',
  578. daysOfWeekHighlighted: '1,5'
  579. }),
  580. dp = input.data('datepicker'),
  581. picker = dp.picker,
  582. target;
  583. input.focus();
  584. target = picker.find('.datepicker-days tbody td:nth(0)');
  585. ok(!target.hasClass('highlighted'), 'Day of week is not highlighted');
  586. target = picker.find('.datepicker-days tbody td:nth(22)');
  587. ok(target.hasClass('highlighted'), 'Day of week is highlighted');
  588. target = picker.find('.datepicker-days tbody td:nth(24)');
  589. ok(!target.hasClass('highlighted'), 'Day of week is not highlighted');
  590. target = picker.find('.datepicker-days tbody td:nth(26)');
  591. ok(target.hasClass('highlighted'), 'Day of week is highlighted');
  592. });
  593. test('DatesDisabled', function(){
  594. var input = $('<input />')
  595. .appendTo('#qunit-fixture')
  596. .val('2012-10-26')
  597. .datepicker({
  598. format: 'yyyy-mm-dd',
  599. datesDisabled: ['2012-10-1', '2012-10-10', '2012-10-20']
  600. }),
  601. dp = input.data('datepicker'),
  602. picker = dp.picker,
  603. target;
  604. input.focus();
  605. target = picker.find('.datepicker-days tbody td:nth(1)');
  606. ok(target.hasClass('disabled'), 'Day of week is disabled');
  607. ok(target.hasClass('disabled-date'), 'Date is disabled');
  608. target = picker.find('.datepicker-days tbody td:nth(2)');
  609. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  610. target = picker.find('.datepicker-days tbody td:nth(10)');
  611. ok(target.hasClass('disabled'), 'Day of week is disabled');
  612. ok(target.hasClass('disabled-date'), 'Date is disabled');
  613. target = picker.find('.datepicker-days tbody td:nth(11)');
  614. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  615. target = picker.find('.datepicker-days tbody td:nth(20)');
  616. ok(target.hasClass('disabled'), 'Day of week is disabled');
  617. ok(target.hasClass('disabled-date'), 'Date is disabled');
  618. target = picker.find('.datepicker-days tbody td:nth(21)');
  619. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  620. });
  621. test('DatesDisabled as attribute', function(){
  622. var input = $('<input data-date-dates-disabled="2012-10-1,2012-10-10,2012-10-20" />')
  623. .appendTo('#qunit-fixture')
  624. .val('2012-10-26')
  625. .datepicker({
  626. format: 'yyyy-mm-dd'
  627. }),
  628. dp = input.data('datepicker'),
  629. picker = dp.picker,
  630. target;
  631. input.focus();
  632. target = picker.find('.datepicker-days tbody td:nth(1)');
  633. ok(target.hasClass('disabled'), 'Day of week is disabled');
  634. ok(target.hasClass('disabled-date'), 'Date is disabled');
  635. target = picker.find('.datepicker-days tbody td:nth(2)');
  636. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  637. target = picker.find('.datepicker-days tbody td:nth(10)');
  638. ok(target.hasClass('disabled'), 'Day of week is disabled');
  639. ok(target.hasClass('disabled-date'), 'Date is disabled');
  640. target = picker.find('.datepicker-days tbody td:nth(11)');
  641. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  642. target = picker.find('.datepicker-days tbody td:nth(20)');
  643. ok(target.hasClass('disabled'), 'Day of week is disabled');
  644. ok(target.hasClass('disabled-date'), 'Date is disabled');
  645. target = picker.find('.datepicker-days tbody td:nth(21)');
  646. ok(!target.hasClass('disabled'), 'Day of week is enabled');
  647. });
  648. test('BeforeShowDay', function(){
  649. var beforeShowDay = function(date) {
  650. switch (date.getDate()){
  651. case 25:
  652. return {
  653. tooltip: 'Example tooltip',
  654. classes: 'active'
  655. };
  656. case 26:
  657. return "test26";
  658. case 27:
  659. return {enabled: false, classes: 'test27'};
  660. case 28:
  661. return false;
  662. case 30:
  663. return { content: "foo" + date.getDate() }
  664. }
  665. };
  666. var input = $('<input />')
  667. .appendTo('#qunit-fixture')
  668. .val('2012-10-26')
  669. .datepicker({
  670. format: 'yyyy-mm-dd',
  671. beforeShowDay: beforeShowDay
  672. }),
  673. dp = input.data('datepicker'),
  674. picker = dp.picker,
  675. target;
  676. input.focus();
  677. target = picker.find('.datepicker-days tbody td:nth(25)');
  678. equal(target.attr('title'), 'Example tooltip', '25th has tooltip');
  679. ok(!target.hasClass('disabled'), '25th is enabled');
  680. target = picker.find('.datepicker-days tbody td:nth(26)');
  681. ok(target.hasClass('test26'), '26th has test26 class');
  682. ok(!target.hasClass('disabled'), '26th is enabled');
  683. target = picker.find('.datepicker-days tbody td:nth(27)');
  684. ok(target.hasClass('test27'), '27th has test27 class');
  685. ok(target.hasClass('disabled'), '27th is disabled');
  686. target = picker.find('.datepicker-days tbody td:nth(28)');
  687. ok(target.hasClass('disabled'), '28th is disabled');
  688. target = picker.find('.datepicker-days tbody td:nth(29)');
  689. ok(!target.hasClass('disabled'), '29th is enabled');
  690. target = picker.find('.datepicker-days tbody td:nth(30)');
  691. ok(target.text() == "foo30", '30th has custom content');
  692. });
  693. test('BeforeShowMonth regress .day content', function() {
  694. var input = $('<input />')
  695. .appendTo('#qunit-fixture')
  696. .val('2012-10-26')
  697. .datepicker({
  698. format: 'yyyy-mm-dd',
  699. beforeShowDay: function(date) {
  700. return {
  701. content: '<strong>foo123</strong>'
  702. };
  703. }
  704. }),
  705. dp = input.data('datepicker'),
  706. picker = dp.picker,
  707. target;
  708. input.focus();
  709. target = picker.find('.datepicker-days tbody td:nth(30)');
  710. target.trigger('click');
  711. datesEqual(dp.viewDate, UTCDate(2012, 9, 30));
  712. });
  713. test('BeforeShowMonth', function () {
  714. var beforeShowMonth = function (date) {
  715. switch (date.getMonth()) {
  716. case 0:
  717. return {
  718. tooltip: 'Example tooltip',
  719. classes: 'active'
  720. };
  721. case 2:
  722. return "testMarch";
  723. case 4:
  724. return {enabled: false, classes: 'testMay'};
  725. case 5:
  726. return false;
  727. }
  728. };
  729. var input = $('<input />')
  730. .appendTo('#qunit-fixture')
  731. .val('2012-10-26')
  732. .datepicker({
  733. format: 'yyyy-mm-dd',
  734. beforeShowMonth: beforeShowMonth
  735. }),
  736. dp = input.data('datepicker'),
  737. picker = dp.picker,
  738. target;
  739. input.focus();
  740. target = picker.find('.datepicker-months tbody span:nth(0)');
  741. equal(target.attr('title'), 'Example tooltip', '1st has tooltip');
  742. ok(!target.hasClass('disabled'), 'January is enabled');
  743. target = picker.find('.datepicker-months tbody span:nth(2)');
  744. ok(target.hasClass('testMarch'), 'March has testMarch class');
  745. ok(!target.hasClass('disabled'), 'March enabled');
  746. target = picker.find('.datepicker-months tbody span:nth(4)');
  747. ok(target.hasClass('testMay'), 'May has testMay class');
  748. ok(target.hasClass('disabled'), 'May is disabled');
  749. target = picker.find('.datepicker-months tbody span:nth(5)');
  750. ok(target.hasClass('disabled'), 'June is disabled');
  751. target = picker.find('.datepicker-months tbody span:nth(6)');
  752. ok(!target.hasClass('disabled'), 'July is enabled');
  753. });
  754. test('BeforeShowYear', function () {
  755. var beforeShowYear = function (date) {
  756. switch (date.getFullYear()) {
  757. case 2013:
  758. return {
  759. tooltip: 'Example tooltip',
  760. classes: 'active'
  761. };
  762. case 2014:
  763. return "test2014";
  764. case 2015:
  765. return {enabled: false, classes: 'test2015'};
  766. case 2016:
  767. return false;
  768. }
  769. };
  770. var input = $('<input />')
  771. .appendTo('#qunit-fixture')
  772. .val('2012-10-26')
  773. .datepicker({
  774. format: 'yyyy-mm-dd',
  775. beforeShowYear: beforeShowYear
  776. }),
  777. dp = input.data('datepicker'),
  778. picker = dp.picker,
  779. target;
  780. input.focus();
  781. target = picker.find('.datepicker-years tbody span:nth(4)');
  782. equal(target.attr('title'), 'Example tooltip', '5th has tooltip');
  783. ok(!target.hasClass('disabled'), '2013, 5th is enabled');
  784. target = picker.find('.datepicker-years tbody span:nth(5)');
  785. ok(target.hasClass('test2014'), '6th has test2014 class');
  786. ok(!target.hasClass('disabled'), '2014, 6th is enabled');
  787. target = picker.find('.datepicker-years tbody span:nth(6)');
  788. ok(target.hasClass('test2015'), '2015, 7th has test2015 class');
  789. ok(target.hasClass('disabled'), '2015, 7th is disabled');
  790. target = picker.find('.datepicker-years tbody span:nth(7)');
  791. ok(target.hasClass('disabled'), '2016, 8th is disabled');
  792. target = picker.find('.datepicker-years tbody span:nth(8)');
  793. ok(!target.hasClass('disabled'), '2017, 9th is enabled');
  794. });
  795. test('beforeShowDecade', function () {
  796. var beforeShowDecade = function (date) {
  797. switch (date.getFullYear()) {
  798. case 2030:
  799. return {
  800. tooltip: 'Example tooltip',
  801. classes: 'active'
  802. };
  803. case 2040:
  804. return "test2040";
  805. case 2050:
  806. return {enabled: false, classes: 'test2050'};
  807. case 2060:
  808. return false;
  809. }
  810. };
  811. var input = $('<input />')
  812. .appendTo('#qunit-fixture')
  813. .val('03/05/2012')
  814. .datepicker({ beforeShowDecade: beforeShowDecade }),
  815. dp = input.data('datepicker'),
  816. picker = dp.picker,
  817. target;
  818. input.focus();
  819. target = picker.find('.datepicker-decades tbody span:nth(4)');
  820. equal(target.attr('title'), 'Example tooltip', '5th has tooltip');
  821. ok(!target.hasClass('disabled'), '2030, 5th is enabled');
  822. target = picker.find('.datepicker-decades tbody span:nth(5)');
  823. ok(target.hasClass('test2040'), '6th has test2040 class');
  824. ok(!target.hasClass('disabled'), '2040, 6th is enabled');
  825. target = picker.find('.datepicker-decades tbody span:nth(6)');
  826. ok(target.hasClass('test2050'), '2050, 7th has test2050 class');
  827. ok(target.hasClass('disabled'), '2050, 7th is disabled');
  828. target = picker.find('.datepicker-decades tbody span:nth(7)');
  829. ok(target.hasClass('disabled'), '2060, 8th is disabled');
  830. target = picker.find('.datepicker-decades tbody span:nth(8)');
  831. ok(!target.hasClass('disabled'), '2070, 9th is enabled');
  832. });
  833. test('beforeShowCentury', function () {
  834. var beforeShowCentury = function (date) {
  835. switch (date.getFullYear()) {
  836. case 2300:
  837. return {
  838. tooltip: 'Example tooltip',
  839. classes: 'active'
  840. };
  841. case 2400:
  842. return "test2400";
  843. case 2500:
  844. return {enabled: false, classes: 'test2500'};
  845. case 2600:
  846. return false;
  847. }
  848. };
  849. var input = $('<input />')
  850. .appendTo('#qunit-fixture')
  851. .val('03/05/2012')
  852. .datepicker({ beforeShowCentury: beforeShowCentury }),
  853. dp = input.data('datepicker'),
  854. picker = dp.picker,
  855. target;
  856. input.focus();
  857. target = picker.find('.datepicker-centuries tbody span:nth(4)');
  858. equal(target.attr('title'), 'Example tooltip', '5th has tooltip');
  859. ok(!target.hasClass('disabled'), '2300, 5th is enabled');
  860. target = picker.find('.datepicker-centuries tbody span:nth(5)');
  861. ok(target.hasClass('test2400'), '6th has test2400 class');
  862. ok(!target.hasClass('disabled'), '2400, 6th is enabled');
  863. target = picker.find('.datepicker-centuries tbody span:nth(6)');
  864. ok(target.hasClass('test2500'), '2500, 7th has test2500 class');
  865. ok(target.hasClass('disabled'), '2500, 7th is disabled');
  866. target = picker.find('.datepicker-centuries tbody span:nth(7)');
  867. ok(target.hasClass('disabled'), '2600, 8th is disabled');
  868. target = picker.find('.datepicker-centuries tbody span:nth(8)');
  869. ok(!target.hasClass('disabled'), '2700, 9th is enabled');
  870. });
  871. test('Orientation: values are parsed correctly', function(){
  872. var input = $('<input />')
  873. .appendTo('#qunit-fixture')
  874. .val('2012-10-26')
  875. .datepicker({
  876. format: 'yyyy-mm-dd'
  877. }),
  878. dp = input.data('datepicker');
  879. equal(dp.o.orientation.x, 'auto');
  880. equal(dp.o.orientation.y, 'auto');
  881. dp._process_options({orientation: ''});
  882. equal(dp.o.orientation.x, 'auto', 'Empty value');
  883. equal(dp.o.orientation.y, 'auto', 'Empty value');
  884. dp._process_options({orientation: 'left'});
  885. equal(dp.o.orientation.x, 'left', '"left"');
  886. equal(dp.o.orientation.y, 'auto', '"left"');
  887. dp._process_options({orientation: 'right'});
  888. equal(dp.o.orientation.x, 'right', '"right"');
  889. equal(dp.o.orientation.y, 'auto', '"right"');
  890. dp._process_options({orientation: 'top'});
  891. equal(dp.o.orientation.x, 'auto', '"top"');
  892. equal(dp.o.orientation.y, 'top', '"top"');
  893. dp._process_options({orientation: 'bottom'});
  894. equal(dp.o.orientation.x, 'auto', '"bottom"');
  895. equal(dp.o.orientation.y, 'bottom', '"bottom"');
  896. dp._process_options({orientation: 'left top'});
  897. equal(dp.o.orientation.x, 'left', '"left top"');
  898. equal(dp.o.orientation.y, 'top', '"left top"');
  899. dp._process_options({orientation: 'left bottom'});
  900. equal(dp.o.orientation.x, 'left', '"left bottom"');
  901. equal(dp.o.orientation.y, 'bottom', '"left bottom"');
  902. dp._process_options({orientation: 'right top'});
  903. equal(dp.o.orientation.x, 'right', '"right top"');
  904. equal(dp.o.orientation.y, 'top', '"right top"');
  905. dp._process_options({orientation: 'right bottom'});
  906. equal(dp.o.orientation.x, 'right', '"right bottom"');
  907. equal(dp.o.orientation.y, 'bottom', '"right bottom"');
  908. dp._process_options({orientation: 'left right'});
  909. equal(dp.o.orientation.x, 'left', '"left right"');
  910. equal(dp.o.orientation.y, 'auto', '"left right"');
  911. dp._process_options({orientation: 'right left'});
  912. equal(dp.o.orientation.x, 'right', '"right left"');
  913. equal(dp.o.orientation.y, 'auto', '"right left"');
  914. dp._process_options({orientation: 'top bottom'});
  915. equal(dp.o.orientation.x, 'auto', '"top bottom"');
  916. equal(dp.o.orientation.y, 'top', '"top bottom"');
  917. dp._process_options({orientation: 'bottom top'});
  918. equal(dp.o.orientation.x, 'auto', '"bottom top"');
  919. equal(dp.o.orientation.y, 'bottom', '"bottom top"');
  920. dp._process_options({orientation: 'foo bar'});
  921. equal(dp.o.orientation.x, 'auto', '"foo bar"');
  922. equal(dp.o.orientation.y, 'auto', '"foo bar"');
  923. dp._process_options({orientation: 'foo left'});
  924. equal(dp.o.orientation.x, 'left', '"foo left"');
  925. equal(dp.o.orientation.y, 'auto', '"foo left"');
  926. dp._process_options({orientation: 'top bar'});
  927. equal(dp.o.orientation.x, 'auto', '"top bar"');
  928. equal(dp.o.orientation.y, 'top', '"top bar"');
  929. });
  930. test('startDate', function(){
  931. var input = $('<input />')
  932. .appendTo('#qunit-fixture')
  933. .val('2012-10-26')
  934. .datepicker({
  935. format: 'yyyy-mm-dd',
  936. startDate: new Date(2012, 9, 26)
  937. }),
  938. dp = input.data('datepicker'),
  939. picker = dp.picker,
  940. target;
  941. input.focus();
  942. target = picker.find('.datepicker-days tbody td:nth(25)');
  943. ok(target.hasClass('disabled'), 'Previous day is disabled');
  944. target = picker.find('.datepicker-days tbody td:nth(26)');
  945. ok(!target.hasClass('disabled'), 'Specified date is enabled');
  946. target = picker.find('.datepicker-days tbody td:nth(27)');
  947. ok(!target.hasClass('disabled'), 'Next day is enabled');
  948. });
  949. test('endDate', function(){
  950. var input = $('<input />')
  951. .appendTo('#qunit-fixture')
  952. .val('2012-10-26')
  953. .datepicker({
  954. format: 'yyyy-mm-dd',
  955. endDate: new Date(2012, 9, 26)
  956. }),
  957. dp = input.data('datepicker'),
  958. picker = dp.picker,
  959. target;
  960. input.focus();
  961. target = picker.find('.datepicker-days tbody td:nth(25)');
  962. ok(!target.hasClass('disabled'), 'Previous day is enabled');
  963. target = picker.find('.datepicker-days tbody td:nth(26)');
  964. ok(!target.hasClass('disabled'), 'Specified date is enabled');
  965. target = picker.find('.datepicker-days tbody td:nth(27)');
  966. ok(target.hasClass('disabled'), 'Next day is disabled');
  967. });
  968. test('Multidate', function(){
  969. var input = $('<input />')
  970. .appendTo('#qunit-fixture')
  971. .val('2012-03-05')
  972. .datepicker({
  973. format: 'yyyy-mm-dd',
  974. multidate: true
  975. }),
  976. dp = input.data('datepicker'),
  977. picker = dp.picker,
  978. target;
  979. input.focus();
  980. // Initial value is selected
  981. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 (initial date) in dates');
  982. // Select first
  983. target = picker.find('.datepicker-days tbody td:nth(7)');
  984. equal(target.text(), '4'); // Mar 4
  985. target.click();
  986. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
  987. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  988. equal(input.val(), '2012-03-05,2012-03-04');
  989. // Select second
  990. target = picker.find('.datepicker-days tbody td:nth(15)');
  991. equal(target.text(), '12'); // Mar 12
  992. target.click();
  993. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 12), '2012-03-12 in dates');
  994. datesEqual(dp.viewDate, UTCDate(2012, 2, 12));
  995. equal(input.val(), '2012-03-05,2012-03-04,2012-03-12');
  996. // Deselect first
  997. target = picker.find('.datepicker-days tbody td:nth(7)');
  998. equal(target.text(), '4'); // Mar 4
  999. target.click();
  1000. ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
  1001. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  1002. equal(input.val(), '2012-03-05,2012-03-12');
  1003. });
  1004. test('Multidate with limit', function(){
  1005. var input = $('<input />')
  1006. .appendTo('#qunit-fixture')
  1007. .val('2012-03-05')
  1008. .datepicker({
  1009. format: 'yyyy-mm-dd',
  1010. multidate: 2
  1011. }),
  1012. dp = input.data('datepicker'),
  1013. picker = dp.picker,
  1014. target;
  1015. input.focus();
  1016. // Initial value is selected
  1017. ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 (initial date) in dates');
  1018. // Select first
  1019. target = picker.find('.datepicker-days tbody td:nth(7)');
  1020. equal(target.text(), '4'); // Mar 4
  1021. target.click();
  1022. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
  1023. datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
  1024. equal(input.val(), '2012-03-05,2012-03-04');
  1025. // Select second
  1026. target = picker.find('.datepicker-days tbody td:nth(15)');
  1027. equal(target.text(), '12'); // Mar 12
  1028. target.click();
  1029. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 12), '2012-03-12 in dates');
  1030. datesEqual(dp.viewDate, UTCDate(2012, 2, 12));
  1031. equal(input.val(), '2012-03-04,2012-03-12');
  1032. // Select third
  1033. target = picker.find('.datepicker-days tbody td:nth(20)');
  1034. equal(target.text(), '17'); // Mar 17
  1035. target.click();
  1036. datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 17), '2012-03-17 in dates');
  1037. ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
  1038. datesEqual(dp.viewDate, UTCDate(2012, 2, 17));
  1039. equal(input.val(), '2012-03-12,2012-03-17');
  1040. });
  1041. test('Multidate Separator', function(){
  1042. var input = $('<input />')
  1043. .appendTo('#qunit-fixture')
  1044. .val('2012-03-05')
  1045. .datepicker({
  1046. format: 'yyyy-mm-dd',
  1047. multidate: true,
  1048. multidateSeparator: ' '
  1049. }),
  1050. dp = input.data('datepicker'),
  1051. picker = dp.picker,
  1052. target;
  1053. input.focus();
  1054. // Select first
  1055. target = picker.find('.datepicker-days tbody td:nth(7)');
  1056. equal(target.text(), '4'); // Mar 4
  1057. target.click();
  1058. equal(input.val(), '2012-03-05 2012-03-04');
  1059. // Select second
  1060. target = picker.find('.datepicker-days tbody td:nth(15)');
  1061. equal(target.text(), '12'); // Mar 12
  1062. target.click();
  1063. equal(input.val(), '2012-03-05 2012-03-04 2012-03-12');
  1064. });
  1065. test("Picker is shown on input focus when showOnFocus is not defined", function () {
  1066. var input = $('<input />')
  1067. .appendTo('#qunit-fixture')
  1068. .val('2014-01-01')
  1069. .datepicker({
  1070. }),
  1071. dp = input.data('datepicker'),
  1072. picker = dp.picker;
  1073. input.focus();
  1074. ok(picker.is(":visible"), "Datepicker is visible");
  1075. });
  1076. test("Picker is shown on input focus when showOnFocus is true", function () {
  1077. var input = $('<input />')
  1078. .appendTo('#qunit-fixture')
  1079. .val('2014-01-01')
  1080. .datepicker({
  1081. showOnFocus: true
  1082. }),
  1083. dp = input.data('datepicker'),
  1084. picker = dp.picker;
  1085. input.focus();
  1086. ok(picker.is(":visible"), "Datepicker is visible");
  1087. });
  1088. test("Picker is hidden on input focus when showOnFocus is false", function () {
  1089. var input = $('<input />')
  1090. .appendTo('#qunit-fixture')
  1091. .val('2014-01-01')
  1092. .datepicker({
  1093. showOnFocus: false
  1094. }),
  1095. dp = input.data('datepicker'),
  1096. picker = dp.picker;
  1097. input.focus();
  1098. ok(picker.is(":hidden"), "Datepicker is hidden");
  1099. });
  1100. test('Container', function(){
  1101. var testContainer = $('<div class="date-picker-container"/>')
  1102. .appendTo('#qunit-fixture'),
  1103. input = $('<input />')
  1104. .appendTo('#qunit-fixture')
  1105. .val('2012-10-26')
  1106. .datepicker({
  1107. format: 'yyyy-mm-dd',
  1108. container: '.date-picker-container',
  1109. startDate: new Date(2012, 9, 26)
  1110. }),
  1111. dp = input.data('datepicker'),
  1112. target = dp.picker;
  1113. input.focus();
  1114. equal(target.parent()[0], testContainer[0], 'Container is not the testContainer that was specificed');
  1115. });
  1116. test('Default View Date (Object)', function(){
  1117. var input = $('<input />')
  1118. .appendTo('#qunit-fixture')
  1119. .datepicker({
  1120. format: 'yyyy-mm-dd',
  1121. defaultViewDate: { year: 1977, month: 04, day: 25 }
  1122. }),
  1123. dp = input.data('datepicker'),
  1124. picker = dp.picker,
  1125. target;
  1126. input.focus();
  1127. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'May 1977');
  1128. });
  1129. test('Default View Date (Date)', function(){
  1130. var input = $('<input />')
  1131. .appendTo('#qunit-fixture')
  1132. .datepicker({
  1133. format: 'yyyy-mm-dd',
  1134. defaultViewDate: new Date(1977, 4, 25)
  1135. }),
  1136. dp = input.data('datepicker'),
  1137. picker = dp.picker,
  1138. target;
  1139. input.focus();
  1140. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'May 1977');
  1141. });
  1142. test('Default View Date (String)', function(){
  1143. var input = $('<input />')
  1144. .appendTo('#qunit-fixture')
  1145. .datepicker({
  1146. format: 'yyyy-mm-dd',
  1147. defaultViewDate: "1977-05-24"
  1148. }),
  1149. dp = input.data('datepicker'),
  1150. picker = dp.picker,
  1151. target;
  1152. input.focus();
  1153. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'May 1977');
  1154. });
  1155. test('Immediate Updates', function(){
  1156. var input = $('<input />')
  1157. .appendTo('#qunit-fixture')
  1158. .val('2014-01-01')
  1159. .datepicker({
  1160. format: 'yyyy-mm-dd',
  1161. immediateUpdates: true
  1162. }),
  1163. dp = input.data('datepicker'),
  1164. picker = dp.picker;
  1165. // Change month
  1166. input.focus();
  1167. picker.find('.datepicker-days .next').click();
  1168. equal(input.val(), '2014-02-01');
  1169. // Change year
  1170. picker.find('.datepicker-days .datepicker-switch').click();
  1171. picker.find('.datepicker-months .next').click();
  1172. equal(input.val(), '2015-02-01');
  1173. // Change decade set (doesn't update input)
  1174. picker.find('.datepicker-months .datepicker-switch').click();
  1175. picker.find('.datepicker-years .next').click();
  1176. equal(input.val(), '2015-02-01');
  1177. // Change century set (doesn't update input)
  1178. picker.find('.datepicker-years .datepicker-switch').click();
  1179. picker.find('.datepicker-decades .next').click();
  1180. equal(input.val(), '2015-02-01');
  1181. // Change millennium set (doesn't update input)
  1182. picker.find('.datepicker-decades .datepicker-switch').click();
  1183. picker.find('.datepicker-centuries .next').click();
  1184. equal(input.val(), '2015-02-01');
  1185. });
  1186. test('forceParse: false on enter on invalid date', function () {
  1187. var input = $('<input />')
  1188. .appendTo('#qunit-fixture')
  1189. .val('123456789')
  1190. .datepicker({forceParse: false})
  1191. .focus();
  1192. input.trigger({
  1193. type: 'keydown',
  1194. keyCode: 13,
  1195. shiftKey: false
  1196. });
  1197. equal(input.val(), '123456789', 'date not parsed');
  1198. });
  1199. test('forceParse: false on mousedown on invalid date', function () {
  1200. var input = $('<input />')
  1201. .appendTo('#qunit-fixture')
  1202. .val('123456789')
  1203. .datepicker({forceParse: false})
  1204. .focus();
  1205. $(document).trigger({
  1206. type: 'mousedown'
  1207. });
  1208. equal(input.val(), '123456789', 'date not parsed');
  1209. });
  1210. //datepicker-dropdown
  1211. test('Enable on readonly options (default)', function(){
  1212. var input = $('<input readonly="readonly" />')
  1213. .appendTo('#qunit-fixture')
  1214. .datepicker({format: "dd-mm-yyyy"}),
  1215. dp = input.data('datepicker'),
  1216. picker = dp.picker;
  1217. ok(!picker.is(':visible'));
  1218. input.focus();
  1219. ok(picker.is(':visible'));
  1220. });
  1221. test('Enable on readonly options (false)', function(){
  1222. var input = $('<input readonly="readonly" />')
  1223. .appendTo('#qunit-fixture')
  1224. .datepicker({
  1225. format: "dd-mm-yyyy",
  1226. enableOnReadonly: false
  1227. }),
  1228. dp = input.data('datepicker'),
  1229. picker = dp.picker;
  1230. ok(!picker.is(':visible'));
  1231. input.focus();
  1232. ok(!picker.is(':visible'));
  1233. });
  1234. test('Startview: year view visible after date pick', function(){
  1235. var input = $('<input />')
  1236. .appendTo('#qunit-fixture')
  1237. .datepicker({
  1238. startView: 2,
  1239. minViewMode: 1,
  1240. autoclose: true
  1241. }),
  1242. dp = input.data('datepicker'),
  1243. picker = dp.picker,
  1244. target;
  1245. input.focus();
  1246. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  1247. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  1248. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  1249. target = picker.find('.datepicker-years tbody td:nth(7)');
  1250. target.click();
  1251. target = picker.find('.datepicker-years tbody td:nth(4)');
  1252. target.click();
  1253. target = picker.find('.datepicker-years tbody td:nth(20)');
  1254. target.click();
  1255. input.focus();
  1256. ok(picker.find('.datepicker-days').is(':not(:visible)'), 'Days view hidden');
  1257. ok(picker.find('.datepicker-months').is(':not(:visible)'), 'Months view hidden');
  1258. ok(picker.find('.datepicker-years').is(':visible'), 'Years view visible');
  1259. });
  1260. test('Title: none', function(){
  1261. var input = $('<input />')
  1262. .appendTo('#qunit-fixture')
  1263. .datepicker({
  1264. format: 'yyyy-mm-dd'
  1265. }),
  1266. dp = input.data('datepicker'),
  1267. picker = dp.picker,
  1268. target;
  1269. input.focus();
  1270. ok(picker.is(':visible'), 'Picker is visible');
  1271. target = picker.find('.datepicker-days thead .datepicker-title');
  1272. ok(target.is(':not(:visible)'), 'Title is hidden');
  1273. });
  1274. test('Title: with value', function(){
  1275. var input = $('<input />')
  1276. .appendTo('#qunit-fixture')
  1277. .datepicker({
  1278. format: 'yyyy-mm-dd',
  1279. title: 'Some Title'
  1280. }),
  1281. dp = input.data('datepicker'),
  1282. picker = dp.picker,
  1283. target;
  1284. input.focus();
  1285. ok(picker.is(':visible'), 'Picker is visible');
  1286. target = picker.find('.datepicker-days thead .datepicker-title');
  1287. ok(target.is(':visible'), 'Title is visible');
  1288. equal(target.text(), 'Some Title');
  1289. });
  1290. test('i18n: Leverage i18n titleFormat when available.', patch_date(function(Date){
  1291. var input = $('<input />')
  1292. .appendTo('#qunit-fixture')
  1293. .val('2015年04月21日')
  1294. .datepicker({
  1295. language: 'zh-CN'
  1296. }),
  1297. dp = input.data('datepicker'),
  1298. picker = dp.picker;
  1299. input.focus();
  1300. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), '2015年04月', 'Title is in Chinese: 2015年04月');
  1301. }));
  1302. test('i18n: Leverage English (default) i18n titleFormat when translation key for specified language is not available.', patch_date(function(Date){
  1303. var input = $('<input />')
  1304. .appendTo('#qunit-fixture')
  1305. .val('04/21/2015')
  1306. .datepicker({
  1307. language: 'aa-BB'
  1308. }),
  1309. dp = input.data('datepicker'),
  1310. picker = dp.picker;
  1311. input.focus();
  1312. equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'April 2015', 'Title is in default format: April 2015');
  1313. }));
  1314. test('Z-index Offset: none', function(){
  1315. var input = $('<input />')
  1316. .appendTo('#qunit-fixture')
  1317. .datepicker(),
  1318. dp = input.data('datepicker'),
  1319. picker = dp.picker;
  1320. input.parent().css('z-index', 234);
  1321. input.focus();
  1322. equal(dp.o.zIndexOffset, 10, 'Z-index offset option defaults to 10.');
  1323. equal(picker.css('z-index'), 244, 'Picker Z-index offset is respected.');
  1324. });
  1325. test('Z-index Offset: with value', function(){
  1326. var input = $('<input />')
  1327. .appendTo('#qunit-fixture')
  1328. .datepicker({
  1329. zIndexOffset: 1000
  1330. }),
  1331. dp = input.data('datepicker'),
  1332. picker = dp.picker;
  1333. input.parent().css('z-index', 234);
  1334. input.focus();
  1335. equal(dp.o.zIndexOffset, 1000, 'Z-index offset option is accepted.');
  1336. equal(picker.css('z-index'), 1234, 'Picker Z-index offset is respected.');
  1337. });
  1338. test('templates', function(){
  1339. var input = $('<input />')
  1340. .appendTo('#qunit-fixture')
  1341. .datepicker({
  1342. templates: {
  1343. leftArrow: '<span class="glyphicon glyphicon-arrow-left"></span>',
  1344. rightArrow: '</table>'
  1345. }
  1346. }),
  1347. dp = input.data('datepicker'),
  1348. picker = dp.picker;
  1349. input.focus();
  1350. equal(picker.find('.datepicker-days .prev').prop('innerHTML'), '<span class="glyphicon glyphicon-arrow-left"></span>');
  1351. equal(picker.find('.datepicker-days .next').prop('innerHTML'), $('<div>').html('&raquo;').text());
  1352. });
  1353. test('Nav arrow html templates with span tag', function () {
  1354. var input = $('<input />')
  1355. .appendTo('#qunit-fixture')
  1356. .val('2012-10-26')
  1357. .datepicker({
  1358. format: 'yyyy-mm-dd',
  1359. templates: {
  1360. leftArrow: '<span></span>',
  1361. rightArrow: '<span></span>'
  1362. }
  1363. }),
  1364. dp = input.data('datepicker'),
  1365. picker = dp.picker,
  1366. target;
  1367. input.focus();
  1368. target = picker.find('.datepicker-months tbody span:nth(9)');
  1369. ok(target.hasClass('active'), 'Month is selected');
  1370. });
  1371. test('Nav arrow html templates .prev click', function () {
  1372. var input = $('<input />')
  1373. .appendTo('#qunit-fixture')
  1374. .val('2012-10-26')
  1375. .datepicker({
  1376. format: 'yyyy-mm-dd',
  1377. startView: 1,
  1378. templates: {
  1379. leftArrow: '<i></i>'
  1380. }
  1381. }),
  1382. dp = input.data('datepicker'),
  1383. picker = dp.picker,
  1384. target;
  1385. input.focus();
  1386. picker.find('.datepicker-months thead .prev i').trigger('click');
  1387. target = picker.find('.datepicker-months thead .datepicker-switch');
  1388. equal(target.text(), '2011');
  1389. });
  1390. test('Visibility of the prev and next arrows for year/decade/century/millenium views with startDate and endDate', function(){
  1391. var input = $('<input />')
  1392. .appendTo('#qunit-fixture')
  1393. .val('01/01/2015')
  1394. .datepicker({
  1395. format: 'dd/mm/yyyy',
  1396. startView: 1,
  1397. startDate: '01/12/2014',
  1398. endDate: '01/12/2016'
  1399. }),
  1400. dp = input.data('datepicker'),
  1401. picker = dp.picker,
  1402. target;
  1403. input.focus();
  1404. target = picker.find('.datepicker-months thead th.prev');
  1405. ok(!target.hasClass('disabled'), 'Prev switcher is not hidden');
  1406. target = picker.find('.datepicker-months thead th.next');
  1407. ok(!target.hasClass('disabled'), 'Next switcher is not hidden');
  1408. picker.find('.datepicker-months thead th.datepicker-switch').click();
  1409. target = picker.find('.datepicker-years thead th.prev');
  1410. ok(target.hasClass('disabled'), 'Prev switcher is hidden');
  1411. target = picker.find('.datepicker-years thead th.next');
  1412. ok(target.hasClass('disabled'), 'Next switcher is hidden');
  1413. picker.find('.datepicker-years thead th.datepicker-switch').click();
  1414. target = picker.find('.datepicker-decades thead th.prev');
  1415. ok(target.hasClass('disabled'), 'Prev switcher is hidden');
  1416. target = picker.find('.datepicker-decades thead th.next');
  1417. ok(target.hasClass('disabled'), 'Next switcher is hidden');
  1418. picker.find('.datepicker-decades thead th.datepicker-switch').click();
  1419. target = picker.find('.datepicker-centuries thead th.prev');
  1420. ok(target.hasClass('disabled'), 'Prev switcher is hidden');
  1421. target = picker.find('.datepicker-centuries thead th.next');
  1422. ok(target.hasClass('disabled'), 'Next switcher is hidden');
  1423. });
  1424. test('date cells (outdated)', function(){
  1425. var input = $('<input />')
  1426. .appendTo('#qunit-fixture')
  1427. .datepicker(),
  1428. dp = input.data('datepicker'),
  1429. picker = dp.picker;
  1430. input.focus();
  1431. picker.find('.datepicker-days .day').each(function(){
  1432. ok(this.hasAttribute('data-date'));
  1433. });
  1434. });
  1435. test('keepEmptyValues: none (default is false)', function() {
  1436. var proxy_element = $('<div />').appendTo('#qunit-fixture'),
  1437. input_from = $('<input />').val('2016-04-01').appendTo('#qunit-fixture'),
  1438. input_to = $('<input />').appendTo('#qunit-fixture'),
  1439. dp = proxy_element.datepicker({
  1440. format: 'yyyy-mm-dd',
  1441. inputs: [input_from, input_to]
  1442. }),
  1443. input_from_dp = input_from.data('datepicker');
  1444. input_from.focus();
  1445. input_from_dp.picker.find('.old.day').eq(0).click();
  1446. equal(input_from.val(), '2016-03-27');
  1447. equal(input_to.val(), '2016-03-27', 'Input_from value should be distributed.');
  1448. });
  1449. test('keepEmptyValues: true', function() {
  1450. var proxy_element = $('<div />').appendTo('#qunit-fixture'),
  1451. input_from = $('<input />').val('2016-04-01').appendTo('#qunit-fixture'),
  1452. input_to = $('<input />').appendTo('#qunit-fixture'),
  1453. dp = proxy_element.datepicker({
  1454. format: 'yyyy-mm-dd',
  1455. inputs: [input_from, input_to],
  1456. keepEmptyValues: true
  1457. }),
  1458. input_from_dp = input_from.data('datepicker');
  1459. input_from.focus();
  1460. input_from_dp.picker.find('.old.day').eq(0).click();
  1461. equal(input_from.val(), '2016-03-27');
  1462. equal(input_to.val(), '', 'Input_from value should not be distributed.');
  1463. });
  1464. test('maxViewMode and navigation switch', function(){
  1465. var input = $('<input />')
  1466. .appendTo('#qunit-fixture')
  1467. .datepicker({
  1468. maxViewMode: 0
  1469. }),
  1470. dp = input.data('datepicker'),
  1471. picker = dp.picker;
  1472. input.focus();
  1473. picker.find('.datepicker-days thead th.datepicker-switch').click();
  1474. ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
  1475. });
  1476. test('updateViewDate', function() {
  1477. expect(8);
  1478. var input = $('<input value="08/03/1990"/>')
  1479. .appendTo('#qunit-fixture')
  1480. .datepicker({
  1481. defaultViewDate: {
  1482. year: 1945,
  1483. month: 4,
  1484. day: 8
  1485. },
  1486. updateViewDate: false
  1487. })
  1488. .on('changeMonth', function() {
  1489. var msg = shouldTriggerChangeMonth ? 'changeMonth must be triggered' : 'changeMonth must not be triggered';
  1490. ok(shouldTriggerChangeMonth, msg);
  1491. })
  1492. .on('changeYear', function() {
  1493. var msg = shouldTriggerChangeYear ? 'changeYear must be triggered' : 'changeYear must not be triggered';
  1494. ok(shouldTriggerChangeYear, msg);
  1495. }),
  1496. dp = input.data('datepicker'),
  1497. picker = dp.picker,
  1498. shouldTriggerChangeMonth = false,
  1499. shouldTriggerChangeYear = false,
  1500. monthShown = picker.find('.datepicker-days thead th.datepicker-switch');
  1501. equal(monthShown.text(), "May 1945", 'uses defaultViewDate on initialization');
  1502. input.datepicker('setDate', new Date(1945, 8, 2));
  1503. equal(monthShown.text(), "May 1945", 'does not change viewDate on `setDate` method');
  1504. input.focus();
  1505. picker.find('.datepicker-days tbody tr td.day.new:first').click();
  1506. equal(monthShown.text(), "May 1945", 'does not change viewDate if a day in next month is selected');
  1507. shouldTriggerChangeMonth = true;
  1508. picker.find('.datepicker-days thead th.next').click();
  1509. equal(monthShown.text(), 'June 1945', 'changing month must still be possible'); // and must trigger `changeMonth` event
  1510. shouldTriggerChangeYear = true;
  1511. picker.find('.datepicker-days thead th.datepicker-switch').click();
  1512. picker.find('.datepicker-months thead th.next').click();
  1513. picker.find('.datepicker-months tbody .month:first').click();
  1514. equal(monthShown.text(), 'January 1946', 'changing year must still be possible'); // and must trigger `changeYear` and `changeMonth` events
  1515. });
  1516. test('Week Days: Week days default visibility (or enabled)', function(){
  1517. var input = $('<input />')
  1518. .appendTo('#qunit-fixture')
  1519. .val('2012-03-05')
  1520. .datepicker({
  1521. format: 'yyyy-mm-dd'
  1522. }),
  1523. dp = input.data('datepicker'),
  1524. picker = dp.picker,
  1525. target;
  1526. input.focus();
  1527. ok(picker.find('.dow').length > 0, 'Week days added to view');
  1528. });
  1529. test('Week Days: Week days visibility when disabled', function(){
  1530. var input = $('<input />')
  1531. .appendTo('#qunit-fixture')
  1532. .val('2012-03-05')
  1533. .datepicker({
  1534. format: 'yyyy-mm-dd',
  1535. showWeekDays: false
  1536. }),
  1537. dp = input.data('datepicker'),
  1538. picker = dp.picker,
  1539. target;
  1540. input.focus();
  1541. ok(picker.find('.dow').length === 0, 'Week days not added to view');
  1542. });