DateRangePicker.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. describe('DateRangePicker', function () {
  2. let clock;
  3. let elem;
  4. let input0;
  5. let input1;
  6. before(function () {
  7. clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
  8. });
  9. after(function () {
  10. clock.restore();
  11. });
  12. beforeEach(function () {
  13. elem = domUtils.parseHTML('<div><input><input></div>').firstChild;
  14. [input0, input1] = elem.children;
  15. testContainer.appendChild(elem);
  16. });
  17. afterEach(function () {
  18. testContainer.removeChild(elem);
  19. });
  20. it('input elements\' values are used for the initial dates', function () {
  21. input0.value = '04/20/2020';
  22. input1.value = '04/22/2020';
  23. const drp = new DateRangePicker(elem);
  24. expect(drp.dates, 'to equal', [dateValue(2020, 3, 20), dateValue(2020, 3, 22)]);
  25. drp.destroy();
  26. input0.value = '';
  27. input1.value = '';
  28. });
  29. it('the pickers are hidden at start', function () {
  30. const {drp, picker0, picker1} = createDRP(elem);
  31. expect(isVisible(picker0), 'to be false');
  32. expect(isVisible(picker1), 'to be false');
  33. drp.destroy();
  34. });
  35. it('the pickers becomes visible when the input element get focus and invisivle when losing focus', function () {
  36. const {drp, picker0, picker1} = createDRP(elem);
  37. input0.focus();
  38. expect(isVisible(picker0), 'to be true');
  39. simulant.fire(input0, 'keydown', {key: 'Tab'});
  40. expect(isVisible(picker0), 'to be false');
  41. input1.focus();
  42. expect(isVisible(picker1), 'to be true');
  43. simulant.fire(input1, 'keydown', {key: 'Tab'});
  44. expect(isVisible(picker1), 'to be false');
  45. drp.destroy();
  46. });
  47. it('indicates the range with hilighting the start/end in the pickers', function () {
  48. input0.value = '04/20/2020';
  49. input1.value = '04/22/2020';
  50. const partsClasses = ['.view-switch', '.prev-btn', '.next-btn'];
  51. let {drp, picker0, picker1} = createDRP(elem);
  52. let [viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses);
  53. let [viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses);
  54. input0.focus();
  55. let cells = getCells(picker0);
  56. expect(viewSwitch0.textContent, 'to be', 'April 2020');
  57. expect(getCellIndices(cells, '.selected'), 'to equal', [22]);
  58. expect(getCellIndices(cells, '.range-start'), 'to equal', [22]);
  59. expect(getCellIndices(cells, '.range-end'), 'to equal', [24]);
  60. expect(getCellIndices(cells, '.range'), 'to equal', [23]);
  61. expect(getCellIndices(cells, '.focused'), 'to equal', [22]);
  62. input1.focus();
  63. cells = getCells(picker1);
  64. expect(viewSwitch1.textContent, 'to be', 'April 2020');
  65. expect(getCellIndices(cells, '.selected'), 'to equal', [24]);
  66. expect(getCellIndices(cells, '.range-start'), 'to equal', [22]);
  67. expect(getCellIndices(cells, '.range-end'), 'to equal', [24]);
  68. expect(getCellIndices(cells, '.range'), 'to equal', [23]);
  69. expect(getCellIndices(cells, '.focused'), 'to equal', [24]);
  70. drp.destroy();
  71. // range over months (days → months views)
  72. input0.value = '02/26/2020';
  73. input1.value = '04/12/2020';
  74. ({drp, picker0, picker1} = createDRP(elem));
  75. ([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
  76. ([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
  77. // range-start
  78. input0.focus();
  79. cells = getCells(picker0);
  80. expect(viewSwitch0.textContent, 'to be', 'February 2020');
  81. expect(getCellIndices(cells, '.selected'), 'to equal', [31]);
  82. expect(getCellIndices(cells, '.range-start'), 'to equal', [31]);
  83. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  84. expect(getCellIndices(cells, '.range'), 'to equal', [32, 33, 34, 35, 36, 37, 38, 39, 40, 41]);
  85. expect(getCellIndices(cells, '.focused'), 'to equal', [31]);
  86. prevBtn0.click();
  87. cells = getCells(picker0);
  88. expect(viewSwitch0.textContent, 'to be', 'January 2020');
  89. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  90. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  91. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  92. expect(getCellIndices(cells, '.range'), 'to equal', []);
  93. expect(getCellIndices(cells, '.focused'), 'to equal', [28]);
  94. nextBtn0.click();
  95. nextBtn0.click();
  96. cells = getCells(picker0);
  97. expect(viewSwitch0.textContent, 'to be', 'March 2020');
  98. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  99. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  100. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  101. expect(getCellIndices(cells, '.range').length, 'to be', 42);
  102. expect(getCellIndices(cells, '.focused'), 'to equal', [25]);
  103. nextBtn0.click();
  104. cells = getCells(picker0);
  105. expect(viewSwitch0.textContent, 'to be', 'April 2020');
  106. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  107. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  108. expect(getCellIndices(cells, '.range-end'), 'to equal', [14]);
  109. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
  110. expect(getCellIndices(cells, '.focused'), 'to equal', [28]);
  111. viewSwitch0.click();
  112. cells = getCells(picker0);
  113. expect(viewSwitch0.textContent, 'to be', '2020');
  114. expect(getCellIndices(cells, '.selected'), 'to equal', [1]);
  115. expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
  116. expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
  117. expect(getCellIndices(cells, '.range'), 'to equal', [2]);
  118. expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
  119. // range-end
  120. input1.focus();
  121. cells = getCells(picker1);
  122. expect(viewSwitch1.textContent, 'to be', 'April 2020');
  123. expect(getCellIndices(cells, '.selected'), 'to equal', [14]);
  124. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  125. expect(getCellIndices(cells, '.range-end'), 'to equal', [14]);
  126. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
  127. expect(getCellIndices(cells, '.focused'), 'to equal', [14]);
  128. nextBtn1.click();
  129. cells = getCells(picker1);
  130. expect(viewSwitch1.textContent, 'to be', 'May 2020');
  131. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  132. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  133. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  134. expect(getCellIndices(cells, '.range'), 'to equal', []);
  135. expect(getCellIndices(cells, '.focused'), 'to equal', [16]);
  136. prevBtn1.click();
  137. prevBtn1.click();
  138. cells = getCells(picker1);
  139. expect(viewSwitch1.textContent, 'to be', 'March 2020');
  140. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  141. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  142. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  143. expect(getCellIndices(cells, '.range').length, 'to be', 42);
  144. expect(getCellIndices(cells, '.focused'), 'to equal', [11]);
  145. prevBtn1.click();
  146. cells = getCells(picker1);
  147. expect(viewSwitch1.textContent, 'to be', 'February 2020');
  148. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  149. expect(getCellIndices(cells, '.range-start'), 'to equal', [31]);
  150. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  151. expect(getCellIndices(cells, '.range'), 'to equal', [32, 33, 34, 35, 36, 37, 38, 39, 40, 41]);
  152. expect(getCellIndices(cells, '.focused'), 'to equal', [17]);
  153. viewSwitch1.click();
  154. cells = getCells(picker1);
  155. expect(viewSwitch0.textContent, 'to be', '2020');
  156. expect(getCellIndices(cells, '.selected'), 'to equal', [3]);
  157. expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
  158. expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
  159. expect(getCellIndices(cells, '.range'), 'to equal', [2]);
  160. expect(getCellIndices(cells, '.focused'), 'to equal', [1]);
  161. drp.destroy();
  162. // range over years (months → years views)
  163. input0.value = '10/01/2020';
  164. input1.value = '03/31/2023';
  165. ({drp, picker0, picker1} = createDRP(elem));
  166. ([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
  167. ([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
  168. // range-start
  169. input0.focus();
  170. viewSwitch0.click();
  171. cells = getCells(picker0);
  172. expect(viewSwitch0.textContent, 'to be', '2020');
  173. expect(getCellIndices(cells, '.selected'), 'to equal', [9]);
  174. expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
  175. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  176. expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
  177. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  178. prevBtn0.click();
  179. cells = getCells(picker0);
  180. expect(viewSwitch0.textContent, 'to be', '2019');
  181. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  182. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  183. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  184. expect(getCellIndices(cells, '.range'), 'to equal', []);
  185. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  186. nextBtn0.click();
  187. nextBtn0.click();
  188. cells = getCells(picker0);
  189. expect(viewSwitch0.textContent, 'to be', '2021');
  190. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  191. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  192. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  193. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  194. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  195. nextBtn0.click();
  196. nextBtn0.click();
  197. cells = getCells(picker0);
  198. expect(viewSwitch0.textContent, 'to be', '2023');
  199. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  200. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  201. expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
  202. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
  203. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  204. viewSwitch0.click();
  205. cells = getCells(picker0);
  206. expect(viewSwitch0.textContent, 'to be', '2020-2029');
  207. expect(getCellIndices(cells, '.selected'), 'to equal', [1]);
  208. expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
  209. expect(getCellIndices(cells, '.range-end'), 'to equal', [4]);
  210. expect(getCellIndices(cells, '.range'), 'to equal', [2, 3]);
  211. expect(getCellIndices(cells, '.focused'), 'to equal', [4]);
  212. // range-end
  213. input1.focus();
  214. viewSwitch1.click();
  215. cells = getCells(picker1);
  216. expect(viewSwitch1.textContent, 'to be', '2023');
  217. expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
  218. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  219. expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
  220. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
  221. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  222. nextBtn1.click();
  223. cells = getCells(picker1);
  224. expect(viewSwitch1.textContent, 'to be', '2024');
  225. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  226. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  227. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  228. expect(getCellIndices(cells, '.range'), 'to equal', []);
  229. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  230. prevBtn1.click();
  231. prevBtn1.click();
  232. cells = getCells(picker1);
  233. expect(viewSwitch1.textContent, 'to be', '2022');
  234. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  235. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  236. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  237. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  238. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  239. prevBtn1.click();
  240. prevBtn1.click();
  241. cells = getCells(picker1);
  242. expect(viewSwitch1.textContent, 'to be', '2020');
  243. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  244. expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
  245. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  246. expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
  247. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  248. viewSwitch1.click();
  249. cells = getCells(picker1);
  250. expect(viewSwitch1.textContent, 'to be', '2020-2029');
  251. expect(getCellIndices(cells, '.selected'), 'to equal', [4]);
  252. expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
  253. expect(getCellIndices(cells, '.range-end'), 'to equal', [4]);
  254. expect(getCellIndices(cells, '.range'), 'to equal', [2, 3]);
  255. expect(getCellIndices(cells, '.focused'), 'to equal', [1]);
  256. drp.destroy();
  257. // range over decades (years → decades views)
  258. input0.value = '01/01/2017';
  259. input1.value = '12/31/2041';
  260. ({drp, picker0, picker1} = createDRP(elem));
  261. ([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
  262. ([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
  263. // range-start
  264. input0.focus();
  265. viewSwitch0.click();
  266. viewSwitch0.click();
  267. cells = getCells(picker0);
  268. expect(viewSwitch0.textContent, 'to be', '2010-2019');
  269. expect(getCellIndices(cells, '.selected'), 'to equal', [8]);
  270. expect(getCellIndices(cells, '.range-start'), 'to equal', [8]);
  271. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  272. expect(getCellIndices(cells, '.range'), 'to equal', [9, 10, 11]);
  273. expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
  274. prevBtn0.click();
  275. cells = getCells(picker0);
  276. expect(viewSwitch0.textContent, 'to be', '2000-2009');
  277. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  278. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  279. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  280. expect(getCellIndices(cells, '.range'), 'to equal', []);
  281. expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
  282. nextBtn0.click();
  283. nextBtn0.click();
  284. cells = getCells(picker0);
  285. expect(viewSwitch0.textContent, 'to be', '2020-2029');
  286. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  287. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  288. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  289. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  290. expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
  291. nextBtn0.click();
  292. nextBtn0.click();
  293. cells = getCells(picker0);
  294. expect(viewSwitch0.textContent, 'to be', '2040-2049');
  295. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  296. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  297. expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
  298. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
  299. expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
  300. viewSwitch0.click();
  301. cells = getCells(picker0);
  302. expect(viewSwitch0.textContent, 'to be', '2000-2090');
  303. expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
  304. expect(getCellIndices(cells, '.range-start'), 'to equal', [2]);
  305. expect(getCellIndices(cells, '.range-end'), 'to equal', [5]);
  306. expect(getCellIndices(cells, '.range'), 'to equal', [3, 4]);
  307. expect(getCellIndices(cells, '.focused'), 'to equal', [5]);
  308. // range-end
  309. input1.focus();
  310. viewSwitch1.click();
  311. viewSwitch1.click();
  312. cells = getCells(picker1);
  313. expect(viewSwitch1.textContent, 'to be', '2040-2049');
  314. expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
  315. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  316. expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
  317. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
  318. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  319. nextBtn1.click();
  320. cells = getCells(picker1);
  321. expect(viewSwitch1.textContent, 'to be', '2050-2059');
  322. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  323. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  324. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  325. expect(getCellIndices(cells, '.range'), 'to equal', []);
  326. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  327. prevBtn1.click();
  328. prevBtn1.click();
  329. cells = getCells(picker1);
  330. expect(viewSwitch1.textContent, 'to be', '2030-2039');
  331. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  332. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  333. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  334. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  335. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  336. prevBtn1.click();
  337. prevBtn1.click();
  338. cells = getCells(picker1);
  339. expect(viewSwitch1.textContent, 'to be', '2010-2019');
  340. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  341. expect(getCellIndices(cells, '.range-start'), 'to equal', [8]);
  342. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  343. expect(getCellIndices(cells, '.range'), 'to equal', [9, 10, 11]);
  344. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  345. viewSwitch1.click();
  346. cells = getCells(picker1);
  347. expect(viewSwitch1.textContent, 'to be', '2000-2090');
  348. expect(getCellIndices(cells, '.selected'), 'to equal', [5]);
  349. expect(getCellIndices(cells, '.range-start'), 'to equal', [2]);
  350. expect(getCellIndices(cells, '.range-end'), 'to equal', [5]);
  351. expect(getCellIndices(cells, '.range'), 'to equal', [3, 4]);
  352. expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
  353. drp.destroy();
  354. // range over centures (decades views)
  355. input0.value = '01/22/1984';
  356. input1.value = '12/31/2121';
  357. ({drp, picker0, picker1} = createDRP(elem));
  358. ([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
  359. ([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
  360. // range-start
  361. input0.focus();
  362. viewSwitch0.click();
  363. viewSwitch0.click();
  364. viewSwitch0.click();
  365. cells = getCells(picker0);
  366. expect(viewSwitch0.textContent, 'to be', '1900-1990');
  367. expect(getCellIndices(cells, '.selected'), 'to equal', [9]);
  368. expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
  369. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  370. expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
  371. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  372. prevBtn0.click();
  373. cells = getCells(picker0);
  374. expect(viewSwitch0.textContent, 'to be', '1800-1890');
  375. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  376. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  377. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  378. expect(getCellIndices(cells, '.range'), 'to equal', []);
  379. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  380. nextBtn0.click();
  381. nextBtn0.click();
  382. cells = getCells(picker0);
  383. expect(viewSwitch0.textContent, 'to be', '2000-2090');
  384. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  385. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  386. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  387. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  388. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  389. nextBtn0.click();
  390. cells = getCells(picker0);
  391. expect(viewSwitch0.textContent, 'to be', '2100-2190');
  392. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  393. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  394. expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
  395. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2]);
  396. expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
  397. // range-end
  398. input1.focus();
  399. viewSwitch1.click();
  400. viewSwitch1.click();
  401. viewSwitch1.click();
  402. cells = getCells(picker1);
  403. expect(viewSwitch1.textContent, 'to be', '2100-2190');
  404. expect(getCellIndices(cells, '.selected'), 'to equal', [3]);
  405. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  406. expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
  407. expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2]);
  408. expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
  409. nextBtn1.click();
  410. cells = getCells(picker1);
  411. expect(viewSwitch1.textContent, 'to be', '2200-2290');
  412. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  413. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  414. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  415. expect(getCellIndices(cells, '.range'), 'to equal', []);
  416. expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
  417. prevBtn1.click();
  418. prevBtn1.click();
  419. cells = getCells(picker1);
  420. expect(viewSwitch1.textContent, 'to be', '2000-2090');
  421. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  422. expect(getCellIndices(cells, '.range-start'), 'to equal', []);
  423. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  424. expect(getCellIndices(cells, '.range').length, 'to be', 12);
  425. expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
  426. prevBtn1.click();
  427. cells = getCells(picker1);
  428. expect(viewSwitch1.textContent, 'to be', '1900-1990');
  429. expect(getCellIndices(cells, '.selected'), 'to equal', []);
  430. expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
  431. expect(getCellIndices(cells, '.range-end'), 'to equal', []);
  432. expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
  433. expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
  434. drp.destroy();
  435. });
  436. });