-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Editor: Wait for popover positioning in MediaReplaceFlow tests
#45863
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
001d6b6
Block Editor: Wait for popover positioning in MediaReplaceFlow tests
tyxla e035d52
Remove an extra backtick
tyxla 1f7ee28
Use Element.closest() to locate closest popover
tyxla 99069f9
Fix comment
tyxla 1e65537
Remove an excess assertion
tyxla 8032ab0
Reorder assertions
tyxla e59733d
Introduce a less-specific way to assert positioning
tyxla 85d318d
Use the right element when locating the popover
tyxla 6c63bc5
Clarify element.style usage
tyxla 56eef5d
Wait for the menu to get visible
tyxla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use Element.closest() to locate closest popover
- Loading branch information
commit 1f7ee28d5606de43257516e6312ecd7b5edb4d8d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jsnajdr a note on this approach: when we have direct access to the
Dropdownprops, we can pass adata-testidprop throughpopoverPropsand it will be a more optimal way to access the popover than using.closest(). I've used this technique in #45911 if you're interested to see an example.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.
Agreed, using
data-test-idsounds like a better option when possible.Do we ever add
data-testidto a component's source, or does that only happen inside the tests ?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'd never recommend cluttering the component source, but for test fixtures, I've found it to be nice and clean as a last resort.
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 afraid I don't get the point of
data-testid-- on what scale is it a more optimal way to access the popover? That it doesn't trigger theno-node-accessrule?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.
That, too, but there is more. It also allows us to avoid testing implementation details, and having to peek into the implementation of other components. That makes our tests more resilient since they don't rely on the implementation details of other components we're not currently testing.
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.
FWIW I just wanted to point it out as a potential alternative; we can't achieve it here without altering the component source because
popoverPropsdon't accept additional 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.
I think it'll be hard to avoid testing implementation details: the way how the popover is positioned, which element and with what CSS styles, that it's done async -- these are all implementation details. The best we can do is to wrap them inside helpers like custom queries or matchers.
Even the fact that the positioned
divand thedivthat gets thedata-testidprop are the same element is an implementation detail. It doesn't always need to be so. The rest props are internally calledcontentProps, so maybe they were applied tocomponents-popover_contentelement in the past?Also, as you write, it's not always possible to pass
popoverProps, especially when testing a larger unit, like a full block edit UI, where there are multiple tooltips and menus.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.
That's fair, and there's not much we can do to make things easier for composable components that offer larger flexibility through a plethora of props.
Do you have any reservations about the approach proposed in the PR after the changes I made @jsnajdr ?