Skip to content

Commit

Permalink
fix(date-picker): update keyboard validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dethell committed Nov 15, 2023
1 parent 2268b6a commit 59750ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions packages/date-picker/test/keyboard-navigation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,14 @@ describe('keyboard navigation', () => {
await waitForScrollToFinish(datePicker._overlayContent);
expect(focusSpy.called).to.be.true;
let calledDate = focusSpy.firstCall.args[0];
expect(calledDate.toISOString().split('T')[0]).to.be.eql('2010-01-01');
let formattedDate = `${calledDate.getFullYear()}-${calledDate.getMonth() + 1}-${calledDate.getDate()}`;
expect(formattedDate).to.be.eql('2010-1-1');
// Attempt to move focus to the previous week and it should stay on the min date
await sendKeys({ press: 'ArrowUp' });
await waitForScrollToFinish(datePicker._overlayContent);
calledDate = focusSpy.secondCall.args[0];
expect(calledDate.toISOString().split('T')[0]).to.be.eql('2010-01-01');
formattedDate = `${calledDate.getFullYear()}-${calledDate.getMonth() + 1}-${calledDate.getDate()}`;
expect(formattedDate).to.be.eql('2010-1-1');
});

it('should not allow navigation beyond max', async () => {
Expand All @@ -580,12 +582,14 @@ describe('keyboard navigation', () => {
await waitForScrollToFinish(datePicker._overlayContent);
expect(focusSpy.called).to.be.true;
let calledDate = focusSpy.firstCall.args[0];
expect(calledDate.toISOString().split('T')[0]).to.be.eql('2010-01-31');
let formattedDate = `${calledDate.getFullYear()}-${calledDate.getMonth() + 1}-${calledDate.getDate()}`;
expect(formattedDate).to.be.eql('2010-1-31');
// Attempt to move focus to the previous week and it should stay on the min date
await sendKeys({ press: 'ArrowDown' });
await waitForScrollToFinish(datePicker._overlayContent);
calledDate = focusSpy.secondCall.args[0];
expect(calledDate.toISOString().split('T')[0]).to.be.eql('2010-01-31');
formattedDate = `${calledDate.getFullYear()}-${calledDate.getMonth() + 1}-${calledDate.getDate()}`;
expect(formattedDate).to.be.eql('2010-1-31');
});

it('should allow navigation on a disabled date', async () => {
Expand All @@ -598,7 +602,8 @@ describe('keyboard navigation', () => {
await waitForScrollToFinish(datePicker._overlayContent);
expect(focusSpy.called).to.be.true;
const calledDate = focusSpy.firstCall.args[0];
expect(calledDate.toISOString().split('T')[0]).to.be.eql('2010-01-29');
const formattedDate = `${calledDate.getFullYear()}-${calledDate.getMonth() + 1}-${calledDate.getDate()}`;
expect(formattedDate).to.be.eql('2010-1-29');
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/date-picker/test/month-calendar.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ describe('vaadin-month-calendar', () => {
expect(date.getFullYear()).to.equal(month.getFullYear());
});

it('should not update value on disabled date tap', async () => {
it('should not update value on disabled-by-max date tap', async () => {
monthCalendar.maxDate = new Date('2016-02-09');
await nextRender();
const date10 = getDateCells(monthCalendar).find((dateElement) => dateElement.date.getDate() === 10);
tap(date10);
expect(monthCalendar.selectedDate).to.be.undefined;
});

it('should update value on disabled-by-function date tap', () => {
monthCalendar.isDateDisabled = (date) => {
if (!date) {
return false;
Expand All @@ -143,7 +145,6 @@ describe('vaadin-month-calendar', () => {
};
const date9 = getDateCells(monthCalendar).find((dateElement) => dateElement.date.getDate() === 9);
tap(date9);

expect(monthCalendar.selectedDate).to.be.undefined;
});

Expand Down

0 comments on commit 59750ee

Please sign in to comment.