-
Notifications
You must be signed in to change notification settings - Fork 647
chore: add className testing util: #7231
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
base: main
Are you sure you want to change the base?
Conversation
|
|
👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
| implementsClassNameBehavior( | ||
| AnchoredOverlay, | ||
| 'prc-Overlay-Overlay-ViJgm', | ||
| component => component.container.firstChild!.childNodes[1].firstChild?.firstChild as HTMLElement, |
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.
🫠
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.
what's going on here? 😅 I don't understand
Is this the way to get the baseHtmlElement? + Is this so weird because every component puts the className in a different spot and not just the first child?
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.
Is this the way to get the baseHtmlElement?
Yeah, I'm trying to tell the helper how to find the element with the className
Is this so weird because every component puts the className in a different spot and not just the first child?
Correct! a lot of them will be the first child, which I've made the default, but for some of them I expect some "I need to tell you what the styled element is" which is what this is
| describe('AnchoredOverlay', () => { | ||
| implementsClassNameBehavior( | ||
| AnchoredOverlay, | ||
| 'prc-Overlay-Overlay-ViJgm', |
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.
Hmm, feels off putting the hashed className here, can we import this from .module.css file instead, does that work?
| 'prc-Overlay-Overlay-ViJgm', | ||
| component => component.container.firstChild!.childNodes[1].firstChild?.firstChild as HTMLElement, | ||
| props => <AnchoredOverlayTestComponent initiallyOpen={true} {...props} />, | ||
| ) |
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.
my dream test function call looks like this:
implementsClassName(ActionList)
// or if we need to,
implementsClassName(props => <AnchoredOverlayFixture {...props} />)implementsClassName should
- render without custom className to figure out the base class and base element
- render with custom className, make sure it has both classes on the base element
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.
render without custom className to figure out the base class and base element
can you elaborate on this one? I'm confused on how it would do that 🤔
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 literally making this up so it might not work, i should invest some time doing a proof of concept) Is there a pattern we follow for base classes? Does it always have the component name like in prc-Overlay-Overlay-ViJgm, is it safe to find the first prc-* class we find, that's probably the base class?
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 we could, the main problem I see is we don't have (as far as I can tell) "getByClassName" or something of the sorts util, so even knowing the full className, I don't know how to find the element is my main problem.
Another potential roadblock I see is some components are composed of others so will definitely have multiple "prc-*" classes
| component.container.firstChild as HTMLElement, | ||
| renderComponent: (props: {className?: string}) => React.JSX.Element = props => <Component {...(props as TProps)} />, | ||
| ) { | ||
| it('renders with the base className', () => { |
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.
idk why but this feels like a strange test to test for. The custom className test is 10/10
| import {type RenderResult, render as HTMLRender} from '@testing-library/react' | ||
| import {it, expect} from 'vitest' | ||
|
|
||
| export function implementsClassNameBehavior<TProps extends {className?: string}>( |
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.
nit:
| export function implementsClassNameBehavior<TProps extends {className?: string}>( | |
| export function implementsClassName<TProps extends {className?: string}>( |
siddharthkp
left a comment
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.
Left a few direction comments
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/7852 |
|
🔴 ci completed with status |
Relatos to https://github.com/github/primer/issues/5255
This pull request adds a reusable test utility to verify that components correctly handle
classNameprops and applies it to theAnchoredOverlaycomponent tests. The main focus is on improving test coverage and consistency for CSS class name behavior.Changelog
New
implementsClassNameBehaviorfunction toutils/testing.tsx, which provides a standardized way to test that components render both their default and customclassNameprops.implementsClassNameBehaviorinto theAnchoredOverlaytest suite, ensuring that the component correctly applies both its base and custom class names.Rollout strategy
Test-only update
Testing & Reviewing
Merge checklist