123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803 |
- describe('options - date restrictions', function () {
- const getDisabled = cells => filterCells(cells, '.disabled').map(el => [el, el.textContent]);
- let input;
- beforeEach(function () {
- input = document.createElement('input');
- testContainer.appendChild(input);
- });
- afterEach(function () {
- testContainer.removeChild(input);
- });
- describe('datesDisabled', function () {
- let clock;
- beforeEach(function () {
- clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
- });
- afterEach(function () {
- clock.restore();
- });
- it('specifies unselectable dates', function () {
- const dp = new Datepicker(input, {
- datesDisabled: [new Date(2020, 1, 12), '2/13/2020', new Date(2020, 1, 13), '2/20/2020'],
- });
- const picker = document.querySelector('.datepicker');
- dp.show();
- expect(picker.querySelector('.prev-btn').disabled, 'to be false');
- expect(picker.querySelector('.next-btn').disabled, 'to be false');
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[17], '12'],
- [cells[18], '13'],
- [cells[25], '20'],
- ]);
- cells[17].click();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- dp.setDate(new Date(2020, 1, 12));
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- input.value = '2/12/2020';
- dp.update();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '2/12/2020');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- cells[16].click();
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 11)]);
- expect(input.value, 'to be', '02/11/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[16]]);
- dp.enterEditMode();
- input.value = '2/12/2020';
- simulant.fire(input, 'keydown', {key: 'Enter'});
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 11)]);
- expect(input.value, 'to be', '2/12/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[16]]);
- dp.destroy();
- });
- it('makes the picker prevent those dates becoming view date', function () {
- const dp = new Datepicker(input, {
- datesDisabled: ['2/11/2020', '2/12/2020', '2/13/2020', '2/20/2020'],
- });
- const picker = document.querySelector('.datepicker');
- const cells = getCells(picker);
- dp.show();
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[15]]);
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- // on 5th
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- // on 27th
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
- // on 19th
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[15]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- // on 4th
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- dp.destroy();
- });
- it('can be updated with setOptions()', function () {
- const {dp, picker} = createDP(input);
- dp.setOptions({datesDisabled: [new Date(2020, 1, 11), new Date(2020, 1, 26)]});
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[16], '11'],
- [cells[31], '26'],
- ]);
- dp.setOptions({datesDisabled: []});
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', []);
- dp.destroy();
- });
- });
- describe('daysOfWeekDisabled', function () {
- let clock;
- beforeEach(function () {
- clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
- });
- afterEach(function () {
- clock.restore();
- });
- it('specifies unselectable days of week', function () {
- const {dp, picker} = createDP(input, {daysOfWeekDisabled: [0, 6]});
- dp.show();
- expect(picker.querySelector('.prev-btn').disabled, 'to be false');
- expect(picker.querySelector('.next-btn').disabled, 'to be false');
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], '26'],
- [cells[6], '1'],
- [cells[7], '2'],
- [cells[13], '8'],
- [cells[14], '9'],
- [cells[20], '15'],
- [cells[21], '16'],
- [cells[27], '22'],
- [cells[28], '23'],
- [cells[34], '29'],
- [cells[35], '1'],
- [cells[41], '7'],
- ]);
- cells[14].click();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- dp.setDate(new Date(2020, 1, 9));
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- input.value = '2/9/2020';
- dp.update();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '2/9/2020');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- cells[15].click();
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 10)]);
- expect(input.value, 'to be', '02/10/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[15]]);
- dp.enterEditMode();
- input.value = '2/9/2020';
- simulant.fire(input, 'keydown', {key: 'Enter'});
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 10)]);
- expect(input.value, 'to be', '2/9/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[15]]);
- dp.destroy();
- });
- it('makes the picker prevent those dates becoming view date', function () {
- const {dp, picker} = createDP(input, {daysOfWeekDisabled: [0, 6]});
- const cells = getCells(picker);
- dp.show();
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[22]]);
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- // on 7th
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[15]]);
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[12]]);
- dp.destroy();
- });
- it('can be updated with setOptions()', function () {
- const {dp, picker} = createDP(input);
- dp.setOptions({daysOfWeekDisabled: [4]});
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[4], '30'],
- [cells[11], '6'],
- [cells[18], '13'],
- [cells[25], '20'],
- [cells[32], '27'],
- [cells[39], '5'],
- ]);
- dp.setOptions({daysOfWeekDisabled: []});
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', []);
- dp.destroy();
- });
- });
- describe('maxDate', function () {
- let clock;
- beforeEach(function () {
- clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
- });
- afterEach(function () {
- clock.restore();
- });
- it('specifies the maximum selectable date', function () {
- const {dp, picker} = createDP(input, {maxDate: new Date(2020, 1, 25)});
- const viewSwitch = getViewSwitch(picker);
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[31], '26'],
- [cells[32], '27'],
- [cells[33], '28'],
- [cells[34], '29'],
- [cells[35], '1'],
- [cells[36], '2'],
- [cells[37], '3'],
- [cells[38], '4'],
- [cells[39], '5'],
- [cells[40], '6'],
- [cells[41], '7'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[2], 'Mar'],
- [cells[3], 'Apr'],
- [cells[4], 'May'],
- [cells[5], 'Jun'],
- [cells[6], 'Jul'],
- [cells[7], 'Aug'],
- [cells[8], 'Sep'],
- [cells[9], 'Oct'],
- [cells[10], 'Nov'],
- [cells[11], 'Dec'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[2], '2021'],
- [cells[3], '2022'],
- [cells[4], '2023'],
- [cells[5], '2024'],
- [cells[6], '2025'],
- [cells[7], '2026'],
- [cells[8], '2027'],
- [cells[9], '2028'],
- [cells[10], '2029'],
- [cells[11], '2030'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[4], '2030'],
- [cells[5], '2040'],
- [cells[6], '2050'],
- [cells[7], '2060'],
- [cells[8], '2070'],
- [cells[9], '2080'],
- [cells[10], '2090'],
- [cells[11], '2100'],
- ]);
- dp.hide();
- dp.show();
- cells = getCells(picker);
- cells[31].click();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- dp.setDate(new Date(2020, 1, 26));
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- input.value = '2/26/2020';
- dp.update();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '2/26/2020');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- cells[30].click();
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 25)]);
- expect(input.value, 'to be', '02/25/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[30]]);
- dp.enterEditMode();
- input.value = '2/26/2020';
- simulant.fire(input, 'keydown', {key: 'Enter'});
- expect(dp.dates, 'to equal', [dateValue(2020, 1, 25)]);
- expect(input.value, 'to be', '2/26/2020');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[30]]);
- dp.destroy();
- });
- it('makes the picker disallow to navigate to after the max date', function () {
- const {dp, picker} = createDP(input, {maxDate: '2/14/2020'});
- const [viewSwitch, prevBtn, nextBtn] = getParts(picker, ['.view-switch', '.prev-btn', '.next-btn']);
- dp.show();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be true');
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- let cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[13]]);
- prevBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to Jan 22nd
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- nextBtn.click();
- // view date is limited to the max date
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- // the same goes for ctrl + ArrowRight key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
- // months view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be true');
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- // on prev year's Nov
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[10]]);
- prevBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to Mar
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- nextBtn.click();
- // view date is limited to the Feb
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- // the same goes for ctrl + ArrowRight key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- // years view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be true');
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- // on 2017
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[8]]);
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- prevBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to 2011
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- nextBtn.click();
- // view year is limited to 2020
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- // the same goes for ctrl + ArrowRight key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
- // decades view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be true');
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- // on 1990
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[10]]);
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- prevBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to 1930
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- nextBtn.click();
- // view decade is limited to 2020
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- // the same goes for ctrl + ArrowRight key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- dp.destroy();
- });
- it('can be updated with setOptions()', function () {
- const {dp, picker} = createDP(input);
- dp.setOptions({maxDate: new Date(2020, 1, 28)});
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[34], '29'],
- [cells[35], '1'],
- [cells[36], '2'],
- [cells[37], '3'],
- [cells[38], '4'],
- [cells[39], '5'],
- [cells[40], '6'],
- [cells[41], '7'],
- ]);
- dp.setOptions({maxDate: null});
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', []);
- dp.destroy();
- });
- });
- describe('minDate', function () {
- let clock;
- beforeEach(function () {
- clock = sinon.useFakeTimers({now: new Date(2022, 6, 14)});
- });
- afterEach(function () {
- clock.restore();
- });
- it('specifies the minimum selectable date', function () {
- const {dp, picker} = createDP(input, {minDate: new Date(2022, 6, 4)});
- const viewSwitch = getViewSwitch(picker);
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], '26'],
- [cells[1], '27'],
- [cells[2], '28'],
- [cells[3], '29'],
- [cells[4], '30'],
- [cells[5], '1'],
- [cells[6], '2'],
- [cells[7], '3'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], 'Jan'],
- [cells[1], 'Feb'],
- [cells[2], 'Mar'],
- [cells[3], 'Apr'],
- [cells[4], 'May'],
- [cells[5], 'Jun'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], '2019'],
- [cells[1], '2020'],
- [cells[2], '2021'],
- ]);
- viewSwitch.click();
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], '1990'],
- [cells[1], '2000'],
- [cells[2], '2010'],
- ]);
- dp.hide();
- dp.show();
- cells = getCells(picker);
- cells[7].click();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- dp.setDate(new Date(2022, 6, 3));
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- input.value = '7/3/2022';
- dp.update();
- expect(dp.dates, 'to equal', []);
- expect(input.value, 'to be', '7/3/2022');
- expect(filterCells(cells, '.selected'), 'to equal', []);
- cells[8].click();
- expect(dp.dates, 'to equal', [dateValue(2022, 6, 4)]);
- expect(input.value, 'to be', '07/04/2022');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[8]]);
- dp.enterEditMode();
- input.value = '7/3/2022';
- simulant.fire(input, 'keydown', {key: 'Enter'});
- expect(dp.dates, 'to equal', [dateValue(2022, 6, 4)]);
- expect(input.value, 'to be', '7/3/2022');
- expect(filterCells(cells, '.selected'), 'to equal', [cells[8]]);
- dp.destroy();
- });
- it('makes the picker disallow to navigate to before the min date', function () {
- const {dp, picker} = createDP(input, {minDate: '7/14/2022'});
- const [viewSwitch, prevBtn, nextBtn] = getParts(picker, ['.view-switch', '.prev-btn', '.next-btn']);
- dp.show();
- expect(prevBtn.disabled, 'to be true');
- expect(nextBtn.disabled, 'to be false');
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- let cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
- simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
- nextBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to Aug 13th
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- prevBtn.click();
- // view date is limited to min date
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
- // the same goes for ctrl + ArrowLeft key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
- // months view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be true');
- expect(nextBtn.disabled, 'to be false');
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- // on Oct
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[9]]);
- nextBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to Jun
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- prevBtn.click();
- // view date is limited to Jul
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
- // the same goes for ctrl + ArrowLeft key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
- // years view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be true');
- expect(nextBtn.disabled, 'to be false');
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- // on 2025
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- nextBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to 2031
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- prevBtn.click();
- // view year is limited to 2022
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- // the same goes for ctrl + ArrowLeft key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- // decades view
- viewSwitch.click();
- expect(prevBtn.disabled, 'to be true');
- expect(nextBtn.disabled, 'to be false');
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- simulant.fire(input, 'keydown', {key: 'ArrowDown'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- // on 2050
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
- simulant.fire(input, 'keydown', {key: 'ArrowRight'});
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- nextBtn.click();
- expect(prevBtn.disabled, 'to be false');
- expect(nextBtn.disabled, 'to be false');
- // move to 2110
- simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
- prevBtn.click();
- // view decade is limited to 2020
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- // the same goes for ctrl + ArrowLeft key
- prevBtn.click();
- simulant.fire(input, 'keydown', {key: 'ArrowUp'});
- simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
- cells = getCells(picker);
- expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
- dp.destroy();
- });
- it('can be updated with setOptions()', function () {
- const {dp, picker} = createDP(input);
- dp.setOptions({minDate: new Date(2022, 6, 2)});
- dp.show();
- let cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', [
- [cells[0], '26'],
- [cells[1], '27'],
- [cells[2], '28'],
- [cells[3], '29'],
- [cells[4], '30'],
- [cells[5], '1'],
- ]);
- dp.setOptions({minDate: null});
- cells = getCells(picker);
- expect(getDisabled(cells), 'to equal', []);
- dp.destroy();
- });
- });
- });
|