-
Notifications
You must be signed in to change notification settings - Fork 841
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
[Emotion] Further enhance shouldRenderCustomStyles
#6907
Conversation
- use an obj API for skips - programmatically generate props objects as well as test titles based on skips
- to components that spread style to a different DOM node than `className` - we can now add these tests thanks to the new `targetSelector` API and granular skips
shouldRenderCustomStyles
shouldRenderCustomStyles
const testCases = options.skipStyles | ||
? 'classNames and css' | ||
: 'classNames, css, and styles'; | ||
const testProps = options.skipStyles | ||
? { className: customStyles.className, css: customStyles.css } | ||
: customStyles; | ||
// Account for any skipped props | ||
const testProps = keysOf(customStyles).reduce((map, key) => { | ||
return options.skip?.[key] ? map : { ...map, [key]: customStyles[key] }; | ||
}, {} as Partial<typeof customStyles>); | ||
|
||
// Generate a grammatically excellent list of props being tested | ||
let propsToTest = ''; | ||
const propsToTestArr = Object.keys(testProps); | ||
switch (propsToTestArr.length) { | ||
case 1: | ||
propsToTest = propsToTestArr[0]; | ||
break; | ||
case 2: | ||
propsToTest = `${propsToTestArr[0]} and ${propsToTestArr[1]}`; | ||
break; | ||
// You'll pry the oxford comma from my cold dead hands | ||
default: | ||
propsToTest = `${propsToTestArr | ||
.slice(0, -1) | ||
.join(', ')}, and ${propsToTestArr.slice(-1)}`; | ||
break; | ||
} |
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.
Preview documentation changes for this PR: https://eui.elastic.co/pr_6907/ |
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.
👍 Refactoring to the skip
API is a good way to corral the various options. Now users can pick which facet(s) they want to test.
🎉 Thanks again Trevor! |
Summary
This is some final extra/optional work on top of #6896 - I didn't want to include it in the above PR as that was was big enough as it was. I recommend reviewing by commit and turning off whitespace diffs.
skipStyles
API - now usesskip: { style: true }
skipParentTest
API, now usesskip: { parentTest: true }
skip
API which allows for granular skipping, e.g.skip: { css: true }
...rest
spread - add tests that actually checks that consumer styles are correctly applied)QA
General checklist
N/A, internal dev/tech debt only