@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.
- package/.eslintignore +2 -0
- package/.eslintrc.js +73 -0
- package/.stylelintrc +12 -0
- package/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/demo/index.html +582 -0
- package/demo/live-demo.js +471 -0
- package/dist/DateRangePicker.cjs.js +2996 -0
- package/dist/DateRangePicker.esm.js +2994 -0
- package/dist/DateRangePicker.umd.js +3002 -0
- package/dist/Datepicker.cjs.js +2778 -0
- package/dist/Datepicker.esm.js +2776 -0
- package/dist/Datepicker.umd.js +2784 -0
- package/dist/css/datepicker-bs4.css +276 -0
- package/dist/css/datepicker-bs4.min.css +1 -0
- package/dist/css/datepicker-bs5.css +276 -0
- package/dist/css/datepicker-bs5.min.css +1 -0
- package/dist/css/datepicker-bulma.css +258 -0
- package/dist/css/datepicker-bulma.min.css +1 -0
- package/dist/css/datepicker-foundation.css +262 -0
- package/dist/css/datepicker-foundation.min.css +1 -0
- package/dist/css/datepicker.css +306 -0
- package/dist/css/datepicker.min.css +1403 -0
- package/dist/js/datepicker-full.js +2777 -0
- package/dist/js/datepicker-full.min.js +1 -0
- package/dist/js/datepicker.js +2569 -0
- package/dist/js/datepicker.min.js +1 -0
- package/dist/js/locales/ar-tn.js +15 -0
- package/dist/js/locales/ar.js +15 -0
- package/dist/js/locales/az.js +14 -0
- package/dist/js/locales/bg.js +14 -0
- package/dist/js/locales/bm.js +18 -0
- package/dist/js/locales/bn.js +19 -0
- package/dist/js/locales/br.js +18 -0
- package/dist/js/locales/bs.js +15 -0
- package/dist/js/locales/ca.js +18 -0
- package/dist/js/locales/cs.js +19 -0
- package/dist/js/locales/cy.js +14 -0
- package/dist/js/locales/da.js +19 -0
- package/dist/js/locales/de.js +18 -0
- package/dist/js/locales/el.js +16 -0
- package/dist/js/locales/en-AU.js +18 -0
- package/dist/js/locales/en-CA.js +18 -0
- package/dist/js/locales/en-GB.js +18 -0
- package/dist/js/locales/en-IE.js +17 -0
- package/dist/js/locales/en-NZ.js +17 -0
- package/dist/js/locales/en-ZA.js +17 -0
- package/dist/js/locales/eo.js +17 -0
- package/dist/js/locales/es.js +18 -0
- package/dist/js/locales/et.js +18 -0
- package/dist/js/locales/eu.js +18 -0
- package/dist/js/locales/fa.js +17 -0
- package/dist/js/locales/fi.js +17 -0
- package/dist/js/locales/fo.js +15 -0
- package/dist/js/locales/fr-CH.js +21 -0
- package/dist/js/locales/fr.js +18 -0
- package/dist/js/locales/gl.js +16 -0
- package/dist/js/locales/he.js +15 -0
- package/dist/js/locales/hi.js +18 -0
- package/dist/js/locales/hr.js +13 -0
- package/dist/js/locales/hu.js +18 -0
- package/dist/js/locales/hy.js +18 -0
- package/dist/js/locales/id.js +15 -0
- package/dist/js/locales/is.js +14 -0
- package/dist/js/locales/it-CH.js +20 -0
- package/dist/js/locales/it.js +18 -0
- package/dist/js/locales/ja.js +17 -0
- package/dist/js/locales/ka.js +17 -0
- package/dist/js/locales/kk.js +15 -0
- package/dist/js/locales/km.js +15 -0
- package/dist/js/locales/ko.js +18 -0
- package/dist/js/locales/lt.js +19 -0
- package/dist/js/locales/lv.js +18 -0
- package/dist/js/locales/me.js +17 -0
- package/dist/js/locales/mk.js +15 -0
- package/dist/js/locales/mn.js +17 -0
- package/dist/js/locales/mr.js +18 -0
- package/dist/js/locales/ms.js +15 -0
- package/dist/js/locales/nl-BE.js +18 -0
- package/dist/js/locales/nl.js +18 -0
- package/dist/js/locales/no.js +18 -0
- package/dist/js/locales/oc.js +17 -0
- package/dist/js/locales/pl.js +17 -0
- package/dist/js/locales/pt-BR.js +17 -0
- package/dist/js/locales/pt.js +18 -0
- package/dist/js/locales/ro.js +17 -0
- package/dist/js/locales/ru.js +18 -0
- package/dist/js/locales/si.js +18 -0
- package/dist/js/locales/sk.js +18 -0
- package/dist/js/locales/sl.js +15 -0
- package/dist/js/locales/sq.js +18 -0
- package/dist/js/locales/sr-latn.js +16 -0
- package/dist/js/locales/sr.js +16 -0
- package/dist/js/locales/sv.js +17 -0
- package/dist/js/locales/sw.js +15 -0
- package/dist/js/locales/ta.js +18 -0
- package/dist/js/locales/tg.js +19 -0
- package/dist/js/locales/th.js +14 -0
- package/dist/js/locales/tk.js +18 -0
- package/dist/js/locales/tr.js +17 -0
- package/dist/js/locales/uk.js +17 -0
- package/dist/js/locales/uz-cyrl.js +18 -0
- package/dist/js/locales/uz-latn.js +18 -0
- package/dist/js/locales/vi.js +16 -0
- package/dist/js/locales/zh-CN.js +19 -0
- package/dist/js/locales/zh-TW.js +18 -0
- package/dist/locales/index.cjs.js +1028 -0
- package/dist/locales/index.esm.js +1028 -0
- package/dist/main.cjs.js +2999 -0
- package/dist/main.esm.js +2994 -0
- package/dist/main.umd.js +3005 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +266 -0
- package/docs/_sidebar.md +6 -0
- package/docs/api.md +284 -0
- package/docs/date-string+format.md +90 -0
- package/docs/i18n.md +99 -0
- package/docs/images/datepicker-inline.jpg +0 -0
- package/docs/images/datepicker.jpg +0 -0
- package/docs/images/multidate.jpg +0 -0
- package/docs/images/picker-structure.jpg +0 -0
- package/docs/images/rangepicker.jpg +0 -0
- package/docs/images/view-days.jpg +0 -0
- package/docs/images/view-decades.jpg +0 -0
- package/docs/images/view-months.jpg +0 -0
- package/docs/images/view-years.jpg +0 -0
- package/docs/index.html +26 -0
- package/docs/options.md +354 -0
- package/docs/overview.md +174 -0
- package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
- package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
- package/js/DateRangePicker.js +210 -0
- package/js/Datepicker.js +487 -0
- package/js/datepicker-full.js +5 -0
- package/js/events/functions.js +48 -0
- package/js/events/inputFieldListeners.js +206 -0
- package/js/events/otherListeners.js +15 -0
- package/js/events/pickerListeners.js +70 -0
- package/js/i18n/base-locales.js +13 -0
- package/js/i18n/locales/ar-tn.js +15 -0
- package/js/i18n/locales/ar.js +15 -0
- package/js/i18n/locales/az.js +14 -0
- package/js/i18n/locales/bg.js +14 -0
- package/js/i18n/locales/bm.js +18 -0
- package/js/i18n/locales/bn.js +19 -0
- package/js/i18n/locales/br.js +18 -0
- package/js/i18n/locales/bs.js +15 -0
- package/js/i18n/locales/ca.js +18 -0
- package/js/i18n/locales/cs.js +19 -0
- package/js/i18n/locales/cy.js +14 -0
- package/js/i18n/locales/da.js +19 -0
- package/js/i18n/locales/de.js +18 -0
- package/js/i18n/locales/el.js +16 -0
- package/js/i18n/locales/en-AU.js +18 -0
- package/js/i18n/locales/en-CA.js +18 -0
- package/js/i18n/locales/en-GB.js +18 -0
- package/js/i18n/locales/en-IE.js +17 -0
- package/js/i18n/locales/en-NZ.js +17 -0
- package/js/i18n/locales/en-ZA.js +17 -0
- package/js/i18n/locales/eo.js +17 -0
- package/js/i18n/locales/es.js +18 -0
- package/js/i18n/locales/et.js +18 -0
- package/js/i18n/locales/eu.js +18 -0
- package/js/i18n/locales/fa.js +17 -0
- package/js/i18n/locales/fi.js +17 -0
- package/js/i18n/locales/fo.js +15 -0
- package/js/i18n/locales/fr-CH.js +21 -0
- package/js/i18n/locales/fr.js +18 -0
- package/js/i18n/locales/gl.js +16 -0
- package/js/i18n/locales/he.js +15 -0
- package/js/i18n/locales/hi.js +18 -0
- package/js/i18n/locales/hr.js +13 -0
- package/js/i18n/locales/hu.js +18 -0
- package/js/i18n/locales/hy.js +18 -0
- package/js/i18n/locales/id.js +15 -0
- package/js/i18n/locales/is.js +14 -0
- package/js/i18n/locales/it-CH.js +20 -0
- package/js/i18n/locales/it.js +18 -0
- package/js/i18n/locales/ja.js +17 -0
- package/js/i18n/locales/ka.js +17 -0
- package/js/i18n/locales/kk.js +15 -0
- package/js/i18n/locales/km.js +15 -0
- package/js/i18n/locales/ko.js +18 -0
- package/js/i18n/locales/lt.js +19 -0
- package/js/i18n/locales/lv.js +18 -0
- package/js/i18n/locales/me.js +17 -0
- package/js/i18n/locales/mk.js +15 -0
- package/js/i18n/locales/mn.js +17 -0
- package/js/i18n/locales/mr.js +18 -0
- package/js/i18n/locales/ms.js +15 -0
- package/js/i18n/locales/nl-BE.js +18 -0
- package/js/i18n/locales/nl.js +18 -0
- package/js/i18n/locales/no.js +18 -0
- package/js/i18n/locales/oc.js +17 -0
- package/js/i18n/locales/pl.js +17 -0
- package/js/i18n/locales/pt-BR.js +17 -0
- package/js/i18n/locales/pt.js +18 -0
- package/js/i18n/locales/ro.js +17 -0
- package/js/i18n/locales/ru.js +18 -0
- package/js/i18n/locales/si.js +18 -0
- package/js/i18n/locales/sk.js +18 -0
- package/js/i18n/locales/sl.js +15 -0
- package/js/i18n/locales/sq.js +18 -0
- package/js/i18n/locales/sr-latn.js +16 -0
- package/js/i18n/locales/sr.js +16 -0
- package/js/i18n/locales/sv.js +17 -0
- package/js/i18n/locales/sw.js +15 -0
- package/js/i18n/locales/ta.js +18 -0
- package/js/i18n/locales/tg.js +19 -0
- package/js/i18n/locales/th.js +14 -0
- package/js/i18n/locales/tk.js +18 -0
- package/js/i18n/locales/tr.js +17 -0
- package/js/i18n/locales/uk.js +17 -0
- package/js/i18n/locales/uz-cyrl.js +18 -0
- package/js/i18n/locales/uz-latn.js +18 -0
- package/js/i18n/locales/vi.js +16 -0
- package/js/i18n/locales/zh-CN.js +19 -0
- package/js/i18n/locales/zh-TW.js +18 -0
- package/js/lib/date-format.js +185 -0
- package/js/lib/date.js +82 -0
- package/js/lib/dom.js +55 -0
- package/js/lib/event.js +68 -0
- package/js/lib/utils.js +61 -0
- package/js/main.js +4 -0
- package/js/options/defaultOptions.js +38 -0
- package/js/options/processOptions.js +263 -0
- package/js/picker/Picker.js +334 -0
- package/js/picker/templates/calendarWeeksTemplate.js +8 -0
- package/js/picker/templates/daysTemplate.js +8 -0
- package/js/picker/templates/pickerTemplate.js +23 -0
- package/js/picker/views/DaysView.js +250 -0
- package/js/picker/views/MonthsView.js +198 -0
- package/js/picker/views/View.js +55 -0
- package/js/picker/views/YearsView.js +170 -0
- package/package.json +81 -0
- package/postcss.config.js +5 -0
- package/rollup.config.js +75 -0
- package/sass/_mixins.scss +12 -0
- package/sass/datepicker-bs4.scss +91 -0
- package/sass/datepicker-bs5.scss +91 -0
- package/sass/datepicker-bulma.scss +69 -0
- package/sass/datepicker-foundation.scss +66 -0
- package/sass/datepicker.scss +436 -0
- package/sass/index-bs4.scss +5 -0
- package/sass/index-bs5.scss +5 -0
- package/sass/index-bulma.scss +6 -0
- package/sass/index-foundation.scss +3 -0
- package/scripts/build-css.js +39 -0
- package/scripts/build-locales.js +57 -0
- package/scripts/convert-bsdp-locales.js +65 -0
- package/scripts/minify-css.js +31 -0
- package/scripts/minify-js.js +17 -0
- package/style.css +10 -0
- package/tailwind.config.js +16 -0
- package/tailwind.css +1389 -0
- package/test/DateRangePicker/DateRangePicker.js +547 -0
- package/test/DateRangePicker/api-methods.js +415 -0
- package/test/DateRangePicker/date-selection.js +472 -0
- package/test/DateRangePicker/options.js +308 -0
- package/test/Datepicker/Datepicker-object.js +236 -0
- package/test/Datepicker/api-methods.js +328 -0
- package/test/_utils/date.js +102 -0
- package/test/_utils/dom.js +70 -0
- package/test/events.js +785 -0
- package/test/inline-mode.js +45 -0
- package/test/keyboard-operation/arrow-down.js +293 -0
- package/test/keyboard-operation/arrow-left.js +255 -0
- package/test/keyboard-operation/arrow-right.js +215 -0
- package/test/keyboard-operation/arrow-up.js +461 -0
- package/test/keyboard-operation/edit-mode.js +458 -0
- package/test/keyboard-operation/keyboard-operation.js +146 -0
- package/test/mouse-operation.js +580 -0
- package/test/options/before-show.js +635 -0
- package/test/options/bulma-datepicker.sublime-workspace +1280 -0
- package/test/options/buttons.js +383 -0
- package/test/options/date-restrictions.js +802 -0
- package/test/options/format.js +281 -0
- package/test/options/multidate.js +380 -0
- package/test/options/options.js +727 -0
- package/test/options/orientation.js +410 -0
- package/test/options/pick-levle+view.js +357 -0
- package/test/test.html +94 -0
- package/test/unit/DateRangePicker.js +192 -0
- package/test/unit/Datepicker.js +307 -0
- package/test/unit/_setup.js +28 -0
- package/test/unit/lib/date-format.js +310 -0
- package/test/unit/lib/date.js +211 -0
- package/test/unit/lib/dom.js +142 -0
- package/test/unit/lib/event.js +207 -0
- package/test/unit/lib/utils.js +135 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
describe('options - buttons', 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('clearBtn', function () {
|
|
17
|
+
it('displays a button to clear the selection when true', function () {
|
|
18
|
+
const {dp, picker} = createDP(input, {clearBtn: true});
|
|
19
|
+
const [viewSwitch, clearBtn] = getParts(picker, ['.view-switch', '.clear-btn']);
|
|
20
|
+
dp.show();
|
|
21
|
+
|
|
22
|
+
expect(isVisible(clearBtn), 'to be true');
|
|
23
|
+
expect(clearBtn.textContent, 'to be', 'Clear');
|
|
24
|
+
|
|
25
|
+
// months view
|
|
26
|
+
viewSwitch.click();
|
|
27
|
+
expect(isVisible(clearBtn), 'to be true');
|
|
28
|
+
|
|
29
|
+
// years view
|
|
30
|
+
viewSwitch.click();
|
|
31
|
+
expect(isVisible(clearBtn), 'to be true');
|
|
32
|
+
|
|
33
|
+
// decades view
|
|
34
|
+
viewSwitch.click();
|
|
35
|
+
expect(isVisible(clearBtn), 'to be true');
|
|
36
|
+
|
|
37
|
+
dp.destroy();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('can be updated with setOptions()', function () {
|
|
41
|
+
const {dp, picker} = createDP(input);
|
|
42
|
+
dp.setOptions({clearBtn: true});
|
|
43
|
+
dp.show();
|
|
44
|
+
|
|
45
|
+
const clearBtn = picker.querySelector('.clear-btn');
|
|
46
|
+
expect(isVisible(clearBtn), 'to be true');
|
|
47
|
+
|
|
48
|
+
dp.setOptions({clearBtn: false});
|
|
49
|
+
expect(isVisible(clearBtn), 'to be false');
|
|
50
|
+
|
|
51
|
+
dp.destroy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('clear button', function () {
|
|
55
|
+
let dp;
|
|
56
|
+
let picker;
|
|
57
|
+
let clearBtn;
|
|
58
|
+
|
|
59
|
+
beforeEach(function () {
|
|
60
|
+
({dp, picker} = createDP(input, {clearBtn: true}));
|
|
61
|
+
clearBtn = picker.querySelector('.clear-btn');
|
|
62
|
+
dp.show();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(function () {
|
|
66
|
+
dp.destroy();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('clears the selection', function () {
|
|
70
|
+
dp.setDate('2/14/2020');
|
|
71
|
+
clearBtn.click();
|
|
72
|
+
|
|
73
|
+
expect(dp.dates, 'to equal', []);
|
|
74
|
+
expect(input.value, 'to be', '');
|
|
75
|
+
|
|
76
|
+
const viewSwitch = getViewSwitch(picker);
|
|
77
|
+
// months view
|
|
78
|
+
dp.setDate('2/14/2020');
|
|
79
|
+
viewSwitch.click();
|
|
80
|
+
clearBtn.click();
|
|
81
|
+
expect(dp.dates, 'to equal', []);
|
|
82
|
+
|
|
83
|
+
// years view
|
|
84
|
+
dp.setDate('2/14/2020');
|
|
85
|
+
viewSwitch.click();
|
|
86
|
+
clearBtn.click();
|
|
87
|
+
expect(dp.dates, 'to equal', []);
|
|
88
|
+
|
|
89
|
+
// decades view
|
|
90
|
+
dp.setDate('2/14/2020');
|
|
91
|
+
viewSwitch.click();
|
|
92
|
+
clearBtn.click();
|
|
93
|
+
expect(dp.dates, 'to equal', []);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('hides the picker as well when autohide = true', function () {
|
|
97
|
+
dp.setDate('2/14/2020');
|
|
98
|
+
dp.setOptions({autohide: true});
|
|
99
|
+
clearBtn.click();
|
|
100
|
+
|
|
101
|
+
expect(isVisible(picker), 'to be false');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('todayBtn', function () {
|
|
107
|
+
it('displays a button to change the view date to current date when true', function () {
|
|
108
|
+
const {dp, picker} = createDP(input, {todayBtn: true});
|
|
109
|
+
const [viewSwitch, todayBtn] = getParts(picker, ['.view-switch', '.today-btn']);
|
|
110
|
+
dp.show();
|
|
111
|
+
|
|
112
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
113
|
+
expect(todayBtn.textContent, 'to be', 'Today');
|
|
114
|
+
|
|
115
|
+
// months view
|
|
116
|
+
viewSwitch.click();
|
|
117
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
118
|
+
|
|
119
|
+
// years view
|
|
120
|
+
viewSwitch.click();
|
|
121
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
122
|
+
|
|
123
|
+
// decades view
|
|
124
|
+
viewSwitch.click();
|
|
125
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
126
|
+
|
|
127
|
+
dp.destroy();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('today will be disabled if the current date is out of the range of minDate/maxDate', function () {
|
|
131
|
+
const {dp, picker} = createDP(input, {todayBtn: true});
|
|
132
|
+
const todayBtn = picker.querySelector('.today-btn');
|
|
133
|
+
dp.show();
|
|
134
|
+
|
|
135
|
+
expect(todayBtn.disabled, 'to be false');
|
|
136
|
+
|
|
137
|
+
dp.setOptions({minDate: '2/20/2020'});
|
|
138
|
+
expect(todayBtn.disabled, 'to be true');
|
|
139
|
+
|
|
140
|
+
dp.setOptions({minDate: null, maxDate: '2/10/2020'});
|
|
141
|
+
expect(todayBtn.disabled, 'to be true');
|
|
142
|
+
|
|
143
|
+
dp.setOptions({minDate: '2/1/2020', maxDate: '2/29/2020'});
|
|
144
|
+
expect(todayBtn.disabled, 'to be false');
|
|
145
|
+
|
|
146
|
+
dp.destroy();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('can be updated with setOptions()', function () {
|
|
150
|
+
const {dp, picker} = createDP(input);
|
|
151
|
+
dp.setOptions({todayBtn: true});
|
|
152
|
+
dp.show();
|
|
153
|
+
|
|
154
|
+
const todayBtn = picker.querySelector('.today-btn');
|
|
155
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
156
|
+
|
|
157
|
+
dp.setOptions({todayBtn: false});
|
|
158
|
+
expect(isVisible(todayBtn), 'to be false');
|
|
159
|
+
|
|
160
|
+
dp.setOptions({todayBtn: 'true'});
|
|
161
|
+
expect(isVisible(todayBtn), 'to be true');
|
|
162
|
+
|
|
163
|
+
dp.destroy();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('todayBtnMode', function () {
|
|
168
|
+
let dp;
|
|
169
|
+
let picker;
|
|
170
|
+
let viewSwitch;
|
|
171
|
+
let todayBtn;
|
|
172
|
+
let cells;
|
|
173
|
+
|
|
174
|
+
beforeEach(function () {
|
|
175
|
+
({dp, picker} = createDP(input, {todayBtn: true}));
|
|
176
|
+
[viewSwitch, todayBtn] = getParts(picker, ['.view-switch', '.today-btn']);
|
|
177
|
+
dp.show();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(function () {
|
|
181
|
+
dp.destroy();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('specifies the behavior of the today buton', function () {
|
|
185
|
+
const date = dateValue(2020, 1, 11);
|
|
186
|
+
|
|
187
|
+
// defualt to 0: focus-on (change view date)
|
|
188
|
+
dp.setDate(date);
|
|
189
|
+
todayBtn.click();
|
|
190
|
+
|
|
191
|
+
cells = getCells(picker);
|
|
192
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
193
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
194
|
+
expect(cells[16].classList.contains('selected'), 'to be true');
|
|
195
|
+
expect(dp.dates, 'to equal', [date]);
|
|
196
|
+
|
|
197
|
+
dp.destroy();
|
|
198
|
+
|
|
199
|
+
// 1: select (change the selection)
|
|
200
|
+
({dp, picker} = createDP(input, {todayBtn: true, todayBtnMode: 1}));
|
|
201
|
+
todayBtn = picker.querySelector('.today-btn');
|
|
202
|
+
dp.setDate(date);
|
|
203
|
+
dp.show();
|
|
204
|
+
todayBtn.click();
|
|
205
|
+
|
|
206
|
+
cells = getCells(picker);
|
|
207
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
208
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
209
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
210
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('can be updated with setOptions()', function () {
|
|
214
|
+
const date = dateValue(2020, 1, 11);
|
|
215
|
+
|
|
216
|
+
dp.setDate(date);
|
|
217
|
+
dp.setOptions({todayBtnMode: 1});
|
|
218
|
+
todayBtn.click();
|
|
219
|
+
|
|
220
|
+
cells = getCells(picker);
|
|
221
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
222
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
223
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
224
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
225
|
+
|
|
226
|
+
dp.setDate(date);
|
|
227
|
+
dp.setOptions({todayBtnMode: 0});
|
|
228
|
+
todayBtn.click();
|
|
229
|
+
|
|
230
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
231
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
232
|
+
expect(cells[16].classList.contains('selected'), 'to be true');
|
|
233
|
+
expect(dp.dates, 'to equal', [date]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('today button', function () {
|
|
237
|
+
it('changes the view date to the current date when todayBtnMode = 0', function () {
|
|
238
|
+
dp.setDate('4/22/2020');
|
|
239
|
+
todayBtn.click();
|
|
240
|
+
|
|
241
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
242
|
+
|
|
243
|
+
cells = getCells(picker);
|
|
244
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
245
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
246
|
+
expect(cells.find(el => el.classList.contains('selected')), 'to be undefined');
|
|
247
|
+
|
|
248
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
|
|
249
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
250
|
+
|
|
251
|
+
dp.setDate({clear: true});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('also changes the view to days view when todayBtnMode = 0', function () {
|
|
255
|
+
// months view
|
|
256
|
+
dp.setDate('4/22/2020');
|
|
257
|
+
viewSwitch.click();
|
|
258
|
+
todayBtn.click();
|
|
259
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
260
|
+
|
|
261
|
+
// years view
|
|
262
|
+
dp.setDate({clear: true});
|
|
263
|
+
dp.setDate('4/22/2020');
|
|
264
|
+
viewSwitch.click();
|
|
265
|
+
viewSwitch.click();
|
|
266
|
+
todayBtn.click();
|
|
267
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
268
|
+
|
|
269
|
+
// decades view
|
|
270
|
+
dp.setDate({clear: true});
|
|
271
|
+
dp.setDate('4/22/2020');
|
|
272
|
+
viewSwitch.click();
|
|
273
|
+
viewSwitch.click();
|
|
274
|
+
viewSwitch.click();
|
|
275
|
+
todayBtn.click();
|
|
276
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
277
|
+
|
|
278
|
+
dp.setDate({clear: true});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('changes the selection to the current date when todayBtnMode = 1', function () {
|
|
282
|
+
dp.setOptions({todayBtnMode: 1});
|
|
283
|
+
dp.setDate('4/22/2020');
|
|
284
|
+
todayBtn.click();
|
|
285
|
+
|
|
286
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
287
|
+
|
|
288
|
+
cells = getCells(picker);
|
|
289
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
290
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
291
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
292
|
+
|
|
293
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
294
|
+
|
|
295
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
296
|
+
dp.setDate({clear: true});
|
|
297
|
+
dp.setDate('4/22/2020');
|
|
298
|
+
viewSwitch.click();
|
|
299
|
+
viewSwitch.click();
|
|
300
|
+
todayBtn.click();
|
|
301
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
302
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
303
|
+
|
|
304
|
+
dp.setDate({clear: true});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('also hides the picker when todayBtnMode = 1 and autohide = true', function () {
|
|
308
|
+
dp.setOptions({todayBtnMode: 1, autohide: true});
|
|
309
|
+
dp.setDate('4/22/2020');
|
|
310
|
+
todayBtn.click();
|
|
311
|
+
|
|
312
|
+
expect(isVisible(picker), 'to be false');
|
|
313
|
+
|
|
314
|
+
dp.setDate({clear: true});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('always changes the view to current date\'s days view when todayBtnMode = 1', function () {
|
|
318
|
+
const nextBtn = picker.querySelector('.next-btn');
|
|
319
|
+
dp.setOptions({todayBtnMode: 1});
|
|
320
|
+
|
|
321
|
+
// after moving other month or view while the current date is selected already
|
|
322
|
+
// (issue #11)
|
|
323
|
+
todayBtn.click();
|
|
324
|
+
nextBtn.click();
|
|
325
|
+
todayBtn.click();
|
|
326
|
+
cells = getCells(picker);
|
|
327
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
328
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
329
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
330
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
331
|
+
|
|
332
|
+
viewSwitch.click();
|
|
333
|
+
nextBtn.click();
|
|
334
|
+
todayBtn.click();
|
|
335
|
+
cells = getCells(picker);
|
|
336
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
337
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
338
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
339
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
340
|
+
|
|
341
|
+
viewSwitch.click();
|
|
342
|
+
viewSwitch.click();
|
|
343
|
+
nextBtn.click();
|
|
344
|
+
nextBtn.click();
|
|
345
|
+
todayBtn.click();
|
|
346
|
+
cells = getCells(picker);
|
|
347
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
348
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
349
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
350
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
351
|
+
|
|
352
|
+
// when current date is deslected by toggling in multi-date mode
|
|
353
|
+
dp.setOptions({maxNumberOfDates: 3});
|
|
354
|
+
nextBtn.click();
|
|
355
|
+
getCells(picker)[20].click();
|
|
356
|
+
todayBtn.click();
|
|
357
|
+
cells = getCells(picker);
|
|
358
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
359
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
360
|
+
expect(cells[19].classList.contains('selected'), 'to be false');
|
|
361
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 2, 21)]);
|
|
362
|
+
|
|
363
|
+
nextBtn.click();
|
|
364
|
+
todayBtn.click();
|
|
365
|
+
cells = getCells(picker);
|
|
366
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
367
|
+
expect(cells[19].classList.contains('selected'), 'to be true');
|
|
368
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 2, 21), dateValue(2020, 1, 14)]);
|
|
369
|
+
|
|
370
|
+
viewSwitch.click();
|
|
371
|
+
nextBtn.click();
|
|
372
|
+
todayBtn.click();
|
|
373
|
+
cells = getCells(picker);
|
|
374
|
+
expect(viewSwitch.textContent, 'to be', 'February 2020');
|
|
375
|
+
expect(cells[19].classList.contains('focused'), 'to be true');
|
|
376
|
+
expect(cells[19].classList.contains('selected'), 'to be false');
|
|
377
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 2, 21)]);
|
|
378
|
+
|
|
379
|
+
dp.setDate({clear: true});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
});
|