before-show.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. describe('options - beforeShow hooks', 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('beforeShowDay', function () {
  14. it('disables the date when it returns false', function () {
  15. const beforeShowDay = date => !!(date.getDate() % 10);
  16. const {dp, picker} = createDP(input, {beforeShowDay});
  17. let cells = getCells(picker);
  18. let disabledCells = filterCells(cells, '.disabled');
  19. expect(disabledCells, 'to equal', [cells[4], cells[15], cells[25]]);
  20. expect(disabledCells.map(el => el.textContent), 'to equal', ['30', '10', '20']);
  21. picker.querySelector('.next-btn').click();
  22. cells = getCells(picker);
  23. disabledCells = filterCells(cells, '.disabled');
  24. expect(disabledCells, 'to equal', [cells[9], cells[19], cells[29], cells[40]]);
  25. expect(disabledCells.map(el => el.textContent), 'to equal', ['10', '20', '30', '10']);
  26. dp.destroy();
  27. });
  28. it('adds classes to the date when it returns spece separated classes', function () {
  29. const beforeShowDay = date => date.getDate() % 10 ? undefined : 'foo bar';
  30. const {dp, picker} = createDP(input, {beforeShowDay});
  31. let cells = getCells(picker);
  32. let fooCells = filterCells(cells, '.foo');
  33. let barCells = filterCells(cells, '.bar');
  34. expect(fooCells, 'to equal', [cells[4], cells[15], cells[25]]);
  35. expect(barCells, 'to equal', fooCells);
  36. expect(fooCells.map(el => el.textContent), 'to equal', ['30', '10', '20']);
  37. picker.querySelector('.next-btn').click();
  38. cells = getCells(picker);
  39. fooCells = filterCells(cells, '.foo');
  40. barCells = filterCells(cells, '.bar');
  41. expect(fooCells, 'to equal', [cells[9], cells[19], cells[29], cells[40]]);
  42. expect(barCells, 'to equal', fooCells);
  43. expect(fooCells.map(el => el.textContent), 'to equal', ['10', '20', '30', '10']);
  44. dp.destroy();
  45. });
  46. it('disables the date when the return contains enabled: false', function () {
  47. const beforeShowDay = date => ({enabled: !!(date.getDate() % 10)});
  48. const {dp, picker} = createDP(input, {beforeShowDay});
  49. let cells = getCells(picker);
  50. let disabledCells = filterCells(cells, '.disabled');
  51. expect(disabledCells, 'to equal', [cells[4], cells[15], cells[25]]);
  52. picker.querySelector('.next-btn').click();
  53. cells = getCells(picker);
  54. disabledCells = filterCells(cells, '.disabled');
  55. expect(disabledCells, 'to equal', [cells[9], cells[19], cells[29], cells[40]]);
  56. dp.destroy();
  57. });
  58. it('adds classes to the date when the return contains space separated classes in the classes property', function () {
  59. const beforeShowDay = date => date.getDate() % 10 ? undefined : {classes: 'foo bar'};
  60. const {dp, picker} = createDP(input, {beforeShowDay});
  61. let cells = getCells(picker);
  62. let fooCells = filterCells(cells, '.foo');
  63. let barCells = filterCells(cells, '.bar');
  64. expect(fooCells, 'to equal', [cells[4], cells[15], cells[25]]);
  65. expect(barCells, 'to equal', fooCells);
  66. picker.querySelector('.next-btn').click();
  67. cells = getCells(picker);
  68. fooCells = filterCells(cells, '.foo');
  69. barCells = filterCells(cells, '.bar');
  70. expect(fooCells, 'to equal', [cells[9], cells[19], cells[29], cells[40]]);
  71. expect(barCells, 'to equal', fooCells);
  72. dp.destroy();
  73. });
  74. it('uses custom content to the date cell when the return contains text/html in the content property', function () {
  75. const beforeShowDay = (date) => date.getDate() % 10 === 4 ? {content: '<em>❤️</em>'} : undefined;
  76. const {dp, picker} = createDP(input, {beforeShowDay});
  77. let cells = getCells(picker);
  78. let ccCells = cells.filter(el => el.children.length > 0);
  79. expect(ccCells, 'to equal', [cells[9], cells[19], cells[29], cells[38]]);
  80. ccCells.forEach((cell) => {
  81. expect(cell.innerHTML, 'to be', '<em>❤️</em>');
  82. });
  83. picker.querySelector('.next-btn').click();
  84. cells = getCells(picker);
  85. ccCells = cells.filter(el => el.children.length > 0);
  86. expect(ccCells, 'to equal', [cells[3], cells[13], cells[23], cells[34]]);
  87. ccCells.forEach((cell) => {
  88. expect(cell.innerHTML, 'to be', '<em>❤️</em>');
  89. });
  90. dp.destroy();
  91. });
  92. it('can be updated with setOptions()', function () {
  93. const {dp, picker} = createDP(input);
  94. dp.setOptions({beforeShowDay: date => !!(date.getDate() % 10)});
  95. dp.show();
  96. let cells = getCells(picker);
  97. let disabledCells = filterCells(cells, '.disabled');
  98. expect(disabledCells, 'to equal', [cells[4], cells[15], cells[25]]);
  99. dp.hide();
  100. dp.setOptions({beforeShowDay: null});
  101. dp.show();
  102. cells = getCells(picker);
  103. disabledCells = filterCells(cells, '.disabled');
  104. expect(disabledCells, 'to equal', []);
  105. dp.destroy();
  106. });
  107. });
  108. describe('beforeShowMonth', function () {
  109. it('disables the month on months view when it returns false', function () {
  110. const beforeShowMonth = date => !!(date.getMonth() % 5);
  111. const {dp, picker} = createDP(input, {beforeShowMonth});
  112. const viewSwitch = getViewSwitch(picker);
  113. dp.show();
  114. viewSwitch.click();
  115. let cells = getCells(picker);
  116. let disabledCells = filterCells(cells, '.disabled');
  117. expect(disabledCells, 'to equal', [cells[0], cells[5], cells[10]]);
  118. expect(disabledCells.map(el => el.textContent), 'to equal', ['Jan', 'Jun', 'Nov']);
  119. picker.querySelector('.next-btn').click();
  120. cells = getCells(picker);
  121. disabledCells = filterCells(cells, '.disabled');
  122. expect(disabledCells, 'to equal', [cells[0], cells[5], cells[10]]);
  123. expect(disabledCells.map(el => el.textContent), 'to equal', ['Jan', 'Jun', 'Nov']);
  124. dp.destroy();
  125. });
  126. it('adds classes to the month on months view when it returns spece separated classes', function () {
  127. const beforeShowMonth = date => date.getMonth() % 5 ? undefined : 'foo bar';
  128. const {dp, picker} = createDP(input, {beforeShowMonth});
  129. const viewSwitch = getViewSwitch(picker);
  130. dp.show();
  131. viewSwitch.click();
  132. let cells = getCells(picker);
  133. let fooCells = filterCells(cells, '.foo');
  134. let barCells = filterCells(cells, '.bar');
  135. expect(fooCells, 'to equal', [cells[0], cells[5], cells[10]]);
  136. expect(barCells, 'to equal', fooCells);
  137. expect(fooCells.map(el => el.textContent), 'to equal', ['Jan', 'Jun', 'Nov']);
  138. picker.querySelector('.next-btn').click();
  139. cells = getCells(picker);
  140. fooCells = filterCells(cells, '.foo');
  141. barCells = filterCells(cells, '.bar');
  142. expect(fooCells, 'to equal', [cells[0], cells[5], cells[10]]);
  143. expect(barCells, 'to equal', fooCells);
  144. expect(fooCells.map(el => el.textContent), 'to equal', ['Jan', 'Jun', 'Nov']);
  145. dp.destroy();
  146. });
  147. it('disables the month on months view when the return contains enabled: false', function () {
  148. const beforeShowMonth = date => ({enabled: !!(date.getMonth() % 5)});
  149. const {dp, picker} = createDP(input, {beforeShowMonth});
  150. const viewSwitch = getViewSwitch(picker);
  151. dp.show();
  152. viewSwitch.click();
  153. let cells = getCells(picker);
  154. let disabledCells = filterCells(cells, '.disabled');
  155. expect(disabledCells, 'to equal', [cells[0], cells[5], cells[10]]);
  156. picker.querySelector('.next-btn').click();
  157. cells = getCells(picker);
  158. disabledCells = filterCells(cells, '.disabled');
  159. expect(disabledCells, 'to equal', [cells[0], cells[5], cells[10]]);
  160. dp.destroy();
  161. });
  162. it('adds classes to the month on months view when the return contains space separated classes in the classes property', function () {
  163. const beforeShowMonth = date => date.getMonth() % 5 ? undefined : {classes: 'foo bar'};
  164. const {dp, picker} = createDP(input, {beforeShowMonth});
  165. const viewSwitch = getViewSwitch(picker);
  166. dp.show();
  167. viewSwitch.click();
  168. let cells = getCells(picker);
  169. let fooCells = filterCells(cells, '.foo');
  170. let barCells = filterCells(cells, '.bar');
  171. expect(fooCells, 'to equal', [cells[0], cells[5], cells[10]]);
  172. expect(barCells, 'to equal', fooCells);
  173. picker.querySelector('.next-btn').click();
  174. cells = getCells(picker);
  175. fooCells = filterCells(cells, '.foo');
  176. barCells = filterCells(cells, '.bar');
  177. expect(fooCells, 'to equal', [cells[0], cells[5], cells[10]]);
  178. expect(barCells, 'to equal', fooCells);
  179. dp.destroy();
  180. });
  181. it('uses custom content to the month cell when the return contains text/html in the content property', function () {
  182. const beforeShowMonth = (date) => (date.getMonth() + date.getFullYear() % 10) % 10 ? undefined : {content: '🍀'};
  183. const {dp, picker} = createDP(input, {beforeShowMonth});
  184. const viewSwitch = getViewSwitch(picker);
  185. dp.show();
  186. viewSwitch.click();
  187. let cells = getCells(picker);
  188. let ccCells = cells.filter(el => el.textContent.length < 3);
  189. expect(ccCells, 'to equal', [cells[0], cells[10]]);
  190. ccCells.forEach((cell) => {
  191. expect(cell.textContent, 'to be', '🍀');
  192. });
  193. picker.querySelector('.next-btn').click();
  194. cells = getCells(picker);
  195. ccCells = cells.filter(el => el.textContent.length < 3);
  196. expect(ccCells, 'to equal', [cells[9]]);
  197. ccCells.forEach((cell) => {
  198. expect(cell.textContent, 'to be', '🍀');
  199. });
  200. dp.destroy();
  201. });
  202. it('can be updated with setOptions()', function () {
  203. const {dp, picker} = createDP(input);
  204. const viewSwitch = getViewSwitch(picker);
  205. dp.setOptions({beforeShowMonth: date => !!(date.getMonth() % 5)});
  206. dp.show();
  207. viewSwitch.click();
  208. let cells = getCells(picker);
  209. let disabledCells = filterCells(cells, '.disabled');
  210. expect(disabledCells, 'to equal', [cells[0], cells[5], cells[10]]);
  211. dp.hide();
  212. dp.setOptions({beforeShowMonth: null});
  213. dp.show();
  214. viewSwitch.click();
  215. cells = getCells(picker);
  216. disabledCells = filterCells(cells, '.disabled');
  217. expect(disabledCells, 'to equal', []);
  218. dp.destroy();
  219. });
  220. });
  221. describe('beforeShowYear', function () {
  222. it('disables the year on years view when it returns false', function () {
  223. const beforeShowYear = date => !!(date.getFullYear() % 4);
  224. const {dp, picker} = createDP(input, {beforeShowYear});
  225. const viewSwitch = getViewSwitch(picker);
  226. dp.show();
  227. viewSwitch.click();
  228. viewSwitch.click();
  229. let cells = getCells(picker);
  230. let disabledCells = filterCells(cells, '.disabled');
  231. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  232. expect(disabledCells.map(el => el.textContent), 'to equal', ['2020', '2024', '2028',]);
  233. picker.querySelector('.next-btn').click();
  234. cells = getCells(picker);
  235. disabledCells = filterCells(cells, '.disabled');
  236. expect(disabledCells, 'to equal', [cells[3], cells[7], cells[11]]);
  237. expect(disabledCells.map(el => el.textContent), 'to equal', ['2032', '2036', '2040']);
  238. dp.destroy();
  239. });
  240. it('adds classes to the year on years view when it returns spece separated classes', function () {
  241. const beforeShowYear = date => date.getFullYear() % 4 ? undefined : 'foo bar';
  242. const {dp, picker} = createDP(input, {beforeShowYear});
  243. const viewSwitch = getViewSwitch(picker);
  244. dp.show();
  245. viewSwitch.click();
  246. viewSwitch.click();
  247. let cells = getCells(picker);
  248. let fooCells = filterCells(cells, '.foo');
  249. let barCells = filterCells(cells, '.bar');
  250. expect(fooCells, 'to equal', [cells[1], cells[5], cells[9]]);
  251. expect(barCells, 'to equal', fooCells);
  252. expect(fooCells.map(el => el.textContent), 'to equal', ['2020', '2024', '2028']);
  253. picker.querySelector('.next-btn').click();
  254. cells = getCells(picker);
  255. fooCells = filterCells(cells, '.foo');
  256. barCells = filterCells(cells, '.bar');
  257. expect(fooCells, 'to equal', [cells[3], cells[7], cells[11]]);
  258. expect(barCells, 'to equal', fooCells);
  259. expect(fooCells.map(el => el.textContent), 'to equal', ['2032', '2036', '2040']);
  260. dp.destroy();
  261. });
  262. it('disables the year on years view when the return contains enabled: false', function () {
  263. const beforeShowYear = date => ({enabled: !!(date.getFullYear() % 4)});
  264. const {dp, picker} = createDP(input, {beforeShowYear});
  265. const viewSwitch = getViewSwitch(picker);
  266. dp.show();
  267. viewSwitch.click();
  268. viewSwitch.click();
  269. let cells = getCells(picker);
  270. let disabledCells = filterCells(cells, '.disabled');
  271. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  272. picker.querySelector('.next-btn').click();
  273. cells = getCells(picker);
  274. disabledCells = filterCells(cells, '.disabled');
  275. expect(disabledCells, 'to equal', [cells[3], cells[7], cells[11]]);
  276. dp.destroy();
  277. });
  278. it('adds classes to the year on years view when the return contains space separated classes in the classes property', function () {
  279. const beforeShowYear = date => date.getFullYear() % 4 ? undefined : {classes: 'foo bar'};
  280. const {dp, picker} = createDP(input, {beforeShowYear});
  281. const viewSwitch = getViewSwitch(picker);
  282. dp.show();
  283. viewSwitch.click();
  284. viewSwitch.click();
  285. let cells = getCells(picker);
  286. let fooCells = filterCells(cells, '.foo');
  287. let barCells = filterCells(cells, '.bar');
  288. expect(fooCells, 'to equal', [cells[1], cells[5], cells[9]]);
  289. expect(barCells, 'to equal', fooCells);
  290. picker.querySelector('.next-btn').click();
  291. cells = getCells(picker);
  292. fooCells = filterCells(cells, '.foo');
  293. barCells = filterCells(cells, '.bar');
  294. expect(fooCells, 'to equal', [cells[3], cells[7], cells[11]]);
  295. expect(barCells, 'to equal', fooCells);
  296. dp.destroy();
  297. });
  298. it('uses custom content to the year cell when the return contains text/html in the content property', function () {
  299. const beforeShowYear = (date) => {
  300. const year = date.getFullYear();
  301. return (year + Math.floor(year / 10) % 10) % 4 ? undefined : {content: '<i class="icn-x"></i>'};
  302. };
  303. const {dp, picker} = createDP(input, {beforeShowYear});
  304. const viewSwitch = getViewSwitch(picker);
  305. dp.show();
  306. viewSwitch.click();
  307. viewSwitch.click();
  308. let cells = getCells(picker);
  309. let ccCells = cells.filter(el => el.children.length > 0);
  310. expect(ccCells, 'to equal', [cells[1], cells[5], cells[9]]);
  311. ccCells.forEach((cell) => {
  312. expect(cell.innerHTML, 'to be', '<i class="icn-x"></i>');
  313. });
  314. picker.querySelector('.next-btn').click();
  315. cells = getCells(picker);
  316. ccCells = cells.filter(el => el.children.length > 0);
  317. expect(ccCells, 'to equal', [cells[2], cells[6], cells[10]]);
  318. ccCells.forEach((cell) => {
  319. expect(cell.innerHTML, 'to be', '<i class="icn-x"></i>');
  320. });
  321. dp.destroy();
  322. });
  323. it('can be updated with setOptions()', function () {
  324. const {dp, picker} = createDP(input);
  325. const viewSwitch = getViewSwitch(picker);
  326. dp.setOptions({beforeShowYear: date => !!(date.getFullYear() % 4)});
  327. dp.show();
  328. viewSwitch.click();
  329. viewSwitch.click();
  330. let cells = getCells(picker);
  331. let disabledCells = filterCells(cells, '.disabled');
  332. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  333. dp.hide();
  334. dp.setOptions({beforeShowYear: null});
  335. dp.show();
  336. viewSwitch.click();
  337. viewSwitch.click();
  338. cells = getCells(picker);
  339. disabledCells = filterCells(cells, '.disabled');
  340. expect(disabledCells, 'to equal', []);
  341. dp.destroy();
  342. });
  343. });
  344. describe('beforeShowDecade', function () {
  345. it('disables the decade on decades view when it returns false', function () {
  346. const beforeShowDecade = date => !!((date.getFullYear() / 10) % 4);
  347. const {dp, picker} = createDP(input, {beforeShowDecade});
  348. const viewSwitch = getViewSwitch(picker);
  349. dp.show();
  350. viewSwitch.click();
  351. viewSwitch.click();
  352. viewSwitch.click();
  353. let cells = getCells(picker);
  354. let disabledCells = filterCells(cells, '.disabled');
  355. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  356. expect(disabledCells.map(el => el.textContent), 'to equal', ['2000', '2040', '2080',]);
  357. picker.querySelector('.next-btn').click();
  358. cells = getCells(picker);
  359. disabledCells = filterCells(cells, '.disabled');
  360. expect(disabledCells, 'to equal', [cells[3], cells[7], cells[11]]);
  361. expect(disabledCells.map(el => el.textContent), 'to equal', ['2120', '2160', '2200']);
  362. dp.destroy();
  363. });
  364. it('adds classes to the decade on decades view when it returns spece separated classes', function () {
  365. const beforeShowDecade = date => (date.getFullYear() / 10) % 4 ? undefined : 'foo bar';
  366. const {dp, picker} = createDP(input, {beforeShowDecade});
  367. const viewSwitch = getViewSwitch(picker);
  368. dp.show();
  369. viewSwitch.click();
  370. viewSwitch.click();
  371. viewSwitch.click();
  372. let cells = getCells(picker);
  373. let fooCells = filterCells(cells, '.foo');
  374. let barCells = filterCells(cells, '.bar');
  375. expect(fooCells, 'to equal', [cells[1], cells[5], cells[9]]);
  376. expect(barCells, 'to equal', fooCells);
  377. expect(fooCells.map(el => el.textContent), 'to equal', ['2000', '2040', '2080']);
  378. picker.querySelector('.next-btn').click();
  379. cells = getCells(picker);
  380. fooCells = filterCells(cells, '.foo');
  381. barCells = filterCells(cells, '.bar');
  382. expect(fooCells, 'to equal', [cells[3], cells[7], cells[11]]);
  383. expect(barCells, 'to equal', fooCells);
  384. expect(fooCells.map(el => el.textContent), 'to equal', ['2120', '2160', '2200']);
  385. dp.destroy();
  386. });
  387. it('disables the decade on decades view when the return contains enabled: false', function () {
  388. const beforeShowDecade = date => ({enabled: !!((date.getFullYear() / 10) % 4)});
  389. const {dp, picker} = createDP(input, {beforeShowDecade});
  390. const viewSwitch = getViewSwitch(picker);
  391. dp.show();
  392. viewSwitch.click();
  393. viewSwitch.click();
  394. viewSwitch.click();
  395. let cells = getCells(picker);
  396. let disabledCells = filterCells(cells, '.disabled');
  397. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  398. picker.querySelector('.next-btn').click();
  399. cells = getCells(picker);
  400. disabledCells = filterCells(cells, '.disabled');
  401. expect(disabledCells, 'to equal', [cells[3], cells[7], cells[11]]);
  402. dp.destroy();
  403. });
  404. it('adds classes to the decade on decades view when the return contains space separated classes in the classes property', function () {
  405. const beforeShowDecade = date => (date.getFullYear() / 10) % 4 ? undefined : {classes: 'foo bar'};
  406. const {dp, picker} = createDP(input, {beforeShowDecade});
  407. const viewSwitch = getViewSwitch(picker);
  408. dp.show();
  409. viewSwitch.click();
  410. viewSwitch.click();
  411. viewSwitch.click();
  412. let cells = getCells(picker);
  413. let fooCells = filterCells(cells, '.foo');
  414. let barCells = filterCells(cells, '.bar');
  415. expect(fooCells, 'to equal', [cells[1], cells[5], cells[9]]);
  416. expect(barCells, 'to equal', fooCells);
  417. picker.querySelector('.next-btn').click();
  418. cells = getCells(picker);
  419. fooCells = filterCells(cells, '.foo');
  420. barCells = filterCells(cells, '.bar');
  421. expect(fooCells, 'to equal', [cells[3], cells[7], cells[11]]);
  422. expect(barCells, 'to equal', fooCells);
  423. dp.destroy();
  424. });
  425. it('uses custom content to the decade cell when the return contains text/html in the content property', function () {
  426. const beforeShowDecade = (date) => {
  427. const dec = date.getFullYear() / 10;
  428. return (dec + Math.floor(dec / 10) % 10) % 5 ? undefined : {content: '<strong>X</strong>'};
  429. };
  430. const {dp, picker} = createDP(input, {beforeShowDecade});
  431. const viewSwitch = getViewSwitch(picker);
  432. dp.show();
  433. viewSwitch.click();
  434. viewSwitch.click();
  435. viewSwitch.click();
  436. let cells = getCells(picker);
  437. let ccCells = cells.filter(el => el.children.length > 0);
  438. expect(ccCells, 'to equal', [cells[1], cells[6]]);
  439. ccCells.forEach((cell) => {
  440. expect(cell.innerHTML, 'to be', '<strong>X</strong>');
  441. });
  442. picker.querySelector('.next-btn').click();
  443. cells = getCells(picker);
  444. ccCells = cells.filter(el => el.children.length > 0);
  445. expect(ccCells, 'to equal', [cells[5], cells[10]]);
  446. ccCells.forEach((cell) => {
  447. expect(cell.innerHTML, 'to be', '<strong>X</strong>');
  448. });
  449. dp.destroy();
  450. });
  451. it('can be updated with setOptions()', function () {
  452. const {dp, picker} = createDP(input);
  453. const viewSwitch = getViewSwitch(picker);
  454. dp.setOptions({beforeShowDecade: date => !!((date.getFullYear() / 10) % 4)});
  455. dp.show();
  456. viewSwitch.click();
  457. viewSwitch.click();
  458. viewSwitch.click();
  459. let cells = getCells(picker);
  460. let disabledCells = filterCells(cells, '.disabled');
  461. expect(disabledCells, 'to equal', [cells[1], cells[5], cells[9]]);
  462. dp.hide();
  463. dp.setOptions({beforeShowDecade: null});
  464. dp.show();
  465. viewSwitch.click();
  466. viewSwitch.click();
  467. viewSwitch.click();
  468. cells = getCells(picker);
  469. disabledCells = filterCells(cells, '.disabled');
  470. expect(disabledCells, 'to equal', []);
  471. dp.destroy();
  472. });
  473. });
  474. });