Skip to content

[Emotion] Add css prop to requiredProps#6886

Merged
cee-chen merged 7 commits intoelastic:mainfrom
cee-chen:fix-css-merging-1
Jun 29, 2023
Merged

[Emotion] Add css prop to requiredProps#6886
cee-chen merged 7 commits intoelastic:mainfrom
cee-chen:fix-css-merging-1

Conversation

@cee-chen
Copy link
Copy Markdown
Contributor

@cee-chen cee-chen commented Jun 29, 2023

Summary

This PR is part 1 of several PRs that attempt to better harden our testing around the css prop and how it reacts to consumers passing/merging in their own custom Emotion css on top of EUI's css.

The primary change that it makes is adding a css prop to requiredProps (31b8ecf). Almost all other changes are simply snapshot updates reacting accordingly (across almost all components, since we used requiredProps in almost all tests).

Rendering custom css by default should hopefully help make it obvious what custom CSS will look like on top of EUI's CSS as well as spot issues where either custom CSS is not being applied or EUI's CSS is being accidentally overridden.

This PR also incidentally strives to avoid snapshotting Emotion's injected wrapper (which occurs primarily in shallow/mounted snapshots) using a variety of techniques, depending on the complexity of the test and component (see commit messages for more detail).

I recommend reviewing by commit and skimming the 2nd commit with a million snapshot updates 😅

QA

  • CI passes

General checklist

  • Added or updated jest and cypress tests
    - [ ] A changelog entry exists and is marked appropriately N/A - tests only

cee-chen added 5 commits June 28, 2023 22:14
- to make it easier to examine Emotion className output in snapshots
- i.e., snapshots that don't render the super incredibly long Emotion wrapper
- To prevent the super verbose `<Emotion>` injection wrapper from rendering
- these should likely be converted to RTL tests, but honestly they also just need specific assertions and not just blanket snapshots - which would take too long at this point and I'm looking for minimal changes
- that's coming in from the new `requiredProps.css`

approaches are:
- converting to RTL `render` where possible
- removing `..requiredProps` spreads for non `it renders` tests
- `dive()`ing or `mount()`ing instead of `shallow`
@cee-chen cee-chen added testing Issues or PRs that only affect tests - will not need changelog entries skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) labels Jun 29, 2023
@cee-chen cee-chen requested a review from tkajtoch June 29, 2023 05:24
aria-label="aria-label"
aria-labelledby="generated-id"
class="euiButtonIcon euiAccordion__iconButton testClass1 testClass2 emotion-euiButtonIcon-xs-empty-text-euiAccordion__iconButton"
class="euiButtonIcon euiAccordion__iconButton testClass1 testClass2 emotion-euiButtonIcon-xs-empty-text-euiTestCss"
Copy link
Copy Markdown
Contributor Author

@cee-chen cee-chen Jun 29, 2023

Choose a reason for hiding this comment

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

This snapshot actually exemplifies the bug I ran into when working on the new nav redesign. The euiTestCss passed to arrowProps.css is overriding EUI's euiAccordion__iconButton css instead of being merged correctly (which should look like euiAccordion__iconButton-euiTestCss).

This PR does not attempt to solve that problem (as this one is massive enough as it is, and I'm looking to break up the work into more easily reviewable chunks), but helps highlight the problem.

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_6886/

test('is rendered', () => {
const component = shallow(
it('renders', () => {
const { container } = render(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love to see more tests being converted to RTL 💯

@tkajtoch
Copy link
Copy Markdown
Member

This is a solid set of changes and I love that we can now easily see if css props are properly injected.

I made a list of snapshots in this PR that have classes modified in a different way than adding -euiTestCss:

src/components/accordion/__snapshots__/accordion.test.tsx.snap
src/components/collapsible_nav/collapsible_nav_group/__snapshots__/collapsible_nav_group.test.tsx.snap
src/components/color_picker/color_stops/__snapshots__/color_stops.test.tsx.snap
src/components/flyout/__snapshots__/flyout.test.tsx.snap
src/components/image/__snapshots__/image.test.tsx.snap
src/components/key_pad_menu/__snapshots__/key_pad_menu.test.tsx.snap
src/components/page/__snapshots__/page_template.test.tsx.snap
src/components/page/page_header/__snapshots__/page_header.test.tsx.snap
src/components/page/page_header/__snapshots__/page_header_content.test.tsx.snap

Copy link
Copy Markdown
Member

@tkajtoch tkajtoch left a comment

Choose a reason for hiding this comment

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

🚢 Approved! Feel free to merge after rebasing with latest main if there aren't more changes that may affect anything

@cee-chen
Copy link
Copy Markdown
Contributor Author

Thanks Tomasz! Great eye on those changes as well, I do have fixes for all those snapshots coming up in the next PR.

No issues/changes when merging latest except re-running yarn test-unit -u. Going to go ahead and merge this PR!

@cee-chen cee-chen enabled auto-merge (squash) June 29, 2023 21:51
@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_6886/

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_6886/

@cee-chen cee-chen merged commit e578d6d into elastic:main Jun 29, 2023
@cee-chen cee-chen deleted the fix-css-merging-1 branch June 29, 2023 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) testing Issues or PRs that only affect tests - will not need changelog entries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants