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) O3-3853: Add Unit Tests for Datepicker Component #1130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sachithasamadhib
Copy link

@sachithasamadhib sachithasamadhib commented Aug 29, 2024

ticket: https://openmrs.atlassian.net/browse/O3-3853

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

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

@vasharma05
Copy link
Member

vasharma05 commented Sep 19, 2024

Hi @NethmiRodrigo, requesting your review here.
Since DatePicker is critical to multiple use cases, let's try to cover every scenario.
Thanks @sachithasamadhib for taking the lead on this!

Copy link
Collaborator

@NethmiRodrigo NethmiRodrigo left a 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();
Copy link
Collaborator

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?

Comment on lines +20 to +29
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);
Copy link
Collaborator

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'));
Copy link
Collaborator

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

@sachithasamadhib
Copy link
Author

Ya,sure @NethmiRodrigo I will check the test cases which are failing.
Thank you for commenting and reviewing the PR .

@usamaidrsk
Copy link
Member

usamaidrsk commented Oct 10, 2024

Hi @sachithasamadhib,
Thank you for the great work on this!

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!
cc @NethmiRodrigo @denniskigen @pirupius

@brandones
Copy link
Collaborator

@sachithasamadhib are you still working on this? Is it clear to you how to move forward with it?

@brandones brandones changed the title (test) 03-3853: Add Unit Tests for Datepicker Component (test) O3-3853: Add Unit Tests for Datepicker Component Oct 21, 2024
@sachithasamadhib
Copy link
Author

@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.

@brandones
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants