-
-
Notifications
You must be signed in to change notification settings - Fork 334
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
Add unit tests for Select component #812
Conversation
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.
@HenryRocha Thank you, the PR looks great!
I would recommend adding more tests for:
- The dropdown list highlights the currently selected option
- Keyboard and ARIA functions
- Movement through list using up and down arrows
- Selection by using enter
- Hiding the dropdown using esc
- The list scrolls automatically to display the currently selected option
I think we can merge this PR first and a new PR can be raised with these tests.
I'll also defer to @seancolsen and @mr-gabe49 (he built this Select component) for their comments, if they have any.
mathesar_ui/src/component-library/select/__meta__/Select.test.ts
Outdated
Show resolved
Hide resolved
@pavish thank you! I'll wait until the creators of the component give their opinions before working on more tests then. In the mean time, I'll try fixing the test to check if currently selected option updates correctly. |
@HenryRocha This looks great! Thanks for your work! @pavish comments have everything covered. |
- Fix test: updates currently selected option - Add test for: dropdown list highlights the currently selected option - Add test for: movement through list using up and down arrows - Add test for: selection by using enter - Add test for: hiding the dropdown using esc
@pavish I've added a few more tests, covering most of the one you mentioned:
One observation: I tried using Also, I looked around to see if it was possible to see what was being displayed, in order to check if the list scrolls automatically to display the currently selected option, but I could not find anything, so I left that test out. Any tips on how to approach this would be appreciated. Please review the new tests and if they're enough, or if I missed anything. |
The KeyPress event is deprecated and the Select component does not handle it.
I think it's okay to use fire only keyDown and keyUp for the tests.
The testing library does not offer an option to do that (In all fairness, it is incredibly hard/impossible to implement a generic method by just being able to read the DOM). We can test that for our particular usecase by reading the
|
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.
@HenryRocha This looks great! I only have a couple minor comments.
Regarding the test case for 'The list scrolls automatically to display the currently selected option', please feel free to decide whether you'd like to include it in this PR or take it up separately. I am okay with merging this PR without it.
mathesar_ui/src/component-library/select/__meta__/Select.test.ts
Outdated
Show resolved
Hide resolved
mathesar_ui/src/component-library/select/__meta__/Select.test.ts
Outdated
Show resolved
Hide resolved
- Group class checks into one call - Replace queryByText by queryByRole
@pavish I've fixed the issues you mentioned and merged in the new changes from As for the missing tests, I'd say merge the current changes and we'll take up the missing tests in another PR. |
Is this ready for re-review? If so, please re-request review via the button next to @pavish 's username. |
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.
@HenryRocha This PR looks great to me!
Related to #376
Add unit tests for Select component.
Technical details
Add test checking if the trigger button is rendered with the correct text.
Add test to check if custom classes and primary appearance are applied correctly.
Add test to check if all options are rendered.
Add test to check if currently selected option updates correctly. (Not working)
Observations:
The last test, which checks if the selected option updates correctly, is not working. Not sure if it should be working or if we need to mock the function which updates the selected value. Some help would be very welcome.
Also, please check if these tests are enough or if I missed anything.
Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin
Henry Rocha