fix(react-dialog): set transition status to undefined for test environment
#29755
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.
Previous Behavior
DialogTransitionContextis always defined and has valueenteredfor test environment (#29692). However,DialogSurfacehas base styleopacity: 0, and when transition status isentered, it merges styleopacity: 1. To apply stylesDialogSurfaceusesmakeResetStyles()&makeStyles(), so will get following:In this case, tests for
DialogSurfaceusingjest-dom&.toBeVisible()can fail. This is ajsdombug - it cannot detect style override with 'opacity' nor 'visibility' (check Stackblitz). This happens becauseDialogSurfacehas as base styleopacity:0:getComputedStyles(DialogSurfaceElement).opacityinjsdomreturns0and ignores theopacity:1style override 💥Odd thing is, fix #29692 is good enough for a simple test that asserts something within
DialogSurfacevia '.toBeVisible()'. But when a random style override is added toDialogSurface, the test can fail with the same reason. This PR added a unit test case for this.New Behavior
DialogTransitionContextisundefinedfor test environment.DialogSurfaceadds styleopacity:0only when DialogTransitionContext is defined.Test is green and animation works as is.
Discarded solution
I also considered simply moving
opacity:0from baseStyle to 'unmounted' state's style, but it breaks animation:Screen.Recording.2023-11-06.at.11.57.34.mov
note that DialogSurface shows up immediately after open. This is because transition state is
exitedenteringand thenenteredwhen Dialog is opened. Addingopacity:0based on state is not as safe option compare to not adding it at all for test environment.