-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44b2987
commit 46d9553
Showing
4 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/components/DatePicker/Month/hooks/__tests__/useMonthKeyboardNavigation.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks'; | ||
import React from 'react'; | ||
import useMonthKeyboardNavigation from '../useMonthKeyboardNavigation'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
|
||
// jest.mock('hooks/useKeyboardEvents', () => ({ | ||
// useKeyboardEvents: jest.fn(() => ({ keyboardProps: {} })), | ||
// })); | ||
|
||
describe('useMonthKeyboardNavigation', () => { | ||
it('should handle keyboard navigation correctly', () => { | ||
const selectedDays = { from: undefined, to: undefined }; | ||
const isFirstCalendar = true; | ||
const month = 8; // September (zero-based index) | ||
const year = 2023; | ||
|
||
const { result } = renderHook( | ||
() => useMonthKeyboardNavigation({ selectedDays, isFirstCalendar, month, year }) // Pass calendarRef | ||
); | ||
|
||
const { focusedDay } = result.current; | ||
|
||
const { container } = render( | ||
<div> | ||
<table ref={result.current.calendarRef} {...result.current.keyboardProps} /> | ||
<div tabIndex={0} /> | ||
<div tabIndex={0} /> | ||
<div tabIndex={0} /> | ||
</div> | ||
); | ||
|
||
// Simulate keyboard events | ||
act(() => { | ||
fireEvent.keyDown(container, { key: 'ArrowDown', code: 'ArrowDown' }); | ||
}); | ||
expect(result.current.focusedDay).toBe(focusedDay + 7); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters