-
Notifications
You must be signed in to change notification settings - Fork 377
chore: Migrate tests to RTL (3) #7031
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
Conversation
|
Preview: https://patternfly-react-pr-7031.surge.sh A11y report: https://patternfly-react-pr-7031-a11y.surge.sh |
9cf40e8 to
4ef4ca3
Compare
4ef4ca3 to
236c28c
Compare
| expect(view.props().id).toBe('empty-state-icon'); | ||
| }); | ||
|
|
||
| test('Wrap icon in a div', () => { |
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 did you delete this test? is it testing the 'container' variant?
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.
Neither of these icon tests made much sense to me. I see now that it is wrapped in a div when "icon" variant isn't specified. I can add it back with something similar.
| }); | ||
|
|
||
| test('FormSelect passes value and event to onChange handler', () => { | ||
| const myMock = jest.fn(); |
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.
The old test checked that values and events were passed as props to the mocked event handler. Can you also do that here?
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.
These are implementation details that this test shouldn't care about, but I can add at least that the mock was called with 'mr'. There is no longer a simulated event, so I can either grab the whole real event object;
{"_reactName": "onChange", "_targetInst": null, "bubbles": true, "cancelable": false, "currentTarget": null, "defaultPrevented": false, "eventPhase": 3, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": false, "nativeEvent": {"isTrusted": false}, "target": <select aria-invalid="false" aria-label="Some label" class="pf-c-form-control" data-ouia-component-id="OUIA-Generated-FormSelect-default-8" data-ouia-component-type="PF4/FormSelect" data-ouia-safe="true"><option class="" value="mr">Mr</option></select>, "timeStamp": 1648149977372, "type": "change"}
and paste that in, or exclude it since again, this is a detail we should not be concerned about. Rather when this test is rewritten it should verify a DOM change based on the selected option.
| </select> | ||
| </div> | ||
| `; | ||
| exports[`FormSelect required FormSelect input 1`] = `"<select aria-label=\\"required FormSelect\\" class=\\"pf-c-form-control\\" aria-invalid=\\"false\\" data-ouia-component-type=\\"PF4/FormSelect\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-FormSelect-default-7\\"><option class=\\"\\" value=\\"mr\\">Mr</option></select>"`; |
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 dont see anything in this snapshot (or the old snapshot, actually) that indicates the markup has changed because the required flag was set...
If it's not as simple as just updating the snapshot creation to include something that's missing, then we can address this when we update all tests, i guess.
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.
The problem was the prop was wrong and is a perfect example of a false-positive snapshot test. The prop was meant to be isRequired having inspected the component further.
I've updated the test to verify the required attribute is present when the prop is specified instead of taking a snapshot.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`LabelGroup label group with category and tooltip 1`] = `"<ul class=\\"pf-c-label-group__list\\" aria-labelledby=\\"pf-random-id-4\\" role=\\"list\\" data-testid=\\"label-group-test-id\\"><li class=\\"pf-c-label-group__list-item\\"><span class=\\"pf-c-label\\"><span class=\\"pf-c-label__content\\">1.1</span></span></li></ul>"`; |
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.
neither the old nor the new snapshot have a tooltip :/ maybe we should update these tests with a comment so we can be sure to readdress them?
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'll add a comment.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`LabelGroup label group with category 1`] = `"<ul class=\\"pf-c-label-group__list\\" aria-labelledby=\\"pf-random-id-1\\" role=\\"list\\" data-testid=\\"label-group-test-id\\"><li class=\\"pf-c-label-group__list-item\\"><span class=\\"pf-c-label\\"><span class=\\"pf-c-label__content\\">1.1</span></span></li></ul>"`; |
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.
The category is missing from this snapshot
| </div> | ||
| </div> | ||
| `; | ||
| exports[`LabelGroup label group with closable category 1`] = `"<ul class=\\"pf-c-label-group__list\\" aria-labelledby=\\"pf-random-id-2\\" role=\\"list\\" data-testid=\\"label-group-test-id\\"><li class=\\"pf-c-label-group__list-item\\"><span class=\\"pf-c-label\\"><span class=\\"pf-c-label__content\\">1.1</span></span></li></ul>"`; |
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.
the category is missing from this snapshot
| render(<EmptyStateBody data-testid="body-test-id" />); | ||
| expect(screen.getByTestId('body-test-id').className).toContain('pf-c-empty-state__body'); |
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.
Would it be worth checking that passing in a custom class works here like the original test?
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.
Yeah I agree with that, I can add that back in.
| render(<EmptyStateSecondaryActions data-testid="actions-test-id" />); | ||
| expect(screen.getByTestId('actions-test-id').className).toContain('pf-c-empty-state__secondary'); |
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.
Same as above re: passing in a class name
| test('should render form group required variant', () => { | ||
| const view = render( | ||
| <FormGroup isRequired label="label" fieldId="id"> | ||
| render( | ||
| <FormGroup isRequired label="label" fieldId="id" data-testid="form-group-test-id"> | ||
| <input id="id" /> | ||
| </FormGroup> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(screen.getByTestId('form-group-test-id').outerHTML).toMatchSnapshot(); |
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 believE this test and the test on line 45 are testing for the same thing. If nothing else this comment can serve as a note as to what to update in the future after all of these PRs are merged in.
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.
Yeah, it's the same. I'll remove this one.
| test('validated error FormSelect input', () => { | ||
| render( | ||
| <FormSelect validated={ValidatedOptions.error} aria-label="validated FormSelect"> | ||
| <FormSelectOption key={1} value={props.options[1].value} label={props.options[1].label} /> | ||
| </FormSelect> | ||
| ); | ||
| expect(screen.getByLabelText('validated FormSelect').outerHTML).toMatchSnapshot(); | ||
| }); |
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.
Looks like this and the Invalid FormSelect Input test are essentially testing the same thing. Same as another comment above that this could be a note for future update if not removed in this PR.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`LoginFooterItem className is added to the root element 1`] = `"<a target=\\"_blank\\" href=\\"#\\"></a>"`; |
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.
The class isn't being added here, though might be similar to some comments Nicole made about worth noting to readdress in the future.
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.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`LoginFooterItem className is added to the root element 1`] = `"<a target=\\"_blank\\" href=\\"#\\"></a>"`; |
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.
all these snapshots are missing the root element
| /> | ||
| </div> | ||
| `; | ||
| exports[`LoginMainFooterBandItem with custom node 1`] = `"<div>My custom node</div>"`; |
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 is missing the root element.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`FormGroup should render form group validated error variant 1`] = `"<div data-testid=\\"form-group-test-id\\" class=\\"pf-c-form__group\\"><div class=\\"pf-c-form__group-label\\"><label class=\\"pf-c-form__label\\" for=\\"label-id\\"><span class=\\"pf-c-form__label-text\\">label</span></label> </div><div class=\\"pf-c-form__group-control\\"><input id=\\"id\\"></div></div>"`; |
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 snapshot contains nothing indicating that it's an error variant
| </div> | ||
| </div> | ||
| `; | ||
| exports[`FormGroup should render form group variant with function helperText 1`] = `"<div data-testid=\\"form-group-test-id\\" class=\\"pf-c-form__group\\"><div class=\\"pf-c-form__group-label\\"><label class=\\"pf-c-form__label\\" for=\\"label-id\\"><span class=\\"pf-c-form__label-text\\">Label</span></label> </div><div class=\\"pf-c-form__group-control\\"><input id=\\"label-id\\"><div>label</div></div></div>"`; |
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 dont see any helpertext in this snapshot
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.
or in the old one :/
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'm seeing it actually, since helperText is just a div with the text label, you'll need to look for that.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`FormGroup should render form group variant with function label 1`] = `"<div data-testid=\\"form-group-test-id\\" class=\\"pf-c-form__group\\"><div class=\\"pf-c-form__group-label\\"><label class=\\"pf-c-form__label\\" for=\\"id\\"><span class=\\"pf-c-form__label-text\\"><div>label</div></span></label> </div><div class=\\"pf-c-form__group-control\\"><input aria-label=\\"input\\"></div></div>"`; |
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.
again, not seeing the .pf-c-form__helper-text. Maybe i'm looking for the wrong thing?
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.
Same as the other test with the return function, it's just a div with the text label, which does exist in the snapshot.
| </div> | ||
| </div> | ||
| `; | ||
| exports[`FormGroup should render form group variant with node helperText 1`] = `"<div data-testid=\\"form-group-test-id\\" class=\\"pf-c-form__group\\"><div class=\\"pf-c-form__group-label\\"><label class=\\"pf-c-form__label\\" for=\\"label-id\\"><span class=\\"pf-c-form__label-text\\">Label</span></label> </div><div class=\\"pf-c-form__group-control\\"><input id=\\"label-id\\"><h1>Header</h1></div></div>"`; |
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.
again no .pf-c-form__helper-text
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 time I do see the helperText, where in this test the prop is a div with the text "Header" which does exist here.

What: Closes #7030