Skip to content

Conversation

@jpuzz0
Copy link
Contributor

@jpuzz0 jpuzz0 commented Mar 9, 2022

What: Closes #7030

@patternfly-build
Copy link
Collaborator

patternfly-build commented Mar 9, 2022

@jpuzz0 jpuzz0 force-pushed the chore/rtl-migrate-bundle-3 branch 2 times, most recently from 9cf40e8 to 4ef4ca3 Compare March 10, 2022 17:28
@thatblindgeye thatblindgeye self-requested a review March 21, 2022 19:01
@jpuzz0 jpuzz0 force-pushed the chore/rtl-migrate-bundle-3 branch from 4ef4ca3 to 236c28c Compare March 23, 2022 14:02
@nicolethoen nicolethoen self-requested a review March 23, 2022 19:38
expect(view.props().id).toBe('empty-state-icon');
});

test('Wrap icon in a div', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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>"`;
Copy link
Contributor

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.

Copy link
Contributor Author

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>"`;
Copy link
Contributor

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?

Copy link
Contributor Author

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>"`;
Copy link
Contributor

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>"`;
Copy link
Contributor

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

Comment on lines 69 to 70
render(<EmptyStateBody data-testid="body-test-id" />);
expect(screen.getByTestId('body-test-id').className).toContain('pf-c-empty-state__body');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 74 to 75
render(<EmptyStateSecondaryActions data-testid="actions-test-id" />);
expect(screen.getByTestId('actions-test-id').className).toContain('pf-c-empty-state__secondary');
Copy link
Contributor

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

Comment on lines 141 to 147
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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines 154 to 161
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();
});
Copy link
Contributor

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>"`;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component doesn't pass it in is why. I'm going to update the component for this since the prop exists, I assume it shouldn't omit the className as it's doing here:
image

</div>
</div>
`;
exports[`LoginFooterItem className is added to the root element 1`] = `"<a target=\\"_blank\\" href=\\"#\\"></a>"`;
Copy link
Contributor

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>"`;
Copy link
Contributor

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>"`;
Copy link
Contributor

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>"`;
Copy link
Contributor

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

Copy link
Contributor

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 :/

Copy link
Contributor Author

@jpuzz0 jpuzz0 Mar 24, 2022

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>"`;
Copy link
Contributor

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?

Copy link
Contributor Author

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>"`;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@tlabaj tlabaj merged commit 72f1977 into patternfly:main Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate tests to RTL (3)

6 participants