-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: verify date input only on blur on calendar input, close calenda…
…r popup on blur as well
- Loading branch information
Showing
6 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
components/calendar/src/calendar-input/__tests__/calendar-input.test.js
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,54 @@ | ||
import { fireEvent, render, waitFor, within } from '@testing-library/react' | ||
import React from 'react' | ||
import { CalendarInput } from '../calendar-input.js' | ||
|
||
describe('Calendar Input', () => { | ||
it('allow selection of a date through the calendar widget', async () => { | ||
const onDateSelectMock = jest.fn() | ||
const screen = render( | ||
<CalendarInput calendar="gregory" onDateSelect={onDateSelectMock} /> | ||
) | ||
|
||
const dateInput = within( | ||
screen.getByTestId('dhis2-uicore-input') | ||
).getByRole('textbox') | ||
fireEvent.focus(dateInput) | ||
const calendar = await screen.findByTestId('calendar') | ||
expect(calendar).toBeInTheDocument() | ||
|
||
const todayString = new Date().toISOString().slice(0, -14) | ||
const today = within(calendar).getByTestId(todayString) | ||
|
||
fireEvent.click(today) | ||
|
||
await waitFor(() => { | ||
expect(calendar).not.toBeInTheDocument() | ||
}) | ||
expect(onDateSelectMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
calendarDateString: todayString, | ||
}) | ||
) | ||
}) | ||
|
||
it('allow selection of a date through the input', async () => { | ||
const onDateSelectMock = jest.fn() | ||
const screen = render( | ||
<CalendarInput calendar="gregory" onDateSelect={onDateSelectMock} /> | ||
) | ||
|
||
const dateInputString = '2024/10/12' | ||
const dateInput = within( | ||
screen.getByTestId('dhis2-uicore-input') | ||
).getByRole('textbox') | ||
|
||
fireEvent.change(dateInput, { target: { value: dateInputString } }) | ||
fireEvent.blur(dateInput) | ||
|
||
expect(onDateSelectMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
calendarDateString: dateInputString, | ||
}) | ||
) | ||
}) | ||
}) |
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
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
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