chore(TextInputGroup): update testing suite to new standards#7169
chore(TextInputGroup): update testing suite to new standards#7169tlabaj merged 2 commits intopatternfly:mainfrom
Conversation
|
Preview: https://patternfly-react-pr-7169.surge.sh A11y report: https://patternfly-react-pr-7169-a11y.surge.sh |
3127f68 to
d1f1af7
Compare
packages/react-core/src/components/TextInputGroup/__tests__/TextInputGroup.test.tsx
Show resolved
Hide resolved
| expect(input).toHaveClass('pf-c-text-input-group__text-input'); | ||
| }); | ||
|
|
||
| it('renders given input icon props', () => { |
There was a problem hiding this comment.
I think this is more-so "renders the icon" (or something like this) rather than this which reads to me essentially, "the text input group still renders when passing an icon prop". Maybe also mention that it is expected to be hidden.
| expect(input).toHaveAccessibleName('Test label'); | ||
| }); | ||
|
|
||
| it('passes the value prop to the input', () => { |
There was a problem hiding this comment.
Can we not instead visibly see the value passed to the input or is that hidden from users?
There was a problem hiding this comment.
You can't grab it or the placeholder with byRole/byText, but after some further research I did find that RTL provides a matcher specifically for input values/placeholders! Great callout!
| expect(input).toHaveAttribute('value', 'value text'); | ||
| }); | ||
|
|
||
| it('passes the placeholder prop to the input', () => { |
There was a problem hiding this comment.
same as my other comment. If we can verify visibility of the placeholder, that is more meaningful than verifying an attribute exists and makes it so we don't have to test the attribute value IMO.
packages/react-core/src/components/TextInputGroup/__tests__/TextInputGroupMain.test.tsx
Show resolved
Hide resolved
|
|
||
| const input = screen.getByRole('textbox'); | ||
| userEvent.click(input); | ||
| userEvent.click(document.body); |
There was a problem hiding this comment.
This is a good idea. I haven't thought to focus out by simply clicking the document body before.
|
|
||
| const input = screen.getByRole('textbox'); | ||
|
|
||
| expect(input).toHaveAccessibleName('Test label'); |
There was a problem hiding this comment.
Very cool. Haven't used this before.
thatblindgeye
left a comment
There was a problem hiding this comment.
Other than Jeff's comments, the only thing I could think of when looking this over was whether the test that explicitly checks for the default class should be included when the snapshots already have that class to test against.
As you mentioned in our conversation, it was decided in an RTL meeting that testing explicitly for classes should be done. I can see merit in doing so, especially if we don't want snapshots necessarily being used to test that attributes have a specific value, so I'm not willing to block over that. Mentioning it in case anyone else may have an opinion either way after seeing this in action.
| /** the below expectation is to verify that that the component isn't always rendering with the text used to verify | ||
| child rendering in the next test */ | ||
| expect(screen.queryByText('Test')).not.toBeInTheDocument(); |
There was a problem hiding this comment.
For this, would checking that the children length is 0 (or something similar) be viable for this test instead?
There was a problem hiding this comment.
I can get why you would want that, since this expectation only makes sense with the context of the following test, but I feel like checking the length of the children property isn't a very "RTL" approach. @jeffpuzzo thoughts?
There was a problem hiding this comment.
I don't think lines 15 through 17 should be included at all since you're already verifying the parent component is visible without children which is the objective of the test, correct?
There was a problem hiding this comment.
I partially agree?
15-17 aren't strictly necessary to verify that it renders without children, but in the same way that the next test verifies chilldren are rendered (by testing that when "Test" is passed as a child it is rendered to the page), this ensures that the inverse is true (by testing that when "Test" isn't passed it isn't rendered to the page). Essentially it protects from flaws in the test suite, like the component potentially always rendering "Test".
I figure that it goes along with the other aspect of testing that it renders without children for the same reason that checking for "Test" is valid for checking that children are rendered. If you disagree though and think it's either unnecessary or should be a separate test I'm not super committed to it.
There was a problem hiding this comment.
I do disagree. We're specifically rendering this component with no children (aka a self-closing tag). All we care about is that the component still renders.
Testing that text we're purposefully not including in render doesn't exist doesn't make sense to me, as much as it might appear more-so as an inverse of the other test. If someone updates the test to include "Test" as a child after the fact for some reason, then we have bigger problems.
There was a problem hiding this comment.
I think my concern is that what it's actually testing for doesn't exactly fit with what the intention is. I'd say comparing to a snapshot of the component rendered without children might be better, but that's less an option if we only want the single snapshot. EDIT: beaten to it by Jeff
There was a problem hiding this comment.
👍 I can understand that/those viewpoints. I'll update shortly.
|
you just need to resolve conflicts and we can merge. |
fa32de7 to
8a260af
Compare
|
Your changes have been released in:
Thanks for your contribution! 🎉 |
What: Closes #6929
Additional issues: