-
Notifications
You must be signed in to change notification settings - Fork 69
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
chore: move autosuggest tests from Enzyme to RTL #2611
chore: move autosuggest tests from Enzyme to RTL #2611
Conversation
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
47739c5
to
71bc0ae
Compare
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #2611 +/- ##
==========================================
+ Coverage 91.72% 91.88% +0.16%
==========================================
Files 235 235
Lines 4217 4214 -3
Branches 1020 1021 +1
==========================================
+ Hits 3868 3872 +4
+ Misses 345 338 -7
Partials 4 4
☔ View full report in Codecov by Sentry. |
@@ -13,7 +13,7 @@ function FormAutosuggestOption({ | |||
<MenuItem | |||
as="li" | |||
role="option" | |||
tabindex="-1" |
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.
good catch!
it('renders component with options', () => { | ||
const { getByTestId, container } = render(<FormAutosuggestTestComponent />); | ||
const input = getByTestId('autosuggest_textbox_input'); | ||
fireEvent.click(input); |
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.
[curious] Is there a reason to use fireEvent
here (and elsewhere throughout the tests) versus using userEvent
?
If it's possible to use userEvent.click
instead, it's generally preferable since it simulates more of the true user interactions in the browser, not just the low-level click itself.
For example, userEvent.click
also simulates a previous hover
event that a real user would trigger prior to clicking.
Resources:
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.
}); | ||
it('renders without loading state', () => { | ||
const { container } = render(<FormAutosuggestTestComponent />); | ||
expect(container.querySelector('.pgn__form-autosuggest__dropdown-loading')).toBeNull(); |
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.
Is there a way to avoid using the class name implementation detail in this test?
For example, if the component renders a Spinner
with the supplied screenReaderText
prop, could this test assert that the Spinner
is not rendered based on a data-testid
attribute versus relying on the class name that could change at any time. If the class name did change down the road, this test would still pass.
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.
const wrapper = mount(<FormAutosuggestWrapper value="Test Value" />); | ||
it('render with loading state', () => { | ||
const { container } = render(<FormAutosuggestWrapper isLoading />); | ||
expect(container.querySelector('.pgn__form-autosuggest__dropdown-loading')).toBeTruthy(); |
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.
Similar to above comment, could we either assert that the screenReaderText
passed to the Spinner
is rendered, or alternatively, rely on a more stable data-testid
instead of the class name?
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.
6c9a96e
to
0248452
Compare
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.
LGTM!
So the current failing test is the error state test. It was written by having the simulated user enter the textbox and press escape. This worked before 4816baa#diff-96e13c1a773ec8d218ea5667d3dec6c8f6eeadcb00c81584f50d6c3d4d52135fL133, but now that doesn't trigger the error state. It should probably be updated to simulate a click outside, as that will still trigger the error state (I verified on https://paragon-openedx.netlify.app/components/form/form-autosuggest/) |
0248452
to
ba5085a
Compare
Co-authored-by: Mena Hassan <[email protected]>
ba5085a
to
33fb35b
Compare
|
@@ -102,6 +102,7 @@ function FormAutosuggest({ | |||
const iconToggle = ( | |||
<IconButton | |||
className="pgn__form-autosuggest__icon-button" | |||
data-testid="autosuggest_iconbutton" |
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 recently rewrote all tests (except FormAutosuggest
) to RTL. For uniformity of test identifiers, we agreed to use a kebab case. Can you convert the names of the identifiers to a uniform format? autosuggest-iconbutton
@@ -253,7 +255,7 @@ function FormAutosuggest({ | |||
> | |||
{isLoading ? ( | |||
<div className="pgn__form-autosuggest__dropdown-loading"> | |||
<Spinner animation="border" variant="dark" screenReaderText={screenReaderText} /> | |||
<Spinner animation="border" variant="dark" screenReaderText={screenReaderText} data-testid="autosuggest_loading_spinner" /> |
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.
Maybe more readable
<Spinner animation="border" variant="dark" screenReaderText={screenReaderText} data-testid="autosuggest_loading_spinner" /> | |
<Spinner | |
animation="border" | |
variant="dark" | |
screenReaderText={screenReaderText} | |
data-testid="autosuggest-loading-spinner" | |
/> |
@@ -230,6 +231,7 @@ function FormAutosuggest({ | |||
onChange={handleOnChange} | |||
onClick={handleClick} | |||
trailingElement={iconToggle} | |||
data-testid="autosuggest_textbox_input" |
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.
data-testid="autosuggest_textbox_input" | |
data-testid="autosuggest-textbox-input" |
@@ -12,8 +12,9 @@ function FormAutosuggestOption({ | |||
return ( | |||
<MenuItem | |||
as="li" | |||
data-testid="autosuggest_optionitem" |
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.
data-testid="autosuggest_optionitem" | |
data-testid="autosuggest-optionitem" |
import PropTypes from 'prop-types'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; |
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.
Is it better to move this line to setupTests.js
? Did you encounter some problems with this?
@PKulkoRaccoonGang I'm sorry I was a bit hasty and didn't see these comments before hitting merge. We should be able to address them in a quick follow-up PR. |
🎉 This PR is included in version 21.1.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 22.0.0-alpha.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Move autosuggest tests from Enzyme to RTL
Deploy Preview
N/A
Merge Checklist
Post-merge Checklist