second commit
This commit is contained in:
547
node_modules/flowbite-datepicker/test/DateRangePicker/DateRangePicker.js
generated
vendored
Normal file
547
node_modules/flowbite-datepicker/test/DateRangePicker/DateRangePicker.js
generated
vendored
Normal file
@ -0,0 +1,547 @@
|
||||
describe('DateRangePicker', function () {
|
||||
let clock;
|
||||
let elem;
|
||||
let input0;
|
||||
let input1;
|
||||
|
||||
before(function () {
|
||||
clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
elem = domUtils.parseHTML('<div><input><input></div>').firstChild;
|
||||
[input0, input1] = elem.children;
|
||||
testContainer.appendChild(elem);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
testContainer.removeChild(elem);
|
||||
});
|
||||
|
||||
it('input elements\' values are used for the initial dates', function () {
|
||||
input0.value = '04/20/2020';
|
||||
input1.value = '04/22/2020';
|
||||
|
||||
const drp = new DateRangePicker(elem);
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 3, 20), dateValue(2020, 3, 22)]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('the pickers are hidden at start', function () {
|
||||
const {drp, picker0, picker1} = createDRP(elem);
|
||||
|
||||
expect(isVisible(picker0), 'to be false');
|
||||
expect(isVisible(picker1), 'to be false');
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('the pickers becomes visible when the input element get focus and invisivle when losing focus', function () {
|
||||
const {drp, picker0, picker1} = createDRP(elem);
|
||||
|
||||
input0.focus();
|
||||
expect(isVisible(picker0), 'to be true');
|
||||
|
||||
simulant.fire(input0, 'keydown', {key: 'Tab'});
|
||||
expect(isVisible(picker0), 'to be false');
|
||||
|
||||
input1.focus();
|
||||
expect(isVisible(picker1), 'to be true');
|
||||
|
||||
simulant.fire(input1, 'keydown', {key: 'Tab'});
|
||||
expect(isVisible(picker1), 'to be false');
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('indicates the range with hilighting the start/end in the pickers', function () {
|
||||
input0.value = '04/20/2020';
|
||||
input1.value = '04/22/2020';
|
||||
|
||||
const partsClasses = ['.view-switch', '.prev-btn', '.next-btn'];
|
||||
let {drp, picker0, picker1} = createDRP(elem);
|
||||
let [viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses);
|
||||
let [viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses);
|
||||
input0.focus();
|
||||
|
||||
let cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'April 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [22]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [22]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [24]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [23]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [22]);
|
||||
|
||||
input1.focus();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'April 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [24]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [22]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [24]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [23]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [24]);
|
||||
|
||||
drp.destroy();
|
||||
|
||||
// range over months (days → months views)
|
||||
input0.value = '02/26/2020';
|
||||
input1.value = '04/12/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
|
||||
([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
|
||||
|
||||
// range-start
|
||||
input0.focus();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [31]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [31]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [32, 33, 34, 35, 36, 37, 38, 39, 40, 41]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [31]);
|
||||
|
||||
prevBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'January 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [28]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 42);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [25]);
|
||||
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'April 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [14]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [28]);
|
||||
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
|
||||
|
||||
// range-end
|
||||
input1.focus();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'April 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [14]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [14]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [14]);
|
||||
|
||||
nextBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'May 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [16]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 42);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [11]);
|
||||
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [31]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [32, 33, 34, 35, 36, 37, 38, 39, 40, 41]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [17]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [1]);
|
||||
|
||||
drp.destroy();
|
||||
|
||||
// range over years (months → years views)
|
||||
input0.value = '10/01/2020';
|
||||
input1.value = '03/31/2023';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
|
||||
([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
|
||||
|
||||
// range-start
|
||||
input0.focus();
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
prevBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2019');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2021');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2023');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [4]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [2, 3]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [4]);
|
||||
|
||||
// range-end
|
||||
input1.focus();
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2023');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
nextBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2024');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2022');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [4]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [4]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [2, 3]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [1]);
|
||||
|
||||
drp.destroy();
|
||||
|
||||
// range over decades (years → decades views)
|
||||
input0.value = '01/01/2017';
|
||||
input1.value = '12/31/2041';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
|
||||
([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
|
||||
|
||||
// range-start
|
||||
input0.focus();
|
||||
viewSwitch0.click();
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2010-2019');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [8]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [8]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [9, 10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
|
||||
|
||||
prevBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2000-2009');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2040-2049');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [8]);
|
||||
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2000-2090');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [5]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [3, 4]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [5]);
|
||||
|
||||
// range-end
|
||||
input1.focus();
|
||||
viewSwitch1.click();
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2040-2049');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
nextBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2050-2059');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2030-2039');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2010-2019');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [8]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [9, 10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2000-2090');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [5]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [5]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [3, 4]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [2]);
|
||||
|
||||
drp.destroy();
|
||||
|
||||
// range over centures (decades views)
|
||||
input0.value = '01/22/1984';
|
||||
input1.value = '12/31/2121';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
([viewSwitch0, prevBtn0, nextBtn0] = getParts(picker0, partsClasses));
|
||||
([viewSwitch1, prevBtn1, nextBtn1] = getParts(picker1, partsClasses));
|
||||
|
||||
// range-start
|
||||
input0.focus();
|
||||
viewSwitch0.click();
|
||||
viewSwitch0.click();
|
||||
viewSwitch0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '1900-1990');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
prevBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '1800-1890');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
nextBtn0.click();
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2000-2090');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
nextBtn0.click();
|
||||
cells = getCells(picker0);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', '2100-2190');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [9]);
|
||||
|
||||
// range-end
|
||||
input1.focus();
|
||||
viewSwitch1.click();
|
||||
viewSwitch1.click();
|
||||
viewSwitch1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2100-2190');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [0, 1, 2]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
|
||||
|
||||
nextBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2200-2290');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
|
||||
|
||||
prevBtn1.click();
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '2000-2090');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range').length, 'to be', 12);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
|
||||
|
||||
prevBtn1.click();
|
||||
cells = getCells(picker1);
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', '1900-1990');
|
||||
expect(getCellIndices(cells, '.selected'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range-start'), 'to equal', [9]);
|
||||
expect(getCellIndices(cells, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells, '.range'), 'to equal', [10, 11]);
|
||||
expect(getCellIndices(cells, '.focused'), 'to equal', [3]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
});
|
415
node_modules/flowbite-datepicker/test/DateRangePicker/api-methods.js
generated
vendored
Normal file
415
node_modules/flowbite-datepicker/test/DateRangePicker/api-methods.js
generated
vendored
Normal file
@ -0,0 +1,415 @@
|
||||
describe('DateRangePicker - API methods', function () {
|
||||
let clock;
|
||||
let elem;
|
||||
let input0;
|
||||
let input1;
|
||||
|
||||
before(function () {
|
||||
clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
elem = domUtils.parseHTML('<div><input><input></div>').firstChild;
|
||||
[input0, input1] = elem.children;
|
||||
testContainer.appendChild(elem);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
testContainer.removeChild(elem);
|
||||
});
|
||||
|
||||
describe('getDates()', function () {
|
||||
it('returns an array of the Date objects of selected dates', function () {
|
||||
input0.value = '04/20/2020';
|
||||
input1.value = '04/22/2020';
|
||||
|
||||
const drp = new DateRangePicker(elem);
|
||||
expect(drp.getDates(), 'to equal', [
|
||||
new Date(dateValue(2020, 3, 20)),
|
||||
new Date(dateValue(2020, 3, 22)),
|
||||
]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('returns a formatted date stirngs of selected dates if the format is specified', function () {
|
||||
input0.value = '04/20/2020';
|
||||
input1.value = '04/22/2020';
|
||||
|
||||
const drp = new DateRangePicker(elem);
|
||||
expect(drp.getDates('yyyy-mm-dd'), 'to equal', ['2020-04-20', '2020-04-22']);
|
||||
expect(drp.getDates('d M, yy'), 'to equal', ['20 Apr, 20', '22 Apr, 20']);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('uses undefined instead of Date object if date is not selected', function () {
|
||||
const drp = new DateRangePicker(elem);
|
||||
expect(drp.getDates(), 'to equal', [undefined, undefined]);
|
||||
expect(drp.getDates('yyyy-mm-dd'), 'to equal', [undefined, undefined]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setDates()', function () {
|
||||
let drp;
|
||||
let picker0;
|
||||
let picker1;
|
||||
let viewSwitch0;
|
||||
let viewSwitch1;
|
||||
let cells0;
|
||||
let cells1;
|
||||
|
||||
it('changes the selected dates to given dates', function () {
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates('2/11/2020', '2/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [16]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [16]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', [19]);
|
||||
expect(getCellIndices(cells0, '.range'), 'to equal', [17, 18]);
|
||||
expect(getCellIndices(cells0, '.focused'), 'to equal', [16]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 1, 14)]);
|
||||
expect(input1.value, 'to be', '02/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [19]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [16]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [19]);
|
||||
expect(getCellIndices(cells1, '.range'), 'to equal', [17, 18]);
|
||||
expect(getCellIndices(cells1, '.focused'), 'to equal', [19]);
|
||||
|
||||
drp.setDates(new Date(2020, 4, 31), new Date(2020, 6, 5).getTime());
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 4, 31)]);
|
||||
expect(input0.value, 'to be', '05/31/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'May 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [35]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [35]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', []);
|
||||
expect(getCellIndices(cells0, '.range'), 'to equal', [36, 37, 38, 39, 40, 41]);
|
||||
expect(getCellIndices(cells0, '.focused'), 'to equal', [35]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 6, 5)]);
|
||||
expect(input1.value, 'to be', '07/05/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'July 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [7]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [7]);
|
||||
expect(getCellIndices(cells1, '.range'), 'to equal', [0, 1, 2, 3, 4, 5, 6]);
|
||||
expect(getCellIndices(cells1, '.focused'), 'to equal', [7]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('swapps star↔︎end dates if given start date > end date', function () {
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates(new Date(2020, 6, 5).getTime(), new Date(2020, 4, 31));
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 4, 31)]);
|
||||
expect(input0.value, 'to be', '05/31/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'May 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [35]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 6, 5)]);
|
||||
expect(input1.value, 'to be', '07/05/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'July 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [7]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('ignores invalid dates and the same date as the current one and leaves that side untouched', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/14/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates('', '3/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [16]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input1.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [13]);
|
||||
|
||||
let date0Str;
|
||||
let date0YM;
|
||||
let date0Indices;
|
||||
if (new Date(0).getDate() === 1) {
|
||||
date0Str = '01/01/1970';
|
||||
date0YM = 'January 1970';
|
||||
date0Indices = [4];
|
||||
} else {
|
||||
date0Str = '12/31/1969';
|
||||
date0YM = 'December 1969';
|
||||
date0Indices = [31];
|
||||
}
|
||||
|
||||
drp.setDates(0, new Date(-1, 11, 31));
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(0)]);
|
||||
expect(input0.value, 'to be', date0Str);
|
||||
expect(viewSwitch0.textContent, 'to be', date0YM);
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', date0Indices);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input1.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [13]);
|
||||
|
||||
input1.value = 'foo';
|
||||
drp.setDates('2/11/2020', '3/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [16]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input1.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [13]);
|
||||
|
||||
input0.value = 'foo';
|
||||
drp.setDates('2/11/2020', '2/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [16]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 1, 14)]);
|
||||
expect(input1.value, 'to be', '02/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [19]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('sets the same date to both sides if called with one side only when range is not selected', function () {
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates('2/11/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [16]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 1, 11)]);
|
||||
expect(input1.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [16]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates(undefined, '3/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input0.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [13]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input1.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [13]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('clears both sides if {clear: true} is passed as the last effective argument instrad of a date', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/14/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
// start: clear + end: ineffective (unspecified)
|
||||
drp.setDates({clear: true});
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', []);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', []);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', []);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/14/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
// start: clear + end: ineffective (same date)
|
||||
drp.setDates({clear: true}, '2/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', []);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', []);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', []);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/14/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
// start: valid date + end: clear
|
||||
drp.setDates('4/20/2020', {clear: true});
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', []);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', []);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', []);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/14/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
// start: ineffective (same date) + end: clear
|
||||
drp.setDates('2/11/2020', {clear: true});
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', []);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', []);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', []);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('sets the end date to both sides if {clear: true} is passed to start and an eefective date to end', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/11/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates({clear: true}, '2/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 1, 14)]);
|
||||
expect(input0.value, 'to be', '02/14/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [19]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 1, 14)]);
|
||||
expect(input1.value, 'to be', '02/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'February 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [19]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates({clear: true}, '3/14/2020');
|
||||
|
||||
expect(drp.datepickers[0].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input0.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [13]);
|
||||
|
||||
expect(drp.datepickers[1].dates, 'to equal', [dateValue(2020, 2, 14)]);
|
||||
expect(input1.value, 'to be', '03/14/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [13]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
});
|
||||
});
|
472
node_modules/flowbite-datepicker/test/DateRangePicker/date-selection.js
generated
vendored
Normal file
472
node_modules/flowbite-datepicker/test/DateRangePicker/date-selection.js
generated
vendored
Normal file
@ -0,0 +1,472 @@
|
||||
describe('DateRangePicker - date selection', function () {
|
||||
let clock;
|
||||
let elem;
|
||||
let input0;
|
||||
let input1;
|
||||
//
|
||||
let drp;
|
||||
let picker0;
|
||||
let picker1;
|
||||
let viewSwitch0;
|
||||
let viewSwitch1;
|
||||
let nextBtn0;
|
||||
let nextBtn1;
|
||||
let cells0;
|
||||
let cells1;
|
||||
|
||||
before(function () {
|
||||
clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
elem = domUtils.parseHTML('<div><input><input></div>').firstChild;
|
||||
[input0, input1] = elem.children;
|
||||
testContainer.appendChild(elem);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
testContainer.removeChild(elem);
|
||||
});
|
||||
|
||||
it('same date is set to both sides if a date is selected on one side when selections are none', function () {
|
||||
let selectDate = dateValue(2020, 1, 11);
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
cells0[16].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [selectDate, selectDate]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[16]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.datepickers[1].show();
|
||||
cells1[16].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [selectDate, selectDate]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[16]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
|
||||
// other month than default view date's
|
||||
// (issue #17, #19)
|
||||
let partsClasses = ['.view-switch', '.next-btn'];
|
||||
selectDate = dateValue(2020, 2, 10);
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
[viewSwitch0, nextBtn0] = getParts(picker0, partsClasses);
|
||||
[viewSwitch1, nextBtn1] = getParts(picker1, partsClasses);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
nextBtn0.click();
|
||||
getCells(picker0)[9].click();
|
||||
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
expect(drp.dates, 'to equal', [selectDate, selectDate]);
|
||||
expect(input0.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch0.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[9]]);
|
||||
|
||||
expect(input1.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch1.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[9]]);
|
||||
|
||||
drp.datepickers[1].show();
|
||||
nextBtn1.click();
|
||||
expect(viewSwitch1.textContent, 'to equal', 'April 2020');
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
[viewSwitch0, nextBtn0] = getParts(picker0, partsClasses);
|
||||
[viewSwitch1, nextBtn1] = getParts(picker1, partsClasses);
|
||||
|
||||
drp.datepickers[1].show();
|
||||
nextBtn1.click();
|
||||
getCells(picker1)[9].click();
|
||||
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
expect(drp.dates, 'to equal', [selectDate, selectDate]);
|
||||
expect(input0.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch0.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[9]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[9]]);
|
||||
|
||||
expect(input1.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch1.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[9]]);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
nextBtn0.click();
|
||||
expect(viewSwitch0.textContent, 'to equal', 'April 2020');
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('selections are cleared from both sides if selected date on one side is cleared', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/11/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
input0.value = '';
|
||||
simulant.fire(input0, 'keydown', {key: 'Enter'});
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, undefined]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[19]]);
|
||||
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[19]]);
|
||||
|
||||
drp.destroy();
|
||||
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/11/2020';
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
input1.value = '';
|
||||
simulant.fire(input1, 'keydown', {key: 'Enter'});
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, undefined]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[19]]);
|
||||
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[19]]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('dates are swapped if a date later than the 2nd picker\'s selection is seleted on the 1st picker', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/11/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
cells0[20].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 1, 15)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[20]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', [cells0[17], cells0[18], cells0[19]]);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/15/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[20]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[20]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', [cells1[17], cells1[18], cells1[19]]);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[20]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('dates are swapped if a date earlier than the 1st picker\'s selection is seleted on the 2nd picker', function () {
|
||||
input0.value = '02/11/2020';
|
||||
input1.value = '02/11/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.datepickers[1].show();
|
||||
cells1[12].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 7), dateValue(2020, 1, 11)]);
|
||||
expect(input0.value, 'to be', '02/07/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[12]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[12]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', [cells0[13], cells0[14], cells0[15]]);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[12]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[12]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', [cells1[13], cells1[14], cells1[15]]);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[16]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
describe('range between different months', function () {
|
||||
it('each picker displays the month of corresponding end of the range', function () {
|
||||
input0.value = '02/25/2020';
|
||||
input1.value = '03/05/2020';
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[30]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[30]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[39]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(31, 39));
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'March 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[4]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[4]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(0, 4));
|
||||
|
||||
drp.datepickers[1].show();
|
||||
picker1.querySelector('.next-btn').click();
|
||||
cells1 = getCells(picker1);
|
||||
cells1[24].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 25), dateValue(2020, 3, 22)]);
|
||||
expect(input0.value, 'to be', '02/25/2020');
|
||||
expect(input1.value, 'to be', '04/22/2020');
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[30]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[30]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(31));
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'April 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[24]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[24]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(0, 24));
|
||||
|
||||
input0.value = '02/14/1998';
|
||||
simulant.fire(input0, 'keydown', {key: 'Enter'});
|
||||
cells0 = getCells(picker0);
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(1998, 1, 14), dateValue(2020, 3, 22)]);
|
||||
expect(input0.value, 'to be', '02/14/1998');
|
||||
expect(input1.value, 'to be', '04/22/2020');
|
||||
|
||||
expect(viewSwitch0.textContent, 'to be', 'February 1998');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[13]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[13]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(14));
|
||||
|
||||
expect(viewSwitch1.textContent, 'to be', 'April 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[24]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[24]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(0, 24));
|
||||
|
||||
drp.datepickers[0].show();
|
||||
|
||||
// months view
|
||||
viewSwitch0.click();
|
||||
cells0 = getCells(picker0);
|
||||
expect(viewSwitch0.textContent, 'to be', '1998');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[1]]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells1 = getCells(picker1);
|
||||
expect(viewSwitch1.textContent, 'to be', '2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[3]]);
|
||||
|
||||
// years view
|
||||
viewSwitch0.click();
|
||||
cells0 = getCells(picker0);
|
||||
expect(viewSwitch0.textContent, 'to be', '1990-1999');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[9]]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells1 = getCells(picker1);
|
||||
expect(viewSwitch1.textContent, 'to be', '2020-2029');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[1]]);
|
||||
|
||||
// decades view
|
||||
viewSwitch0.click();
|
||||
cells0 = getCells(picker0);
|
||||
expect(viewSwitch0.textContent, 'to be', '1900-1990');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[10]]);
|
||||
|
||||
viewSwitch1.click();
|
||||
cells1 = getCells(picker1);
|
||||
expect(viewSwitch1.textContent, 'to be', '2000-2090');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[3]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('dates are swapped if a date later than the 2nd picker\'s selection is seleted on the 1st picker', function () {
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
[viewSwitch0, nextBtn0] = getParts(picker0, ['.view-switch', '.next-btn']);
|
||||
viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
|
||||
drp.datepickers[1].show();
|
||||
getCells(picker1)[16].click();
|
||||
drp.datepickers[1].hide();
|
||||
drp.datepickers[0].show();
|
||||
expect(viewSwitch0.textContent, 'to equal', 'February 2020');
|
||||
|
||||
nextBtn0.click();
|
||||
expect(viewSwitch0.textContent, 'to equal', 'March 2020');
|
||||
|
||||
getCells(picker0)[9].click();
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 2, 10)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to equal', 'February 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(17));
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch1.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(0, 9));
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[9]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
|
||||
it('dates are swapped if a date earlier than the 1st picker\'s selection is seleted on the 2nd picker', function () {
|
||||
let prevBtn1;
|
||||
|
||||
({drp, picker0, picker1} = createDRP(elem));
|
||||
[viewSwitch0, nextBtn0] = getParts(picker0, ['.view-switch', '.next-btn']);
|
||||
[viewSwitch1, prevBtn1] = getParts(picker1, ['.view-switch', '.prev-btn']);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
nextBtn0.click();
|
||||
getCells(picker0)[9].click();
|
||||
drp.datepickers[0].hide();
|
||||
drp.datepickers[1].show();
|
||||
expect(viewSwitch1.textContent, 'to equal', 'March 2020');
|
||||
|
||||
prevBtn1.click();
|
||||
expect(viewSwitch1.textContent, 'to equal', 'February 2020');
|
||||
|
||||
getCells(picker1)[16].click();
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 2, 10)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(viewSwitch0.textContent, 'to equal', 'February 2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(17));
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '03/10/2020');
|
||||
expect(viewSwitch1.textContent, 'to equal', 'March 2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[9]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(0, 9));
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[9]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
});
|
||||
});
|
||||
});
|
308
node_modules/flowbite-datepicker/test/DateRangePicker/options.js
generated
vendored
Normal file
308
node_modules/flowbite-datepicker/test/DateRangePicker/options.js
generated
vendored
Normal file
@ -0,0 +1,308 @@
|
||||
describe('DateRangePicker - options', function () {
|
||||
let clock;
|
||||
let elem;
|
||||
let input0;
|
||||
let input1;
|
||||
|
||||
before(function () {
|
||||
clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
elem = domUtils.parseHTML('<div><input><input></div>').firstChild;
|
||||
[input0, input1] = elem.children;
|
||||
testContainer.appendChild(elem);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
testContainer.removeChild(elem);
|
||||
});
|
||||
|
||||
describe('allowOneSidedRange', function () {
|
||||
it('disables the requirement for both sides of range to be set/unset', function () {
|
||||
let {drp, picker0, picker1} = createDRP(elem, {allowOneSidedRange: true});
|
||||
let cells0 = getCells(picker0);
|
||||
let cells1 = getCells(picker1);
|
||||
|
||||
drp.datepickers[0].show();
|
||||
cells0[16].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), undefined]);
|
||||
expect(drp.getDates(), 'to equal', [new Date(drp.dates[0]), undefined]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[19]]);
|
||||
|
||||
drp.datepickers[1].show();
|
||||
cells1[25].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 1, 20)]);
|
||||
expect(drp.getDates(), 'to equal', drp.dates.map(date => new Date(date)));
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', [cells0[16]]);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[25]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', cells0.slice(17, 25));
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[16]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/20/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[25]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', [cells1[16]]);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[25]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', cells1.slice(17, 25));
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[25]]);
|
||||
|
||||
simulant.fire(input0, 'keydown', {key: 'Escape'});
|
||||
input0.value = '';
|
||||
simulant.fire(input0, 'keydown', {key: 'Enter'});
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, dateValue(2020, 1, 20)]);
|
||||
expect(drp.getDates(), 'to equal', [undefined, new Date(drp.dates[1])]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.range-end'), 'to equal', [cells0[25]]);
|
||||
expect(filterCells(cells0, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells0, '.focused'), 'to equal', [cells0[19]]);
|
||||
|
||||
expect(input1.value, 'to be', '02/20/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[25]]);
|
||||
expect(filterCells(cells1, '.range-start'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.range-end'), 'to equal', [cells1[25]]);
|
||||
expect(filterCells(cells1, '.range'), 'to equal', []);
|
||||
expect(filterCells(cells1, '.focused'), 'to equal', [cells1[25]]);
|
||||
|
||||
drp.destroy();
|
||||
input0.value = '';
|
||||
input1.value = '';
|
||||
|
||||
// by setDates()
|
||||
({drp, picker0, picker1} = createDRP(elem, {allowOneSidedRange: true}));
|
||||
cells0 = getCells(picker0);
|
||||
cells1 = getCells(picker1);
|
||||
|
||||
drp.setDates('02/11/2020');
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), undefined]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.setDates(undefined, '02/20/2020');
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 1, 20)]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(input1.value, 'to be', '02/20/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[25]]);
|
||||
|
||||
drp.setDates({clear: true});
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, dateValue(2020, 1, 20)]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(input1.value, 'to be', '02/20/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[25]]);
|
||||
|
||||
drp.setDates('02/11/2020', {clear: true});
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), undefined]);
|
||||
expect(input0.value, 'to be', '02/11/2020');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', [cells0[16]]);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.setDates({clear: true}, '02/20/2020');
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, dateValue(2020, 1, 20)]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(input1.value, 'to be', '02/20/2020');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', [cells1[25]]);
|
||||
|
||||
drp.setDates(undefined, {clear: true});
|
||||
|
||||
expect(drp.dates, 'to equal', [undefined, undefined]);
|
||||
expect(input0.value, 'to be', '');
|
||||
expect(filterCells(cells0, '.selected'), 'to equal', []);
|
||||
expect(input1.value, 'to be', '');
|
||||
expect(filterCells(cells1, '.selected'), 'to equal', []);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('can be updated with setOptions()', function () {
|
||||
const drp = new DateRangePicker(elem);
|
||||
drp.setOptions({allowOneSidedRange: true});
|
||||
|
||||
input0.value = '02/11/2020';
|
||||
simulant.fire(input0, 'keydown', {key: 'Enter'});
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 11), undefined]);
|
||||
|
||||
drp.setDates({clear: true}, '02/11/2020');
|
||||
expect(drp.dates, 'to equal', [undefined, dateValue(2020, 1, 11)]);
|
||||
|
||||
drp.setOptions({allowOneSidedRange: false});
|
||||
|
||||
input1.value = '02/20/2020';
|
||||
simulant.fire(input1, 'keydown', {key: 'Enter'});
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 20), dateValue(2020, 1, 20)]);
|
||||
|
||||
drp.setDates({clear: true});
|
||||
expect(drp.dates, 'to equal', [undefined, undefined]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('pickLevel', function () {
|
||||
it('changes the span of range selection to 1st of a month → last day of a month when 1', function () {
|
||||
input0.value = '2/14/2020';
|
||||
input1.value = '2/14/2020';
|
||||
|
||||
const {drp, picker0, picker1} = createDRP(elem, {pickLevel: 1});
|
||||
const viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
const viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
let cells0 = getCells(picker0);
|
||||
let cells1 = getCells(picker1);
|
||||
|
||||
input0.focus();
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 1, 1), dateValue(2020, 1, 29)]);
|
||||
expect(input0.value, 'to be', '02/01/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells0, '.focused'), 'to equal', [1]);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '02/29/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells1, '.focused'), 'to equal', [1]);
|
||||
|
||||
// mouse operation
|
||||
cells0[0].click();
|
||||
cells1[6].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 0, 1), dateValue(2020, 6, 31)]);
|
||||
expect(input0.value, 'to be', '01/01/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [0]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [0]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', [6]);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '07/31/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [6]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [0]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [6]);
|
||||
|
||||
// api call
|
||||
drp.setDates('2/14/2021', '3/14/2020');
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 2, 1), dateValue(2021, 1, 28)]);
|
||||
expect(input0.value, 'to be', '03/01/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', '2020');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', []);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '02/28/2021');
|
||||
expect(viewSwitch1.textContent, 'to be', '2021');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', []);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [1]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
|
||||
it('changes the span of range selection to Jan 1st of a month → Dec 31st of a month when 2', function () {
|
||||
input0.value = '2/14/2020';
|
||||
input1.value = '2/14/2020';
|
||||
|
||||
const {drp, picker0, picker1} = createDRP(elem, {pickLevel: 2});
|
||||
const viewSwitch0 = picker0.querySelector('.view-switch');
|
||||
const viewSwitch1 = picker1.querySelector('.view-switch');
|
||||
let cells0 = getCells(picker0);
|
||||
let cells1 = getCells(picker1);
|
||||
|
||||
input0.focus();
|
||||
expect(drp.dates, 'to equal', [dateValue(2020, 0, 1), dateValue(2020, 11, 31)]);
|
||||
expect(input0.value, 'to be', '01/01/2020');
|
||||
expect(viewSwitch0.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells0, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells0, '.focused'), 'to equal', [1]);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '12/31/2020');
|
||||
expect(viewSwitch1.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [1]);
|
||||
expect(getCellIndices(cells1, '.range'), 'to equal', []);
|
||||
expect(getCellIndices(cells1, '.focused'), 'to equal', [1]);
|
||||
|
||||
// mouse operation
|
||||
cells0[0].click();
|
||||
cells1[3].click();
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2019, 0, 1), dateValue(2022, 11, 31)]);
|
||||
expect(input0.value, 'to be', '01/01/2019');
|
||||
expect(viewSwitch0.textContent, 'to be', '2010-2019');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [10]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [10]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', []);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '12/31/2022');
|
||||
expect(viewSwitch1.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [3]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [0]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [3]);
|
||||
|
||||
// api call
|
||||
drp.setDates('2/14/2025', '3/14/2021');
|
||||
|
||||
expect(drp.dates, 'to equal', [dateValue(2021, 0, 1), dateValue(2025, 11, 31)]);
|
||||
expect(input0.value, 'to be', '01/01/2021');
|
||||
expect(viewSwitch0.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells0, '.selected'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells0, '.range-start'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells0, '.range-end'), 'to equal', [6]);
|
||||
|
||||
input1.focus();
|
||||
expect(input1.value, 'to be', '12/31/2025');
|
||||
expect(viewSwitch1.textContent, 'to be', '2020-2029');
|
||||
expect(getCellIndices(cells1, '.selected'), 'to equal', [6]);
|
||||
expect(getCellIndices(cells1, '.range-start'), 'to equal', [2]);
|
||||
expect(getCellIndices(cells1, '.range-end'), 'to equal', [6]);
|
||||
|
||||
drp.destroy();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user