@ohos-ports/flowbite-datepicker 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +73 -0
  3. package/.stylelintrc +12 -0
  4. package/CHANGELOG.md +72 -0
  5. package/LICENSE +21 -0
  6. package/README.md +71 -0
  7. package/demo/index.html +582 -0
  8. package/demo/live-demo.js +471 -0
  9. package/dist/DateRangePicker.cjs.js +2996 -0
  10. package/dist/DateRangePicker.esm.js +2994 -0
  11. package/dist/DateRangePicker.umd.js +3002 -0
  12. package/dist/Datepicker.cjs.js +2778 -0
  13. package/dist/Datepicker.esm.js +2776 -0
  14. package/dist/Datepicker.umd.js +2784 -0
  15. package/dist/css/datepicker-bs4.css +276 -0
  16. package/dist/css/datepicker-bs4.min.css +1 -0
  17. package/dist/css/datepicker-bs5.css +276 -0
  18. package/dist/css/datepicker-bs5.min.css +1 -0
  19. package/dist/css/datepicker-bulma.css +258 -0
  20. package/dist/css/datepicker-bulma.min.css +1 -0
  21. package/dist/css/datepicker-foundation.css +262 -0
  22. package/dist/css/datepicker-foundation.min.css +1 -0
  23. package/dist/css/datepicker.css +306 -0
  24. package/dist/css/datepicker.min.css +1403 -0
  25. package/dist/js/datepicker-full.js +2777 -0
  26. package/dist/js/datepicker-full.min.js +1 -0
  27. package/dist/js/datepicker.js +2569 -0
  28. package/dist/js/datepicker.min.js +1 -0
  29. package/dist/js/locales/ar-tn.js +15 -0
  30. package/dist/js/locales/ar.js +15 -0
  31. package/dist/js/locales/az.js +14 -0
  32. package/dist/js/locales/bg.js +14 -0
  33. package/dist/js/locales/bm.js +18 -0
  34. package/dist/js/locales/bn.js +19 -0
  35. package/dist/js/locales/br.js +18 -0
  36. package/dist/js/locales/bs.js +15 -0
  37. package/dist/js/locales/ca.js +18 -0
  38. package/dist/js/locales/cs.js +19 -0
  39. package/dist/js/locales/cy.js +14 -0
  40. package/dist/js/locales/da.js +19 -0
  41. package/dist/js/locales/de.js +18 -0
  42. package/dist/js/locales/el.js +16 -0
  43. package/dist/js/locales/en-AU.js +18 -0
  44. package/dist/js/locales/en-CA.js +18 -0
  45. package/dist/js/locales/en-GB.js +18 -0
  46. package/dist/js/locales/en-IE.js +17 -0
  47. package/dist/js/locales/en-NZ.js +17 -0
  48. package/dist/js/locales/en-ZA.js +17 -0
  49. package/dist/js/locales/eo.js +17 -0
  50. package/dist/js/locales/es.js +18 -0
  51. package/dist/js/locales/et.js +18 -0
  52. package/dist/js/locales/eu.js +18 -0
  53. package/dist/js/locales/fa.js +17 -0
  54. package/dist/js/locales/fi.js +17 -0
  55. package/dist/js/locales/fo.js +15 -0
  56. package/dist/js/locales/fr-CH.js +21 -0
  57. package/dist/js/locales/fr.js +18 -0
  58. package/dist/js/locales/gl.js +16 -0
  59. package/dist/js/locales/he.js +15 -0
  60. package/dist/js/locales/hi.js +18 -0
  61. package/dist/js/locales/hr.js +13 -0
  62. package/dist/js/locales/hu.js +18 -0
  63. package/dist/js/locales/hy.js +18 -0
  64. package/dist/js/locales/id.js +15 -0
  65. package/dist/js/locales/is.js +14 -0
  66. package/dist/js/locales/it-CH.js +20 -0
  67. package/dist/js/locales/it.js +18 -0
  68. package/dist/js/locales/ja.js +17 -0
  69. package/dist/js/locales/ka.js +17 -0
  70. package/dist/js/locales/kk.js +15 -0
  71. package/dist/js/locales/km.js +15 -0
  72. package/dist/js/locales/ko.js +18 -0
  73. package/dist/js/locales/lt.js +19 -0
  74. package/dist/js/locales/lv.js +18 -0
  75. package/dist/js/locales/me.js +17 -0
  76. package/dist/js/locales/mk.js +15 -0
  77. package/dist/js/locales/mn.js +17 -0
  78. package/dist/js/locales/mr.js +18 -0
  79. package/dist/js/locales/ms.js +15 -0
  80. package/dist/js/locales/nl-BE.js +18 -0
  81. package/dist/js/locales/nl.js +18 -0
  82. package/dist/js/locales/no.js +18 -0
  83. package/dist/js/locales/oc.js +17 -0
  84. package/dist/js/locales/pl.js +17 -0
  85. package/dist/js/locales/pt-BR.js +17 -0
  86. package/dist/js/locales/pt.js +18 -0
  87. package/dist/js/locales/ro.js +17 -0
  88. package/dist/js/locales/ru.js +18 -0
  89. package/dist/js/locales/si.js +18 -0
  90. package/dist/js/locales/sk.js +18 -0
  91. package/dist/js/locales/sl.js +15 -0
  92. package/dist/js/locales/sq.js +18 -0
  93. package/dist/js/locales/sr-latn.js +16 -0
  94. package/dist/js/locales/sr.js +16 -0
  95. package/dist/js/locales/sv.js +17 -0
  96. package/dist/js/locales/sw.js +15 -0
  97. package/dist/js/locales/ta.js +18 -0
  98. package/dist/js/locales/tg.js +19 -0
  99. package/dist/js/locales/th.js +14 -0
  100. package/dist/js/locales/tk.js +18 -0
  101. package/dist/js/locales/tr.js +17 -0
  102. package/dist/js/locales/uk.js +17 -0
  103. package/dist/js/locales/uz-cyrl.js +18 -0
  104. package/dist/js/locales/uz-latn.js +18 -0
  105. package/dist/js/locales/vi.js +16 -0
  106. package/dist/js/locales/zh-CN.js +19 -0
  107. package/dist/js/locales/zh-TW.js +18 -0
  108. package/dist/locales/index.cjs.js +1028 -0
  109. package/dist/locales/index.esm.js +1028 -0
  110. package/dist/main.cjs.js +2999 -0
  111. package/dist/main.esm.js +2994 -0
  112. package/dist/main.umd.js +3005 -0
  113. package/docs/.nojekyll +0 -0
  114. package/docs/README.md +266 -0
  115. package/docs/_sidebar.md +6 -0
  116. package/docs/api.md +284 -0
  117. package/docs/date-string+format.md +90 -0
  118. package/docs/i18n.md +99 -0
  119. package/docs/images/datepicker-inline.jpg +0 -0
  120. package/docs/images/datepicker.jpg +0 -0
  121. package/docs/images/multidate.jpg +0 -0
  122. package/docs/images/picker-structure.jpg +0 -0
  123. package/docs/images/rangepicker.jpg +0 -0
  124. package/docs/images/view-days.jpg +0 -0
  125. package/docs/images/view-decades.jpg +0 -0
  126. package/docs/images/view-months.jpg +0 -0
  127. package/docs/images/view-years.jpg +0 -0
  128. package/docs/index.html +26 -0
  129. package/docs/options.md +354 -0
  130. package/docs/overview.md +174 -0
  131. package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
  132. package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
  133. package/js/DateRangePicker.js +210 -0
  134. package/js/Datepicker.js +487 -0
  135. package/js/datepicker-full.js +5 -0
  136. package/js/events/functions.js +48 -0
  137. package/js/events/inputFieldListeners.js +206 -0
  138. package/js/events/otherListeners.js +15 -0
  139. package/js/events/pickerListeners.js +70 -0
  140. package/js/i18n/base-locales.js +13 -0
  141. package/js/i18n/locales/ar-tn.js +15 -0
  142. package/js/i18n/locales/ar.js +15 -0
  143. package/js/i18n/locales/az.js +14 -0
  144. package/js/i18n/locales/bg.js +14 -0
  145. package/js/i18n/locales/bm.js +18 -0
  146. package/js/i18n/locales/bn.js +19 -0
  147. package/js/i18n/locales/br.js +18 -0
  148. package/js/i18n/locales/bs.js +15 -0
  149. package/js/i18n/locales/ca.js +18 -0
  150. package/js/i18n/locales/cs.js +19 -0
  151. package/js/i18n/locales/cy.js +14 -0
  152. package/js/i18n/locales/da.js +19 -0
  153. package/js/i18n/locales/de.js +18 -0
  154. package/js/i18n/locales/el.js +16 -0
  155. package/js/i18n/locales/en-AU.js +18 -0
  156. package/js/i18n/locales/en-CA.js +18 -0
  157. package/js/i18n/locales/en-GB.js +18 -0
  158. package/js/i18n/locales/en-IE.js +17 -0
  159. package/js/i18n/locales/en-NZ.js +17 -0
  160. package/js/i18n/locales/en-ZA.js +17 -0
  161. package/js/i18n/locales/eo.js +17 -0
  162. package/js/i18n/locales/es.js +18 -0
  163. package/js/i18n/locales/et.js +18 -0
  164. package/js/i18n/locales/eu.js +18 -0
  165. package/js/i18n/locales/fa.js +17 -0
  166. package/js/i18n/locales/fi.js +17 -0
  167. package/js/i18n/locales/fo.js +15 -0
  168. package/js/i18n/locales/fr-CH.js +21 -0
  169. package/js/i18n/locales/fr.js +18 -0
  170. package/js/i18n/locales/gl.js +16 -0
  171. package/js/i18n/locales/he.js +15 -0
  172. package/js/i18n/locales/hi.js +18 -0
  173. package/js/i18n/locales/hr.js +13 -0
  174. package/js/i18n/locales/hu.js +18 -0
  175. package/js/i18n/locales/hy.js +18 -0
  176. package/js/i18n/locales/id.js +15 -0
  177. package/js/i18n/locales/is.js +14 -0
  178. package/js/i18n/locales/it-CH.js +20 -0
  179. package/js/i18n/locales/it.js +18 -0
  180. package/js/i18n/locales/ja.js +17 -0
  181. package/js/i18n/locales/ka.js +17 -0
  182. package/js/i18n/locales/kk.js +15 -0
  183. package/js/i18n/locales/km.js +15 -0
  184. package/js/i18n/locales/ko.js +18 -0
  185. package/js/i18n/locales/lt.js +19 -0
  186. package/js/i18n/locales/lv.js +18 -0
  187. package/js/i18n/locales/me.js +17 -0
  188. package/js/i18n/locales/mk.js +15 -0
  189. package/js/i18n/locales/mn.js +17 -0
  190. package/js/i18n/locales/mr.js +18 -0
  191. package/js/i18n/locales/ms.js +15 -0
  192. package/js/i18n/locales/nl-BE.js +18 -0
  193. package/js/i18n/locales/nl.js +18 -0
  194. package/js/i18n/locales/no.js +18 -0
  195. package/js/i18n/locales/oc.js +17 -0
  196. package/js/i18n/locales/pl.js +17 -0
  197. package/js/i18n/locales/pt-BR.js +17 -0
  198. package/js/i18n/locales/pt.js +18 -0
  199. package/js/i18n/locales/ro.js +17 -0
  200. package/js/i18n/locales/ru.js +18 -0
  201. package/js/i18n/locales/si.js +18 -0
  202. package/js/i18n/locales/sk.js +18 -0
  203. package/js/i18n/locales/sl.js +15 -0
  204. package/js/i18n/locales/sq.js +18 -0
  205. package/js/i18n/locales/sr-latn.js +16 -0
  206. package/js/i18n/locales/sr.js +16 -0
  207. package/js/i18n/locales/sv.js +17 -0
  208. package/js/i18n/locales/sw.js +15 -0
  209. package/js/i18n/locales/ta.js +18 -0
  210. package/js/i18n/locales/tg.js +19 -0
  211. package/js/i18n/locales/th.js +14 -0
  212. package/js/i18n/locales/tk.js +18 -0
  213. package/js/i18n/locales/tr.js +17 -0
  214. package/js/i18n/locales/uk.js +17 -0
  215. package/js/i18n/locales/uz-cyrl.js +18 -0
  216. package/js/i18n/locales/uz-latn.js +18 -0
  217. package/js/i18n/locales/vi.js +16 -0
  218. package/js/i18n/locales/zh-CN.js +19 -0
  219. package/js/i18n/locales/zh-TW.js +18 -0
  220. package/js/lib/date-format.js +185 -0
  221. package/js/lib/date.js +82 -0
  222. package/js/lib/dom.js +55 -0
  223. package/js/lib/event.js +68 -0
  224. package/js/lib/utils.js +61 -0
  225. package/js/main.js +4 -0
  226. package/js/options/defaultOptions.js +38 -0
  227. package/js/options/processOptions.js +263 -0
  228. package/js/picker/Picker.js +334 -0
  229. package/js/picker/templates/calendarWeeksTemplate.js +8 -0
  230. package/js/picker/templates/daysTemplate.js +8 -0
  231. package/js/picker/templates/pickerTemplate.js +23 -0
  232. package/js/picker/views/DaysView.js +250 -0
  233. package/js/picker/views/MonthsView.js +198 -0
  234. package/js/picker/views/View.js +55 -0
  235. package/js/picker/views/YearsView.js +170 -0
  236. package/package.json +81 -0
  237. package/postcss.config.js +5 -0
  238. package/rollup.config.js +75 -0
  239. package/sass/_mixins.scss +12 -0
  240. package/sass/datepicker-bs4.scss +91 -0
  241. package/sass/datepicker-bs5.scss +91 -0
  242. package/sass/datepicker-bulma.scss +69 -0
  243. package/sass/datepicker-foundation.scss +66 -0
  244. package/sass/datepicker.scss +436 -0
  245. package/sass/index-bs4.scss +5 -0
  246. package/sass/index-bs5.scss +5 -0
  247. package/sass/index-bulma.scss +6 -0
  248. package/sass/index-foundation.scss +3 -0
  249. package/scripts/build-css.js +39 -0
  250. package/scripts/build-locales.js +57 -0
  251. package/scripts/convert-bsdp-locales.js +65 -0
  252. package/scripts/minify-css.js +31 -0
  253. package/scripts/minify-js.js +17 -0
  254. package/style.css +10 -0
  255. package/tailwind.config.js +16 -0
  256. package/tailwind.css +1389 -0
  257. package/test/DateRangePicker/DateRangePicker.js +547 -0
  258. package/test/DateRangePicker/api-methods.js +415 -0
  259. package/test/DateRangePicker/date-selection.js +472 -0
  260. package/test/DateRangePicker/options.js +308 -0
  261. package/test/Datepicker/Datepicker-object.js +236 -0
  262. package/test/Datepicker/api-methods.js +328 -0
  263. package/test/_utils/date.js +102 -0
  264. package/test/_utils/dom.js +70 -0
  265. package/test/events.js +785 -0
  266. package/test/inline-mode.js +45 -0
  267. package/test/keyboard-operation/arrow-down.js +293 -0
  268. package/test/keyboard-operation/arrow-left.js +255 -0
  269. package/test/keyboard-operation/arrow-right.js +215 -0
  270. package/test/keyboard-operation/arrow-up.js +461 -0
  271. package/test/keyboard-operation/edit-mode.js +458 -0
  272. package/test/keyboard-operation/keyboard-operation.js +146 -0
  273. package/test/mouse-operation.js +580 -0
  274. package/test/options/before-show.js +635 -0
  275. package/test/options/bulma-datepicker.sublime-workspace +1280 -0
  276. package/test/options/buttons.js +383 -0
  277. package/test/options/date-restrictions.js +802 -0
  278. package/test/options/format.js +281 -0
  279. package/test/options/multidate.js +380 -0
  280. package/test/options/options.js +727 -0
  281. package/test/options/orientation.js +410 -0
  282. package/test/options/pick-levle+view.js +357 -0
  283. package/test/test.html +94 -0
  284. package/test/unit/DateRangePicker.js +192 -0
  285. package/test/unit/Datepicker.js +307 -0
  286. package/test/unit/_setup.js +28 -0
  287. package/test/unit/lib/date-format.js +310 -0
  288. package/test/unit/lib/date.js +211 -0
  289. package/test/unit/lib/dom.js +142 -0
  290. package/test/unit/lib/event.js +207 -0
  291. package/test/unit/lib/utils.js +135 -0
@@ -0,0 +1,357 @@
1
+ describe('options - pick level & view', function () {
2
+ let clock;
3
+ let input;
4
+
5
+ beforeEach(function () {
6
+ clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
7
+ input = document.createElement('input');
8
+ testContainer.appendChild(input);
9
+ });
10
+
11
+ afterEach(function () {
12
+ testContainer.removeChild(input);
13
+ clock.restore();
14
+ });
15
+
16
+ describe('pickLevel', function () {
17
+ it('limits the minimum of available views', function () {
18
+ const {dp, picker} = createDP(input, {pickLevel: 2});
19
+ const viewSwitch = getViewSwitch(picker);
20
+ const cells1 = getCells(picker)[1];
21
+ dp.show();
22
+
23
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
24
+ expect(cells1.textContent, 'to be', '2020');
25
+
26
+ cells1.click();
27
+
28
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
29
+ expect(getCells(picker)[1].textContent, 'to be', '2020');
30
+
31
+ dp.destroy();
32
+ });
33
+
34
+ it('changes the selection level to month when 1', function () {
35
+ input.value = '2/14/2020';
36
+
37
+ const {dp, picker} = createDP(input, {pickLevel: 1});
38
+ const [viewSwitch, nextBtn] = getParts(picker, ['.view-switch', '.next-btn']);
39
+ let cells = getCells(picker);
40
+ dp.show();
41
+
42
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 1)]);
43
+ expect(input.value, 'to be', '02/01/2020');
44
+ expect(viewSwitch.textContent, 'to be', '2020');
45
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[1]]);
46
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
47
+
48
+ // mouse operation
49
+ cells[0].click();
50
+
51
+ cells = getCells(picker);
52
+ expect(dp.dates, 'to equal', [dateValue(2020, 0, 1)]);
53
+ expect(input.value, 'to be', '01/01/2020');
54
+ expect(viewSwitch.textContent, 'to be', '2020');
55
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[0]]);
56
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[0]]);
57
+
58
+ nextBtn.click();
59
+ getCells(picker)[7].click();
60
+
61
+ cells = getCells(picker);
62
+ expect(dp.dates, 'to equal', [dateValue(2021, 7, 1)]);
63
+ expect(input.value, 'to be', '08/01/2021');
64
+ expect(viewSwitch.textContent, 'to be', '2021');
65
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[7]]);
66
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[7]]);
67
+
68
+ // keyboard operation
69
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
70
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
71
+ simulant.fire(input, 'keydown', {key: 'Enter'});
72
+
73
+ cells = getCells(picker);
74
+ expect(dp.dates, 'to equal', [dateValue(2020, 6, 1)]);
75
+ expect(input.value, 'to be', '07/01/2020');
76
+ expect(viewSwitch.textContent, 'to be', '2020');
77
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[6]]);
78
+
79
+ dp.enterEditMode();
80
+ input.value = '4/20/2021';
81
+ simulant.fire(input, 'keydown', {key: 'Enter'});
82
+
83
+ cells = getCells(picker);
84
+ expect(dp.dates, 'to equal', [dateValue(2021, 3, 1)]);
85
+ expect(input.value, 'to be', '04/01/2021');
86
+ expect(viewSwitch.textContent, 'to be', '2021');
87
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[3]]);
88
+
89
+ // api call
90
+ viewSwitch.click();
91
+
92
+ dp.setDate('2/14/2022');
93
+
94
+ cells = getCells(picker);
95
+ expect(dp.dates, 'to equal', [dateValue(2022, 1, 1)]);
96
+ expect(input.value, 'to be', '02/01/2022');
97
+ expect(viewSwitch.textContent, 'to be', '2022');
98
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[1]]);
99
+
100
+ viewSwitch.click();
101
+ dp.hide();
102
+
103
+ input.value = '3/14/2020';
104
+ dp.update();
105
+ dp.show();
106
+
107
+ cells = getCells(picker);
108
+ expect(dp.dates, 'to equal', [dateValue(2020, 2, 1)]);
109
+ expect(input.value, 'to be', '03/01/2020');
110
+ expect(viewSwitch.textContent, 'to be', '2020');
111
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[2]]);
112
+
113
+ dp.destroy();
114
+ });
115
+
116
+ it('changes the selection level to year when 2', function () {
117
+ input.value = '2/14/2020';
118
+
119
+ const {dp, picker} = createDP(input, {pickLevel: 2});
120
+ const [viewSwitch, nextBtn] = getParts(picker, ['.view-switch', '.next-btn']);
121
+ let cells = getCells(picker);
122
+ dp.show();
123
+
124
+ expect(dp.dates, 'to equal', [dateValue(2020, 0, 1)]);
125
+ expect(input.value, 'to be', '01/01/2020');
126
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
127
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[1]]);
128
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
129
+
130
+ // mouse operation
131
+ cells[2].click();
132
+
133
+ cells = getCells(picker);
134
+ expect(dp.dates, 'to equal', [dateValue(2021, 0, 1)]);
135
+ expect(input.value, 'to be', '01/01/2021');
136
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
137
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[2]]);
138
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[2]]);
139
+
140
+ nextBtn.click();
141
+ getCells(picker)[7].click();
142
+
143
+ cells = getCells(picker);
144
+ expect(dp.dates, 'to equal', [dateValue(2036, 0, 1)]);
145
+ expect(input.value, 'to be', '01/01/2036');
146
+ expect(viewSwitch.textContent, 'to be', '2030-2039');
147
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[7]]);
148
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[7]]);
149
+
150
+ // keyboard operation
151
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
152
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
153
+ simulant.fire(input, 'keydown', {key: 'Enter'});
154
+
155
+ cells = getCells(picker);
156
+ expect(dp.dates, 'to equal', [dateValue(2025, 0, 1)]);
157
+ expect(input.value, 'to be', '01/01/2025');
158
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
159
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[6]]);
160
+
161
+ dp.enterEditMode();
162
+ input.value = '4/20/2021';
163
+ simulant.fire(input, 'keydown', {key: 'Enter'});
164
+
165
+ cells = getCells(picker);
166
+ expect(dp.dates, 'to equal', [dateValue(2021, 0, 1)]);
167
+ expect(input.value, 'to be', '01/01/2021');
168
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
169
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[2]]);
170
+
171
+ // api call
172
+ viewSwitch.click();
173
+
174
+ dp.setDate('2/14/2032');
175
+
176
+ cells = getCells(picker);
177
+ expect(dp.dates, 'to equal', [dateValue(2032, 0, 1)]);
178
+ expect(input.value, 'to be', '01/01/2032');
179
+ expect(viewSwitch.textContent, 'to be', '2030-2039');
180
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[3]]);
181
+
182
+ viewSwitch.click();
183
+ dp.hide();
184
+
185
+ input.value = '3/14/2020';
186
+ dp.update();
187
+ dp.show();
188
+
189
+ cells = getCells(picker);
190
+ expect(dp.dates, 'to equal', [dateValue(2020, 0, 1)]);
191
+ expect(input.value, 'to be', '01/01/2020');
192
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
193
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[1]]);
194
+
195
+ dp.destroy();
196
+ });
197
+
198
+ it('can be updated with setOptions()', function () {
199
+ const {dp, picker} = createDP(input);
200
+ const viewSwitch = getViewSwitch(picker);
201
+ dp.setOptions({pickLevel: 1});
202
+ dp.show();
203
+
204
+ let cells = getCells(picker);
205
+ expect(viewSwitch.textContent, 'to be', '2020');
206
+ expect(cells[1].textContent, 'to be', 'Feb');
207
+
208
+ cells[1].click();
209
+
210
+ cells = getCells(picker);
211
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 1)]);
212
+ expect(input.value, 'to be', '02/01/2020');
213
+ expect(viewSwitch.textContent, 'to be', '2020');
214
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[0]]);
215
+
216
+ dp.setOptions({pickLevel: 0});
217
+
218
+ cells = getCells(picker);
219
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
220
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[6]]);
221
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
222
+
223
+ viewSwitch.click();
224
+ getCells(picker)[3].click();
225
+
226
+ cells = getCells(picker);
227
+ expect(viewSwitch.textContent, 'to be', 'April 2020');
228
+ expect(filterCells(cells, '.selected'), 'to equal', []);
229
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
230
+
231
+ dp.destroy();
232
+ });
233
+ });
234
+
235
+ describe('maxView', function () {
236
+ it('limits the maximum of available views', function () {
237
+ const {dp, picker} = createDP(input, {maxView: 1});
238
+ const viewSwitch = getViewSwitch(picker);
239
+ dp.show();
240
+
241
+ viewSwitch.click();
242
+ viewSwitch.click();
243
+
244
+ expect(viewSwitch.textContent, 'to be', '2020');
245
+ expect(getCells(picker)[0].textContent, 'to be', 'Jan');
246
+
247
+ dp.destroy();
248
+ });
249
+
250
+ it('cannot be smaller than pickLevel', function () {
251
+ const {dp, picker} = createDP(input, {maxView: 1, pickLevel: 2});
252
+ const viewSwitch = getViewSwitch(picker);
253
+ dp.show();
254
+
255
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
256
+ expect(getCells(picker)[1].textContent, 'to be', '2020');
257
+
258
+ viewSwitch.click();
259
+
260
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
261
+ expect(getCells(picker)[1].textContent, 'to be', '2020');
262
+
263
+ dp.destroy();
264
+ });
265
+
266
+ it('can be updated with setOptions()', function () {
267
+ const {dp, picker} = createDP(input);
268
+ const viewSwitch = getViewSwitch(picker);
269
+ dp.setOptions({maxView: 2});
270
+ dp.show();
271
+
272
+ viewSwitch.click();
273
+ viewSwitch.click();
274
+ viewSwitch.click();
275
+
276
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
277
+ expect(getCells(picker)[1].textContent, 'to be', '2020');
278
+
279
+ dp.setOptions({maxView: 0});
280
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
281
+
282
+ viewSwitch.click();
283
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
284
+
285
+ dp.destroy();
286
+ });
287
+ });
288
+
289
+ describe('startView', function () {
290
+ it('specifies the view desplayed on open', function () {
291
+ const {dp, picker} = createDP(input, {startView: 3});
292
+ const viewSwitch = getViewSwitch(picker);
293
+ dp.show();
294
+
295
+ expect(viewSwitch.textContent, 'to be', '2000-2090');
296
+
297
+ let cells = getCells(picker);
298
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
299
+ expect(cells[3].textContent, 'to be', '2020');
300
+
301
+ dp.destroy();
302
+ });
303
+
304
+ it('cannot be smaller than pickLevel', function () {
305
+ const {dp, picker} = createDP(input, {startView: 1, pickLevel: 2});
306
+ const viewSwitch = getViewSwitch(picker);
307
+ dp.show();
308
+
309
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
310
+
311
+ let cells = getCells(picker);
312
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
313
+ expect(cells[1].textContent, 'to be', '2020');
314
+
315
+ dp.destroy();
316
+ });
317
+
318
+ it('cannot be larger than maxView', function () {
319
+ const {dp, picker} = createDP(input, {startView: 3, maxView: 2});
320
+ const viewSwitch = getViewSwitch(picker);
321
+ dp.show();
322
+
323
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
324
+
325
+ let cells = getCells(picker);
326
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
327
+ expect(cells[1].textContent, 'to be', '2020');
328
+
329
+ dp.destroy();
330
+ });
331
+
332
+ it('can be updated with setOptions()', function () {
333
+ const {dp, picker} = createDP(input);
334
+ const viewSwitch = getViewSwitch(picker);
335
+ dp.setOptions({startView: 2});
336
+ dp.show();
337
+
338
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
339
+
340
+ let cells = getCells(picker);
341
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
342
+ expect(cells[1].textContent, 'to be', '2020');
343
+
344
+ dp.hide();
345
+ dp.setOptions({startView: 0});
346
+ dp.show();
347
+
348
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
349
+
350
+ cells = getCells(picker);
351
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
352
+ expect(cells[19].textContent, 'to be', '14');
353
+
354
+ dp.destroy();
355
+ });
356
+ });
357
+ });
package/test/test.html ADDED
@@ -0,0 +1,94 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Mocha Tests</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
8
+ <style type="text/css">
9
+ html * {
10
+ box-sizing: border-box;
11
+ }
12
+ </style>
13
+ <link rel="stylesheet" href="../dist/css/datepicker.css" />
14
+ </head>
15
+ <body>
16
+ <div id="mocha"></div>
17
+
18
+ <div id="test-container"></div>
19
+
20
+ <script src="../node_modules/mocha/mocha.js"></script>
21
+ <script src="../node_modules/unexpected/unexpected.js"></script>
22
+ <script src="../node_modules/sinon/pkg/sinon.js"></script>
23
+ <script src="../node_modules/simulant/dist/simulant.umd.js"></script>
24
+
25
+ <script class="mocha-init">
26
+ mocha.setup('bdd');
27
+ mocha.checkLeaks();
28
+
29
+ window.testContainer = document.getElementById('test-container');
30
+ </script>
31
+ <script src="./_utils/date.js"></script>
32
+ <script src="./_utils/dom.js"></script>
33
+ <script class="setup">
34
+ /* eslint-disable no-undef, no-unused-vars */
35
+ var expect = weknowhow.expect;
36
+ var dateValue = dateUtils.dateValue;
37
+ var parseHTML = domUtils.parseHTML;
38
+ var isVisible = domUtils.isVisible;
39
+ var lastItemOf = arr => arr[arr.length - 1];
40
+
41
+ var createDP = (el, options) => {
42
+ const dp = new Datepicker(el, options);
43
+ return {dp, picker: document.querySelector('.datepicker')};
44
+ };
45
+ var createDRP = (el, options) => {
46
+ const drp = new DateRangePicker(el, options);
47
+ const [picker0, picker1] = document.querySelectorAll('.datepicker');
48
+ return {drp, picker0, picker1};
49
+ };
50
+ var getParts = (picker, selectors) => selectors.map(sel => picker.querySelector(sel));
51
+ var getViewSwitch = picker => picker.querySelector('.view-switch');
52
+ var getCells = picker => Array.from(picker.querySelectorAll('.datepicker-cell'));
53
+ var filterCells = (cells, criteria) => {
54
+ const fn = typeof criteria === 'string' ? el => el.matches(criteria) : criteria;
55
+ return cells.filter(fn);
56
+ };
57
+ var getCellIndices = (cells, criteria) => cells.reduce((indices, cell, idx) => {
58
+ if (cell.matches(criteria)) {
59
+ indices.push(idx);
60
+ }
61
+ return indices;
62
+ }, []);
63
+ </script>
64
+ <script src="../dist/js/datepicker-full.js"></script>
65
+ <script src="../dist/js/locales/fr.js"></script>
66
+ <script src="../dist/js/locales/zh-CN.js"></script>
67
+ <script src="./Datepicker/Datepicker-object.js"></script>
68
+ <script src="./Datepicker/api-methods.js"></script>
69
+ <script src="./mouse-operation.js"></script>
70
+ <script src="./keyboard-operation/keyboard-operation.js"></script>
71
+ <script src="./keyboard-operation/arrow-left.js"></script>
72
+ <script src="./keyboard-operation/arrow-right.js"></script>
73
+ <script src="./keyboard-operation/arrow-up.js"></script>
74
+ <script src="./keyboard-operation/arrow-down.js"></script>
75
+ <script src="./keyboard-operation/edit-mode.js"></script>
76
+ <script src="./events.js"></script>
77
+ <script src="./options/options.js"></script>
78
+ <script src="./options/date-restrictions.js"></script>
79
+ <script src="./options/buttons.js"></script>
80
+ <script src="./options/format.js"></script>
81
+ <script src="./options/multidate.js"></script>
82
+ <script src="./options/pick-levle+view.js"></script>
83
+ <script src="./options/orientation.js"></script>
84
+ <script src="./options/before-show.js"></script>
85
+ <script src="./inline-mode.js"></script>
86
+ <script src="./DateRangePicker/DateRangePicker.js"></script>
87
+ <script src="./DateRangePicker/api-methods.js"></script>
88
+ <script src="./DateRangePicker/date-selection.js"></script>
89
+ <script src="./DateRangePicker/options.js"></script>
90
+ <script class="mocha-exec">
91
+ mocha.run();
92
+ </script>
93
+ </body>
94
+ </html>
@@ -0,0 +1,192 @@
1
+ import './_setup.js';
2
+ import DateRangePicker from '../../js/DateRangePicker.js';
3
+ import {parseHTML} from '../../js/lib/dom.js';
4
+ // to spy constructor with sinon, import entire module
5
+ // @see: https://github.com/sinonjs/sinon/issues/1358#issuecomment-391643741
6
+ import * as DP from '../../js/Datepicker.js';
7
+ const Datepicker = DP.default;
8
+
9
+ describe('DateRangePicker', function () {
10
+ let elem;
11
+ let input0;
12
+ let input1;
13
+
14
+ beforeEach(function () {
15
+ elem = parseHTML('<div><input><input></div>').firstChild;
16
+ [input0, input1] = elem.children;
17
+ testContainer.appendChild(elem);
18
+ });
19
+
20
+ afterEach(function () {
21
+ document.querySelectorAll('.datepicker').forEach((el) => {
22
+ el.parentElement.removeChild(el);
23
+ });
24
+ delete input0.datepicker;
25
+ delete input1.datepicker;
26
+ delete elem.rangepicker;
27
+ testContainer.removeChild(elem);
28
+ });
29
+
30
+ describe('constructor', function () {
31
+ it('attachs the created instance to the bound element', function () {
32
+ const drp = new DateRangePicker(elem);
33
+ expect(elem.rangepicker, 'to be', drp);
34
+ });
35
+
36
+ it('configures the instance with the default values', function () {
37
+ let drp = new DateRangePicker(elem);
38
+ expect(drp.allowOneSidedRange, 'to be false');
39
+ });
40
+
41
+ it('creates datepicker for the inputs passing rangepicker and given options expect', function () {
42
+ const spyDPConstructor = sinon.spy(DP, 'default');
43
+
44
+ let drp = new DateRangePicker(elem);
45
+ expect(spyDPConstructor.args, 'to equal', [
46
+ [input0, {}, drp],
47
+ [input1, {}, drp],
48
+ ]);
49
+ expect(input0.datepicker, 'to be a', Datepicker);
50
+ expect(input1.datepicker, 'to be a', Datepicker);
51
+ expect([input0.datepicker, input1.datepicker], 'to equal', drp.datepickers);
52
+
53
+ spyDPConstructor.resetHistory();
54
+ delete input0.datepicker;
55
+ delete input1.datepicker;
56
+ delete elem.rangepicker;
57
+
58
+ const fakeOptions = {foo: 123, bar: 456};
59
+ drp = new DateRangePicker(elem, fakeOptions);
60
+ expect(spyDPConstructor.args, 'to equal', [
61
+ [input0, fakeOptions, drp],
62
+ [input1, fakeOptions, drp],
63
+ ]);
64
+
65
+ spyDPConstructor.restore();
66
+ });
67
+
68
+ it('makes datepickers property read-only/immutable', function () {
69
+ const drp = new DateRangePicker(elem);
70
+
71
+ expect(() => { drp.datepickers = []; }, 'to throw a', TypeError);
72
+ expect(() => { drp.datepickers[0] = null; }, 'to throw a', TypeError);
73
+ expect(() => { drp.datepickers[2] = {}; }, 'to throw a', TypeError);
74
+ });
75
+
76
+ it('excludes inputs, allowOneSidedRange and maxNumberOfDates from options to pass Datepicker container', function () {
77
+ const spyDPConstructor = sinon.spy(DP, 'default');
78
+ new DateRangePicker(elem, {
79
+ inputs: [input0, input1],
80
+ allowOneSidedRange: false,
81
+ maxNumberOfDates: 2,
82
+ foo: 123,
83
+ });
84
+
85
+ expect(spyDPConstructor.args[0][1], 'to equal', {foo: 123});
86
+
87
+ spyDPConstructor.restore();
88
+ });
89
+
90
+ it('works with arbitrary input elements if they are provided in the inputs option', function () {
91
+ const outsideEl = document.createElement('div');
92
+ const drp = new DateRangePicker(outsideEl, {inputs: [input0, input1]});
93
+
94
+ expect(outsideEl.rangepicker, 'to be', drp);
95
+ expect(input0.datepicker.rangepicker, 'to be', drp);
96
+ expect(input1.datepicker.rangepicker, 'to be', drp);
97
+ expect([input0.datepicker, input1.datepicker], 'to equal', drp.datepickers);
98
+ });
99
+
100
+ it('append datepicker elements to the container)', function () {
101
+ new DateRangePicker(elem);
102
+
103
+ const dpElems = Array.from(document.body.children).filter(el => el.matches('.datepicker'));
104
+ expect(dpElems, 'to have length', 2);
105
+ });
106
+
107
+ it('does not add the active class to the picker elements', function () {
108
+ new DateRangePicker(elem);
109
+
110
+ const dpElems = Array.from(document.querySelectorAll('.datepicker'));
111
+ expect(dpElems.filter(el => el.classList.contains('active')), 'to be empty');
112
+ });
113
+
114
+ it('does nothing but creating an instance if number of inputs < 2', function () {
115
+ elem.removeChild(input1);
116
+
117
+ let drp = new DateRangePicker(elem);
118
+ expect(elem, 'not to have property', 'rangepicker');
119
+ expect(drp, 'not to have properties', ['inputs', 'datepickers']);
120
+ expect(input0, 'not to have property', 'datepicker');
121
+ expect(document.querySelectorAll('.datepicker').length, 'to be', 0);
122
+
123
+ const outsideEl = document.createElement('div');
124
+ drp = new DateRangePicker(outsideEl, {inputs: [input0]});
125
+ expect(outsideEl, 'not to have property', 'rangepicker');
126
+ expect(input0, 'not to have property', 'datepicker');
127
+ expect(document.querySelectorAll('.datepicker').length, 'to be', 0);
128
+ });
129
+ });
130
+
131
+ describe('destroy()', function () {
132
+ let drp;
133
+ let spyDestroy0;
134
+ let spyDestroy1;
135
+
136
+ beforeEach(function () {
137
+ drp = new DateRangePicker(elem);
138
+ spyDestroy0 = sinon.spy(input0.datepicker, 'destroy');
139
+ spyDestroy1 = sinon.spy(input1.datepicker, 'destroy');
140
+ });
141
+
142
+ afterEach(function () {
143
+ spyDestroy0.restore();
144
+ spyDestroy1.restore();
145
+ });
146
+
147
+ it('calls destroy() of each datepickers', function () {
148
+ drp.destroy();
149
+ expect(spyDestroy0.called, 'to be true');
150
+ expect(spyDestroy1.called, 'to be true');
151
+ });
152
+
153
+ it('removes the instance from the bound element', function () {
154
+ drp.destroy();
155
+ expect(Object.prototype.hasOwnProperty.call(elem, 'rangepicker'), 'to be false');
156
+ });
157
+ });
158
+
159
+ describe('dates property', function () {
160
+ it('contains the array of the inputs\' selected dates', function () {
161
+ const drp = new DateRangePicker(elem);
162
+ expect(drp.dates, 'to equal', [undefined, undefined]);
163
+
164
+ const date0 = new Date(2020, 3, 20).setHours(0, 0, 0, 0);
165
+ const date1 = new Date(2020, 3, 22).setHours(0, 0, 0, 0);
166
+ drp.datepickers[0].dates = [date0];
167
+ drp.datepickers[1].dates = [date1];
168
+ expect(drp.dates, 'to equal', [date0, date1]);
169
+ });
170
+ });
171
+
172
+ describe('setOptions()', function () {
173
+ it('updates allowOneSidedRange but ignores inputs if they are in the given options', function () {
174
+ const input2 = document.createElement('input');
175
+ const drp = new DateRangePicker(elem);
176
+
177
+ drp.setOptions({allowOneSidedRange: true, inputs: [input2, input0]});
178
+ expect(drp.allowOneSidedRange, 'to be true');
179
+ expect(drp.inputs, 'to equal', [input0, input1]);
180
+ });
181
+
182
+ it('calls each datepicker\'s setOptions() with given options except inputs, allowOneSidedRange and maxNumberOfDates', function () {
183
+ const drp = new DateRangePicker(elem);
184
+ const stubDP0SetOptions = sinon.stub(drp.datepickers[0], 'setOptions').callsFake(() => {});
185
+ const stubDP1SetOptions = sinon.stub(drp.datepickers[1], 'setOptions').callsFake(() => {});
186
+
187
+ drp.setOptions({inputs: [], allowOneSidedRange: true, maxNumberOfDates: 2, foo: 123, bar: 456});
188
+ expect(stubDP0SetOptions.args, 'to equal', [[{foo: 123, bar: 456}]]);
189
+ expect(stubDP1SetOptions.args, 'to equal', [[{foo: 123, bar: 456}]]);
190
+ });
191
+ });
192
+ });