options.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. describe('options', function () {
  2. let clock;
  3. let input;
  4. beforeEach(function () {
  5. clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
  6. input = document.createElement('input');
  7. testContainer.appendChild(input);
  8. });
  9. afterEach(function () {
  10. testContainer.removeChild(input);
  11. clock.restore();
  12. });
  13. describe('autohide', function () {
  14. it('makes the picker hide automatically on selection when true', function () {
  15. const {dp, picker} = createDP(input, {autohide: true});
  16. dp.show();
  17. // by satDate()
  18. dp.setDate('2/4/2020');
  19. expect(isVisible(picker), 'to be false');
  20. dp.show();
  21. // by click on day cell
  22. getCells(picker)[25].click();
  23. expect(isVisible(picker), 'to be false');
  24. dp.show();
  25. // by typing enter key in edit mode
  26. dp.enterEditMode();
  27. input.value = '2/14/2020';
  28. simulant.fire(input, 'keydown', {key: 'Enter'});
  29. expect(isVisible(picker), 'to be false');
  30. // focus is kept on input field after auto-hidng by clicking day cell
  31. // (issue #21)
  32. const spyFocus = sinon.spy(input, 'focus');
  33. dp.show();
  34. getCells(picker)[25].click();
  35. expect(spyFocus.called, 'to be true');
  36. spyFocus.restore();
  37. dp.destroy();
  38. input.value = '';
  39. });
  40. it('can be updated with setOptions()', function () {
  41. const {dp, picker} = createDP(input);
  42. dp.setOptions({autohide: true});
  43. dp.show();
  44. dp.setDate('2/4/2020');
  45. expect(isVisible(picker), 'to be false');
  46. dp.setOptions({autohide: false});
  47. dp.show();
  48. dp.setDate('2/14/2020');
  49. expect(isVisible(picker), 'to be true');
  50. dp.destroy();
  51. input.value = '';
  52. });
  53. });
  54. describe('buttonClass', function () {
  55. it('specifies the main class used for the button elements', function () {
  56. const {dp, picker} = createDP(input, {buttonClass: 'btn'});
  57. const [viewSwitch, prevBtn, nextBtn, todayBtn, clearBtn] = getParts(picker, [
  58. '.view-switch',
  59. '.prev-btn',
  60. '.next-btn',
  61. '.today-btn',
  62. '.clear-btn',
  63. ]);
  64. expect(viewSwitch.className, 'to be', 'btn view-switch');
  65. expect(prevBtn.className, 'to be', 'btn prev-btn');
  66. expect(nextBtn.className, 'to be', 'btn next-btn');
  67. expect(todayBtn.className, 'to be', 'btn today-btn');
  68. expect(clearBtn.className, 'to be', 'btn clear-btn');
  69. dp.destroy();
  70. });
  71. it('cannot be update with setOptions()', function () {
  72. const {dp, picker} = createDP(input);
  73. dp.setOptions({buttonClass: 'btn'});
  74. const [viewSwitch, prevBtn, nextBtn, todayBtn, clearBtn] = getParts(picker, [
  75. '.view-switch',
  76. '.prev-btn',
  77. '.next-btn',
  78. '.today-btn',
  79. '.clear-btn',
  80. ]);
  81. expect(viewSwitch.className, 'to be', 'button view-switch');
  82. expect(prevBtn.className, 'to be', 'button prev-btn');
  83. expect(nextBtn.className, 'to be', 'button next-btn');
  84. expect(todayBtn.className, 'to be', 'button today-btn');
  85. expect(clearBtn.className, 'to be', 'button clear-btn');
  86. dp.destroy();
  87. });
  88. });
  89. describe('calendarWeeks', function () {
  90. const getDisplayedWeeks = (picker) => {
  91. const calendarWeeks = picker.querySelector('.calendar-weeks');
  92. return Array.from(calendarWeeks.querySelectorAll('.week')).map(el => el.textContent);
  93. };
  94. it('enables display ISO weeks in days view when true', function () {
  95. const {dp, picker} = createDP(input, {calendarWeeks: true});
  96. const [viewSwitch, prevBtn] = getParts(picker, ['.view-switch', '.prev-btn']);
  97. dp.show();
  98. let calendarWeeks = picker.querySelector('.calendar-weeks');
  99. expect(isVisible(calendarWeeks), 'to be true');
  100. expect(getDisplayedWeeks(picker), 'to equal', ['5', '6', '7', '8', '9', '10']);
  101. prevBtn.click();
  102. expect(getDisplayedWeeks(picker), 'to equal', ['1', '2', '3', '4', '5', '6']);
  103. prevBtn.click();
  104. expect(getDisplayedWeeks(picker), 'to equal', ['48', '49', '50', '51', '52', '1']);
  105. prevBtn.click();
  106. expect(getDisplayedWeeks(picker), 'to equal', ['44', '45', '46', '47', '48', '49']);
  107. dp.setDate('01/01/2021');
  108. expect(getDisplayedWeeks(picker), 'to equal', ['53', '1', '2', '3', '4', '5']);
  109. prevBtn.click();
  110. expect(getDisplayedWeeks(picker), 'to equal', ['49', '50', '51', '52', '53', '1']);
  111. // months view
  112. viewSwitch.click();
  113. expect(picker.querySelector('.calendar-weeks'), 'to be null');
  114. // years view
  115. viewSwitch.click();
  116. expect(picker.querySelector('.calendar-weeks'), 'to be null');
  117. // decades view
  118. viewSwitch.click();
  119. expect(picker.querySelector('.calendar-weeks'), 'to be null');
  120. dp.destroy();
  121. });
  122. it('can be updated with setOptions()', function () {
  123. const {dp, picker} = createDP(input);
  124. dp.setOptions({calendarWeeks: true});
  125. dp.show();
  126. expect(isVisible(picker.querySelector('.calendar-weeks')), 'to be true');
  127. dp.setOptions({calendarWeeks: false});
  128. expect(picker.querySelector('.calendar-weeks'), 'to be null');
  129. dp.destroy();
  130. });
  131. });
  132. describe('container', function () {
  133. let foo;
  134. beforeEach(function () {
  135. foo = parseHTML('<div id="foo"><div>').firstChild;
  136. testContainer.appendChild(foo);
  137. });
  138. afterEach(function () {
  139. testContainer.removeChild(foo);
  140. });
  141. it('specifies the element to attach the picker', function () {
  142. const dp = new Datepicker(input, {container: '#foo'});
  143. expect(document.querySelector('.datepicker').parentElement, 'to be', foo);
  144. dp.destroy();
  145. });
  146. it('cannot be update with setOptions()', function () {
  147. const dp = new Datepicker(input);
  148. dp.setOptions({container: '#foo'});
  149. expect(document.querySelector('.datepicker').parentElement, 'to be', document.body);
  150. dp.destroy();
  151. });
  152. });
  153. describe('daysOfWeekHighlighted', function () {
  154. const highlightedCellIndices = (picker) => {
  155. const cells = getCells(picker);
  156. return filterCells(cells, '.highlighted').map(el => cells.indexOf(el));
  157. };
  158. const highlighted1stWeekIndices = picker => highlightedCellIndices(picker).filter(val => val < 7);
  159. it('specifies the days of week to highlight by dey numbers', function () {
  160. const {dp, picker} = createDP(input, {daysOfWeekHighlighted: [1, 5]});
  161. dp.show();
  162. expect(highlightedCellIndices(picker), 'to equal', [1, 5, 8, 12, 15, 19, 22, 26, 29, 33, 36, 40]);
  163. const viewSwitch = getViewSwitch(picker);
  164. // months view
  165. viewSwitch.click();
  166. expect(highlightedCellIndices(picker), 'to equal', []);
  167. // years view
  168. viewSwitch.click();
  169. expect(highlightedCellIndices(picker), 'to equal', []);
  170. // decades view
  171. viewSwitch.click();
  172. expect(highlightedCellIndices(picker), 'to equal', []);
  173. dp.destroy();
  174. });
  175. it('can contain values of 0 - 6 and max 6 items', function () {
  176. const {dp, picker} = createDP(input, {daysOfWeekHighlighted: [0, -1, 1, 2, 3, 2, 4, 5, 6, 7]});
  177. dp.show();
  178. expect(highlighted1stWeekIndices(picker), 'to equal', [0, 1, 2, 3, 4, 5]);
  179. dp.destroy();
  180. });
  181. it('can be updated with setOptions()', function () {
  182. const {dp, picker} = createDP(input);
  183. dp.setOptions({daysOfWeekHighlighted: [6, 0, 3]});
  184. dp.show();
  185. expect(highlighted1stWeekIndices(picker), 'to equal', [0, 3, 6]);
  186. dp.setOptions({daysOfWeekHighlighted: []});
  187. expect(highlightedCellIndices(picker), 'to equal', []);
  188. dp.destroy();
  189. });
  190. });
  191. describe('defaultViewDate', function () {
  192. it('specifies the start view date in the case no selection is made', function () {
  193. const date = new Date(1984, 0, 24);
  194. const {dp, picker} = createDP(input, {defaultViewDate: date});
  195. dp.show();
  196. expect(getViewSwitch(picker).textContent, 'to be', 'January 1984');
  197. let cells = getCells(picker);
  198. expect(filterCells(cells, '.focused'), 'to equal', [cells[23]]);
  199. expect(cells[23].textContent, 'to be', '24');
  200. dp.setDate('7/4/2020');
  201. dp.setDate({clear: true});
  202. expect(getViewSwitch(picker).textContent, 'to be', 'January 1984');
  203. cells = getCells(picker);
  204. expect(filterCells(cells, '.focused'), 'to equal', [cells[23]]);
  205. expect(cells[23].textContent, 'to be', '24');
  206. picker.querySelector('.prev-btn').click();
  207. dp.hide();
  208. dp.show();
  209. expect(getViewSwitch(picker).textContent, 'to be', 'January 1984');
  210. cells = getCells(picker);
  211. expect(filterCells(cells, '.focused'), 'to equal', [cells[23]]);
  212. expect(cells[23].textContent, 'to be', '24');
  213. dp.destroy();
  214. });
  215. it('can be updated with setOptions()', function () {
  216. const {dp, picker} = createDP(input);
  217. dp.show();
  218. dp.setOptions({defaultViewDate: new Date(1984, 0, 24)});
  219. dp.hide();
  220. dp.show();
  221. expect(getViewSwitch(picker).textContent, 'to be', 'January 1984');
  222. let cells = getCells(picker);
  223. expect(filterCells(cells, '.focused'), 'to equal', [cells[23]]);
  224. expect(cells[23].textContent, 'to be', '24');
  225. dp.setOptions({defaultViewDate: new Date(2007, 5, 29)});
  226. dp.setDate('7/4/2020');
  227. dp.setDate({clear: true});
  228. expect(getViewSwitch(picker).textContent, 'to be', 'June 2007');
  229. cells = getCells(picker);
  230. expect(filterCells(cells, '.focused'), 'to equal', [cells[33]]);
  231. expect(cells[33].textContent, 'to be', '29');
  232. dp.destroy();
  233. });
  234. });
  235. describe('disableTouchKeyboard', function () {
  236. const ontouchstartSupported = 'ontouchstart' in document;
  237. before(function () {
  238. if (!ontouchstartSupported) {
  239. document.ontouchstart = null;
  240. }
  241. });
  242. after(function () {
  243. if (!ontouchstartSupported) {
  244. delete document.ontouchstart;
  245. }
  246. });
  247. it('unfocuses the input after showing the picker', function () {
  248. const dp = new Datepicker(input, {disableTouchKeyboard: true});
  249. input.focus();
  250. expect(document.activeElement, 'not to be', input);
  251. dp.destroy();
  252. });
  253. it('prevents the input from getting focus after an eleent in the picker is clicked', function () {
  254. const {dp, picker} = createDP(input, {disableTouchKeyboard: true});
  255. const [viewSwitch, prevBtn] = getParts(picker, ['.view-switch', '.prev-btn']);
  256. dp.show();
  257. prevBtn.focus();
  258. simulant.fire(prevBtn, 'click');
  259. expect(document.activeElement, 'not to be', input);
  260. simulant.fire(getCells(picker)[15], 'click');
  261. expect(document.activeElement, 'not to be', input);
  262. viewSwitch.focus();
  263. simulant.fire(viewSwitch, 'click');
  264. expect(document.activeElement, 'not to be', input);
  265. simulant.fire(getCells(picker)[6], 'click');
  266. expect(document.activeElement, 'not to be', input);
  267. dp.destroy();
  268. });
  269. it('is ignored if the browser does not support document.ontouchstart', function () {
  270. if (ontouchstartSupported) {
  271. return;
  272. }
  273. delete document.ontouchstart;
  274. const {dp, picker} = createDP(input, {disableTouchKeyboard: true});
  275. const [viewSwitch, prevBtn] = getParts(picker, ['.view-switch', '.prev-btn']);
  276. input.focus();
  277. expect(document.activeElement, 'to be', input);
  278. prevBtn.focus();
  279. simulant.fire(prevBtn, 'click');
  280. expect(document.activeElement, 'to be', input);
  281. prevBtn.focus();
  282. simulant.fire(getCells(picker)[15], 'click');
  283. expect(document.activeElement, 'to be', input);
  284. viewSwitch.focus();
  285. simulant.fire(viewSwitch, 'click');
  286. expect(document.activeElement, 'to be', input);
  287. viewSwitch.focus();
  288. simulant.fire(getCells(picker)[6], 'click');
  289. expect(document.activeElement, 'to be', input);
  290. dp.destroy();
  291. document.ontouchstart = null;
  292. });
  293. it('can be updated with setOptions()', function () {
  294. const dp = new Datepicker(input);
  295. dp.setOptions({disableTouchKeyboard: true});
  296. input.focus();
  297. expect(document.activeElement, 'not to be', input);
  298. dp.hide();
  299. dp.setOptions({disableTouchKeyboard: false});
  300. input.focus();
  301. expect(document.activeElement, 'to be', input);
  302. dp.destroy();
  303. });
  304. });
  305. describe('nextArrow', function () {
  306. it('specifies the label of the next button in HTML (or plain text)', function () {
  307. const html = '<i class="icn icn-arrow-right"></i>';
  308. const {dp, picker} = createDP(input, {nextArrow: html});
  309. const nextBtn = picker.querySelector('.next-btn');
  310. dp.show();
  311. expect(nextBtn.innerHTML, 'to be', html);
  312. dp.destroy();
  313. });
  314. it('can be updated with setOptions()', function () {
  315. const {dp, picker} = createDP(input);
  316. const nextBtn = picker.querySelector('.next-btn');
  317. dp.setOptions({nextArrow: 'N'});
  318. dp.show();
  319. expect(nextBtn.textContent, 'to be', 'N');
  320. dp.setOptions({nextArrow: '>'});
  321. expect(nextBtn.textContent, 'to be', '>');
  322. dp.destroy();
  323. });
  324. });
  325. describe('prevArrow', function () {
  326. it('specifies the label of the next button in HTML (or plain text)', function () {
  327. const html = '<i class="icn icn-arrow-left"></i>';
  328. const {dp, picker} = createDP(input, {prevArrow: html});
  329. const prevBtn = picker.querySelector('.prev-btn');
  330. dp.show();
  331. expect(prevBtn.innerHTML, 'to be', html);
  332. dp.destroy();
  333. });
  334. it('can be updated with setOptions()', function () {
  335. const {dp, picker} = createDP(input);
  336. const prevBtn = picker.querySelector('.prev-btn');
  337. dp.setOptions({prevArrow: 'P'});
  338. dp.show();
  339. expect(prevBtn.textContent, 'to be', 'P');
  340. dp.setOptions({prevArrow: '<'});
  341. expect(prevBtn.textContent, 'to be', '<');
  342. dp.destroy();
  343. });
  344. });
  345. describe('showDaysOfWeek', function () {
  346. it('hides day names of week when false', function () {
  347. const {dp, picker} = createDP(input, {showDaysOfWeek: false});
  348. dp.show();
  349. expect(isVisible(picker.querySelector('.days-of-week')), 'to be false');
  350. dp.destroy();
  351. });
  352. it('can be updated with setOptions()', function () {
  353. const {dp, picker} = createDP(input);
  354. dp.setOptions({showDaysOfWeek: false});
  355. dp.show();
  356. expect(isVisible(picker.querySelector('.days-of-week')), 'to be false');
  357. dp.setOptions({showDaysOfWeek: true});
  358. expect(isVisible(picker.querySelector('.days-of-week')), 'to be true');
  359. dp.destroy();
  360. });
  361. });
  362. describe('showOnClick', function () {
  363. it('disables the picker to auto-open on clicking input when false', function () {
  364. const {dp, picker} = createDP(input, {showOnClick: false});
  365. input.focus();
  366. dp.hide();
  367. simulant.fire(input, 'mousedown');
  368. input.click();
  369. expect(isVisible(picker), 'to be false');
  370. dp.destroy();
  371. });
  372. it('can be updated with setOptions()', function () {
  373. const {dp, picker} = createDP(input);
  374. dp.setOptions({showOnClick: false});
  375. input.focus();
  376. dp.hide();
  377. simulant.fire(input, 'mousedown');
  378. input.click();
  379. expect(isVisible(picker), 'to be false');
  380. dp.setOptions({showOnClick: true});
  381. simulant.fire(input, 'mousedown');
  382. input.click();
  383. expect(isVisible(picker), 'to be true');
  384. dp.destroy();
  385. });
  386. });
  387. describe('showOnFocus', function () {
  388. it('disables the picker to auto-open on focus when false', function () {
  389. const {dp, picker} = createDP(input, {showOnFocus: false});
  390. input.focus();
  391. expect(isVisible(picker), 'to be false');
  392. dp.destroy();
  393. });
  394. it('can be updated with setOptions()', function () {
  395. const {dp, picker} = createDP(input);
  396. dp.setOptions({showOnFocus: false});
  397. input.focus();
  398. expect(isVisible(picker), 'to be false');
  399. input.blur();
  400. dp.setOptions({showOnFocus: true});
  401. input.focus();
  402. expect(isVisible(picker), 'to be true');
  403. dp.destroy();
  404. });
  405. });
  406. describe('title', function () {
  407. it('specifies the title of the picker and shows it when not empty', function () {
  408. const {dp, picker} = createDP(input, {title: 'Foo Bar'});
  409. const title = picker.querySelector('.datepicker-title');
  410. dp.show();
  411. expect(title.textContent, 'to be', 'Foo Bar');
  412. expect(isVisible(title), 'to be true');
  413. dp.destroy();
  414. });
  415. it('can be updated with setOptions()', function () {
  416. const {dp, picker} = createDP(input);
  417. const title = picker.querySelector('.datepicker-title');
  418. dp.setOptions({title: 'My Datepicker'});
  419. dp.show();
  420. expect(title.textContent, 'to be', 'My Datepicker');
  421. expect(isVisible(title), 'to be true');
  422. dp.setOptions({title: ''});
  423. expect(title.textContent, 'to be', '');
  424. expect(isVisible(title), 'to be false');
  425. dp.destroy();
  426. });
  427. });
  428. describe('todayHighlight', function () {
  429. it('highlights the current date in days view when true', function () {
  430. const {dp, picker} = createDP(input, {todayHighlight: true});
  431. const viewSwitch = getViewSwitch(picker);
  432. dp.show();
  433. let cells = getCells(picker);
  434. expect(filterCells(cells, '.today'), 'to equal', [cells[19]]);
  435. picker.querySelector('.prev-btn').click();
  436. expect(filterCells(getCells(picker), '.today'), 'to equal', []);
  437. picker.querySelector('.next-btn').click();
  438. viewSwitch.click();
  439. expect(filterCells(getCells(picker), '.today'), 'to equal', []);
  440. viewSwitch.click();
  441. expect(filterCells(getCells(picker), '.today'), 'to equal', []);
  442. viewSwitch.click();
  443. expect(filterCells(getCells(picker), '.today'), 'to equal', []);
  444. dp.destroy();
  445. });
  446. it('can be updated with setOptions()', function () {
  447. const {dp, picker} = createDP(input);
  448. dp.setOptions({todayHighlight: true});
  449. dp.show();
  450. let cells = getCells(picker);
  451. expect(filterCells(cells, '.today'), 'to equal', [cells[19]]);
  452. dp.setOptions({todayHighlight: false});
  453. cells = getCells(picker);
  454. expect(filterCells(cells, '.today'), 'to equal', []);
  455. dp.destroy();
  456. });
  457. });
  458. describe('updateOnBlur', function () {
  459. it('discards unparsed input on losing focus when false', function () {
  460. const outsider = document.createElement('p');
  461. testContainer.appendChild(outsider);
  462. const {dp, picker} = createDP(input, {updateOnBlur: false});
  463. input.focus();
  464. input.value = 'foo';
  465. // on tab key press
  466. simulant.fire(input, 'keydown', {key: 'Tab'});
  467. expect(input.value, 'to be', '');
  468. dp.setDate('04/22/2020');
  469. dp.show();
  470. dp.enterEditMode();
  471. input.value = 'foo';
  472. simulant.fire(input, 'keydown', {key: 'Tab'});
  473. expect(input.value, 'to be', '04/22/2020');
  474. // on click outside
  475. dp.show();
  476. input.value = 'foo';
  477. simulant.fire(picker.querySelector('.dow'), 'mousedown');
  478. expect(input.value, 'to be', 'foo');
  479. simulant.fire(input, 'mousedown');
  480. expect(input.value, 'to be', 'foo');
  481. simulant.fire(outsider, 'mousedown');
  482. expect(input.value, 'to be', '04/22/2020');
  483. dp.setDate({clear: true});
  484. input.value = 'foo';
  485. simulant.fire(outsider, 'mousedown');
  486. expect(input.value, 'to be', '');
  487. dp.destroy();
  488. testContainer.removeChild(outsider);
  489. });
  490. it('can be updated with setOptions()', function () {
  491. const dp = new Datepicker(input);
  492. dp.setOptions({updateOnBlur: false});
  493. input.focus();
  494. input.value = '04/22/2020';
  495. simulant.fire(input, 'keydown', {key: 'Tab'});
  496. expect(input.value, 'to be', '');
  497. dp.setOptions({updateOnBlur: true});
  498. input.focus();
  499. input.value = '04/22/2020';
  500. simulant.fire(input, 'keydown', {key: 'Tab'});
  501. expect(input.value, 'to be', '04/22/2020');
  502. dp.destroy();
  503. });
  504. });
  505. describe('weekStart', function () {
  506. const getDayNames = (picker) => {
  507. const daysOfWeek = picker.querySelector('.days-of-week');
  508. return Array.from(daysOfWeek.children).map(el => el.textContent);
  509. };
  510. const getDatesInColumn = (picker, colIndex) => {
  511. const cells = getCells(picker);
  512. return cells.reduce((dates, el, ix) => {
  513. if (ix % 7 === colIndex) {
  514. dates.push(el.textContent);
  515. }
  516. return dates;
  517. }, []);
  518. };
  519. it('specifies the day of week to display in the first column', function () {
  520. const {dp, picker} = createDP(input, {weekStart: 1});
  521. dp.show();
  522. expect(getDayNames(picker), 'to equal', ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']);
  523. expect(getDatesInColumn(picker, 0), 'to equal', ['27', '3', '10', '17', '24', '2']);
  524. expect(getDatesInColumn(picker, 6), 'to equal', ['2', '9', '16', '23', '1', '8']);
  525. dp.destroy();
  526. });
  527. it('can be updated with setOptions()', function () {
  528. const {dp, picker} = createDP(input);
  529. dp.setOptions({weekStart: 4});
  530. dp.show();
  531. expect(getDayNames(picker), 'to equal', ['Th', 'Fr', 'Sa', 'Su', 'Mo', 'Tu', 'We']);
  532. expect(getDatesInColumn(picker, 0), 'to equal', ['30', '6', '13', '20', '27', '5']);
  533. expect(getDatesInColumn(picker, 6), 'to equal', ['5', '12', '19', '26', '4', '11']);
  534. dp.setOptions({weekStart: 0});
  535. expect(getDayNames(picker), 'to equal', ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']);
  536. expect(getDatesInColumn(picker, 0), 'to equal', ['26', '2', '9', '16', '23', '1']);
  537. expect(getDatesInColumn(picker, 6), 'to equal', ['1', '8', '15', '22', '29', '7']);
  538. dp.destroy();
  539. });
  540. });
  541. });