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
Block Editor: Improve act()
usage in UrlPopover
tests
#46230
Conversation
Size Change: 0 B Total Size: 1.32 MB ℹ️ View Unchanged
|
As recognized, there are some flaws with this approach, it's not reliable enough to check if a popover is positioned the way we do. I'll reconsider the approach in another PR. |
expect( | ||
getWrappingPopoverElement( screen.getByText( 'Editor' ) ) | ||
).toBePositionedPopover() | ||
); |
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.
One interesting thing here is that the test doesn't pass an anchor
prop to the URLPopover
, so there should be no positioning.
However, the Popover
component has a fallback for that case, where it will use the popover element's parent as anchor. @ciampo Are there cases where the fallback is actually used and does something useful? I can imagine using a popover inside a paragraph for example:
<p>Lorem ipsum <span>dolor<Popover>latin for pain</Popover></span> sit amet<p>
and the it will be permanently attached to the span with word "dolor"? Is that what the fallback element is for?
If we didn't do any fallback for anchor
, then it would remain null
and floating-ui
wouldn't do any positioning at all. The popover would have a position: absolute
style and that's all.
What?
This PR improves the
act()
usage inUrlPopover
to make the tests more precise and expressive.Why?
As part of the React 18 upgrade in #45235, we added a bunch of
act()
calls that could be improved and made more specific.How?
Instead of going with
await act( () => Promise.resolve() )
, we change the test to wait for the popover to be positioned before continuing.Testing Instructions
Verify tests still pass:
npm run test:unit packages/block-editor/src/components/url-popover/test/index.js
Testing Instructions for Keyboard
None
Screenshots or screencast
None