-
Notifications
You must be signed in to change notification settings - Fork 224
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
EDSC-4076: Integrate a linter for react-testing-library before the number of those gets too large in EDSC #1844
base: main
Are you sure you want to change the base?
Conversation
ad1ea9e
to
ee6b87b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1844 +/- ##
==========================================
- Coverage 93.81% 93.80% -0.02%
==========================================
Files 777 777
Lines 18867 18869 +2
Branches 4867 4869 +2
==========================================
- Hits 17701 17700 -1
- Misses 1090 1094 +4
+ Partials 76 75 -1 ☔ View full report in Codecov by Sentry. |
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 do need to figure out why code-cov is missing some files
"static/src/js/**/*.js" | ||
], | ||
"rules": { | ||
"testing-library/await-async-events": "off", |
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.
Should these be done in the linter package? otherwise EDSC might have a different setup than say MMT. Some of these feel like they aren't bad to ignore though I understand that it would make this PR even larger some comments on why we're doing these would be good to have though
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 that is the point of the eslintrc, not all repos will want this, we need to exclude tests that haven't been converted from enzyme etc.
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.
Add a comment explaining why these rules are being ignored
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 could use a little background as to why all of these rules are being ignored. A comment explaining might be enough 😄
870f22b
to
aa84425
Compare
"static/src/js/**/*.js" | ||
], | ||
"rules": { | ||
"testing-library/await-async-events": "off", |
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.
Add a comment explaining why these rules are being ignored
@@ -28,8 +28,8 @@ const setup = () => { | |||
|
|||
describe('CollapsePanel component', () => { | |||
test('renders itself correctly', () => { | |||
const { container } = setup() | |||
expect(container.firstChild).toHaveClass('collapse-panel test-wrap-class') | |||
setup() |
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.
If no other tests are using the container, don't set it on line 19 and return it on line 22
@@ -1,3 +1,5 @@ | |||
/* eslint-disable testing-library/no-node-access */ |
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.
Why are these rules ignored? Does the eslintrc rules cover them, or do they need to be addressed?
If they do have to be ignored, we should use the // eslint-disable-next-line
syntax only on the lines that need it. In general this means we don't accidentally write code in a file that gets ignored but could have been fixable
@@ -55,6 +55,7 @@ const Facets = (props) => { | |||
featuresFacet.children.push({ | |||
applied: featureFacets.customizable, | |||
title: 'Customizable', | |||
'data-testid': 'customizable-info', |
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 this being used in the tests?
@@ -101,8 +103,15 @@ export const GranuleResultsDownloadNotebookButton = ({ | |||
<Dropdown.Menu | |||
ref={dropdownMenuRef} | |||
className="granule-results-download-notebook-button__menu" | |||
data-testid="dropdown-menu" |
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 avoid using test ids. In this example I don't think it is necessary
const dropdownMenu = screen.getByTestId('dropdown-menu')
const downloadButton = within(dropdownMenu).getByRole('button', { name: 'Download Notebook' })
Does screen.getByRole('button', { name: 'Download Notebook' })
work without needing the test id?
const images = within(modal).queryAllByTestId('mock-edsc-image') | ||
const pagination = within(modal).queryByText('2/2') | ||
images = within(modal).queryAllByTestId('mock-edsc-image') | ||
pagination = within(modal).queryByText('2/2') |
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 this line should also be moved below the waitFor
@@ -1,3 +1,4 @@ | |||
/* eslint-disable testing-library/no-unnecessary-act */ |
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 this covered by eslintrc? If not, use // eslint-disable-next-line
instead of disabling for the whole file
@@ -135,6 +135,9 @@ export class PanelItem extends Component { | |||
if (scrollable) { | |||
return ( | |||
<SimpleBar | |||
data-testid="simplebar-content-wrapper" |
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.
This doesn't seem necessary with both a role and a label on the component
@@ -51,22 +51,25 @@ export const projectHeader = [ | |||
top: 6, | |||
height: 12, | |||
width: 80, | |||
radius: 2 | |||
radius: 2, | |||
'data-testid': 'skeleton-item' |
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.
Are these being used?
expect(screen.queryByLabelText('Start')).not.toBeInTheDocument() | ||
}) | ||
|
||
test('when clicked toggles the state of show ', async () => { | ||
const user = userEvent.setup() | ||
const { click } = userEvent.setup() |
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.
Not sure why this change was made. But one thing we've done in other repos is call userEvent.setup()
first in the setup
function, then return the user
object. So the test ends up looking like this const { user } = setup({})
. That avoids having userEvent.setup()
called 18 times in this file
Overview
What is the feature?
Adds react testing library eslint plugin to edsc
What is the Solution?
Added edsc specific configs to the lint config, the shared linter config updated version, and updated all the tests that were experiencing new linter errors
What areas of the application does this impact?
Component tests that use react testing library.
Testing
Reproduction steps
npm run lint
Attachments
Please include relevant screenshots or files that would be helpful in reviewing and verifying this change.
Checklist