Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make keyboard tests more reliable (#3793) (CP: 23.0) #3797

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/date-picker/test/keyboard-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.initialPosition = initialDate;
await nextRender(overlay);
await overlay.focusDate(initialDate);
await waitForScrollToFinish(overlay);
});

it('should focus one week forward with arrow down', async () => {
Expand Down Expand Up @@ -165,12 +166,14 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT

it(`should focus one day ${isRTL ? 'backward' : 'forward'} with arrow 'right'`, async () => {
await sendKeys({ press: 'ArrowRight' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(isRTL ? new Date(1999, 11, 31) : new Date(2000, 0, 2));
});

it(`should focus one day ${isRTL ? 'forward' : 'backward'} with arrow left`, async () => {
await sendKeys({ press: 'ArrowLeft' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(isRTL ? new Date(2000, 0, 2) : new Date(1999, 11, 31));
});
Expand All @@ -197,6 +200,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
it('should select a date with space', async () => {
await sendKeys({ press: 'ArrowRight' });
await sendKeys({ press: 'Space' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(2000, 0, 2));
});
Expand All @@ -209,12 +213,14 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
it('should focus first day of the month with home', async () => {
await sendKeys({ press: 'ArrowLeft' });
await sendKeys({ press: 'Home' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 1));
});

it('should focus last day of the month with end', async () => {
await sendKeys({ press: 'End' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(2000, 0, 31));
});
Expand All @@ -235,7 +241,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT

it('should not skip a month', async () => {
await overlay.focusDate(new Date(2000, 0, 31));
await nextRender(overlay);
await waitForScrollToFinish(overlay);
await sendKeys({ press: 'PageDown' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
Expand All @@ -244,7 +250,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT

it('should focus the previously focused date number if available', async () => {
await overlay.focusDate(new Date(2000, 0, 31));
await nextRender(overlay);
await waitForScrollToFinish(overlay);
await sendKeys({ press: 'PageDown' });
await sendKeys({ press: 'PageDown' });
await waitForScrollToFinish(overlay);
Expand Down Expand Up @@ -331,27 +337,31 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.minDate = new Date(1999, 11, 3);
await sendKeys({ down: 'ArrowLeft' });
await sendKeys({ down: 'Home' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 3));
});

it('should focus max date with end', async () => {
overlay.maxDate = new Date(2000, 0, 26);
await sendKeys({ down: 'End' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(2000, 0, 26));
});

it('should focus max date with pagedown', async () => {
overlay.maxDate = new Date(2000, 0, 28);
await sendKeys({ press: 'PageDown' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(2000, 0, 28));
});

it('should focus min date with pageup', async () => {
overlay.minDate = new Date(1999, 11, 3);
await sendKeys({ press: 'PageUp' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 3));
});
Expand Down Expand Up @@ -384,8 +394,8 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.focusedDate = new Date(1999, 5, 10);
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);

await sendKeys({ press: 'PageUp' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -394,8 +404,8 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.focusedDate = new Date(1999, 5, 10);
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);

await sendKeys({ press: 'PageDown' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand Down Expand Up @@ -432,6 +442,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.focusedDate = new Date(1999, 5, 10);
overlay.minDate = new Date(1999, 11, 25);
await sendKeys({ press: 'Home' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -440,6 +451,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.focusedDate = new Date(1999, 5, 10);
overlay.minDate = new Date(1999, 11, 25);
await sendKeys({ press: 'End' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -449,6 +461,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);
await sendKeys({ press: 'ArrowUp' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -458,6 +471,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);
await sendKeys({ press: 'ArrowDown' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -467,6 +481,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);
await sendKeys({ press: 'ArrowLeft' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand All @@ -476,6 +491,7 @@ import { getDefaultI18n, getFocusedCell, getOverlayContent, open, waitForScrollT
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);
await sendKeys({ press: 'ArrowRight' });
await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
expect(cell.date).to.eql(new Date(1999, 11, 25));
});
Expand Down