-
Notifications
You must be signed in to change notification settings - Fork 210
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) O3-3853: Add Unit Tests for Datepicker Component #1130
base: main
Are you sure you want to change the base?
Conversation
Hi @NethmiRodrigo, requesting your review here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this up @sachithasamadhib! Some suggestions to the test cases, also please check your test cases which are failing
|
||
it('renders without crashing', () => { | ||
render(<OpenmrsDatePicker />); | ||
expect(screen.getByRole('button')).toBeInTheDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could make this slightly more comprehensive to check if the input field is there and if the calendar grid appears when we click on the calendar icon and expect the month and year on the calendar grid's header to be the current month and year of the locale (we should probably test this for different locales). @ibacher what do you think?
it('calls onChange handler with the correct date', () => { | ||
const onChangeMock = jest.fn(); | ||
render(<OpenmrsDatePicker onChange={onChangeMock} />); | ||
fireEvent.click(screen.getByRole('button')); | ||
const dateToSelect = screen.getByText('15'); | ||
fireEvent.click(dateToSelect); | ||
|
||
expect(onChangeMock).toHaveBeenCalled(); | ||
const selectedDate = new Date(onChangeMock.mock.calls[0][0]); | ||
expect(selectedDate.getDate()).toBe(15); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is testing by clicking on a date on the calendar, if so we should probably assert the month and year as well
const maxDate = new Date(2023, 11, 31); | ||
render(<OpenmrsDatePicker minDate={minDate} maxDate={maxDate} />); | ||
|
||
fireEvent.click(screen.getByRole('button')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use userEvent
instead in all the places. Read why - https://ph-fritsche.github.io/blog/post/why-userevent
Ya,sure @NethmiRodrigo I will check the test cases which are failing. |
Hi @sachithasamadhib, Would it be possible for you to also include a mock implementation for the component? That would be really helpful. i.e to avoid this Thanks again! |
@sachithasamadhib are you still working on this? Is it clear to you how to move forward with it? |
yes @brandones I'am still working on this. |
Ping @sachithasamadhib , could you please provide an estimated timeline for when you will get this done? It is not kind to tell people on a project you are going to do something and then leave it hanging for a month. Please let us know if you'll be doing it, or if you need help, or if someone else should take it. Thanks. |
ticket: https://openmrs.atlassian.net/browse/O3-3853
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
The Datepicker component is now integrated with unit tests with including edge cases and error handling to verify its functionality (ticket: https://openmrs.atlassian.net/browse/O3-3853).
Screenshots
Related Issue
Other