-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[test] Convert SwipeableDrawer tests to testing-library #26916
Merged
eps1lon
merged 4 commits into
mui:next
from
eps1lon:test/SwipeableDrawer/testing-library
Jun 25, 2021
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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.
Need to do some manual testing to understand what was replayed here.
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.
Verified in https://codesandbox.io/s/single-swipearea-lock-ksyss (
monitorEvents(document.body, ['touchstart', 'touchmove', 'touchend'])
) that the way the test is setup atouchstart
would only be fired at the last renderedSwipeableDrawer
. TheSwipeArea
s are stacked on top of each other and hit detection never "pierces" elements i.e. if a touch hits an element then the event is targetted at that element not at all the ones the touch pierces. Then the event bubbles up but since theSwipeArea
s are siblings, only one registers thetouchstart
.I also remembered that subsequent
touchmove
andtouchend
target the same element as thetouchstart
.But I don't know how I could get this test to fail. I thought https://github.com/mui-org/material-ui/blob/5f882fefadbdd72e950a4940a550c1d3287dd150/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js#L300-L303 was responsible for this behavior but removing the early return does not fail any test.
@oliviertassinari Do you know what implementation this test was ensuring or how one would test https://github.com/mui-org/material-ui/blob/5f882fefadbdd72e950a4940a550c1d3287dd150/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js#L300-L303
Also please review the full test diff (https://github.com/mui-org/material-ui/pull/26916/files#diff-2e95d46f49f995c596826a9b8b12a84dc9de890ac9ffb65d208dd2fc23b2ccbeR508-R551) to make sure I didn't miss something.
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.
The new test case looks correct. Regarding getting it to fail. We added more defensive logic, later on, to avoid two swipeable drawers responding to the same event. It seems that this logic is winning over the previous solutions. For instance,
event.defaultMuiPrevented
now only seems to make sense if there is a custom component.claimedSwipeInstance
now seems to be solved by testing the target of the event. We should be able to remove this logic.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 somewhat leaning towards keeping the implementation to be safe. Touch related interactions are hard to test automatically so it may take a while before people realize we broken something.