chore(BackToTop) update tests to new standarts#7833
Conversation
|
Preview: https://patternfly-react-pr-7833.surge.sh A11y report: https://patternfly-react-pr-7833-a11y.surge.sh |
ba6cdad to
f615544
Compare
|
@wise-king-sullyman |
|
In the case of the |
|
@nicolethoen IMO yeah for anything that can be ascertained by grabbing the button with a For things that we need to grab the containing |
wise-king-sullyman
left a comment
There was a problem hiding this comment.
This is a strong first swing at this! I do have a few requests for additional tests and like @nicolethoen would like to see some tweaks to the queries being used though.
packages/react-core/src/components/BackToTop/__tests__/BackToTop.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/BackToTop/__tests__/BackToTop.test.tsx
Show resolved
Hide resolved
packages/react-core/src/components/BackToTop/__tests__/BackToTop.test.tsx
Show resolved
Hide resolved
packages/react-core/src/components/BackToTop/__tests__/BackToTop.test.tsx
Show resolved
Hide resolved
thatblindgeye
left a comment
There was a problem hiding this comment.
Awesome work on this! Other than Austn's comment, only had one comment below
| expect(screen.getByTestId('backtotop').firstChild).toBeVisible(); | ||
| expect(screen.getByTestId('backtotop').firstChild).not.toHaveClass('pf-m-hidden'); |
There was a problem hiding this comment.
Since the earlier tests are just checking for the pf-m-hidden class, could we remove the toBeVisible line here?
f615544 to
234ba4c
Compare
30fb1eb to
c58e76f
Compare
wise-king-sullyman
left a comment
There was a problem hiding this comment.
I have a few nits that I would like to see addressed, but none are true blockers so I'm happy to approve 🙂
Really awesome work on this!
| <p>{variant}</p> | ||
| <p>{iconPosition}</p> |
There was a problem hiding this comment.
Nit: can you update these to have some additional text which you include in your getByText query to ensure that we don't get false positive because of text elsewhere in the component?
| <p>{variant}</p> | |
| <p>{iconPosition}</p> | |
| <p>Variant: {variant}</p> | |
| <p>Icon position: {iconPosition}</p> |
| expect(screen.getByRole(`button`).parentElement).toHaveClass('pf-m-hidden'); | ||
| }); | ||
|
|
||
| test('Renders BackToTop when isAlwaysVisible prop is set', () => { |
There was a problem hiding this comment.
Nit: can you adjust this test name since it isn't really testing that BackToTop renders, but rather that it renders without the hidden class?
| test('Passes correct text content to button child component', () => { | ||
| render(<BackToTop title="Back to the future" />); | ||
|
|
||
| expect(screen.getByText('Back to the future')).toBeVisible(); |
There was a problem hiding this comment.
Nit: here I would rather see us use the getByRole query to select the button and assert that it's text is what we expect using the toHaveTextContent matcher.
| test('Passes correct icon to button child component', () => { | ||
| render(<BackToTop />); | ||
|
|
||
| expect(screen.getByTestId('icon').firstChild).toBeTruthy(); | ||
| }); |
There was a problem hiding this comment.
Nit: for the icon I would rather see us do something like what I did for the angle right icon in the accordion toggle where we mock it out (since the SVG isn't actually a responsibility of BackToTop), and then I would just assert that the icon div contains the text you pass in for the mock so that we know it's being sent to Button properly.
* chore(BackToTop) update tests to new standarts * add more tests * add a few more tests, update queries * add more tests, mocking in progress * mock button child element, test props passed to it * update user-event calls
What: Closes #7813
Additional issues: There seems to be an issue with toBeVisible(). When component visibility is controlled by css property, toBeVisible reports the component as visible even though it has css property that should hide the component (eg. display: none)
I've worked around that by checking for hidden class instead("pf-m-hidden").