-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Focus preview button after opening preview. #20570
Conversation
Size Change: -428 B (0%) Total Size: 865 kB
ℹ️ View Unchanged
|
@@ -144,6 +146,7 @@ describe( 'Preview', () => { | |||
// Pressing preview without changes should bring same preview window to | |||
// front and reload, but should not show interstitial. | |||
await editorPage.bringToFront(); | |||
await editorPage.click( '.editor-post-preview__button-toggle' ); |
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.
Something I don't understand here.
We click on "editor-post-preview__button-toggle" here and then when calling waitForPreviewNavigation
. Do we need to click the button twice?
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.
When navigating back from the preview to the editor, the preview options dropdown is still open, so when waitForPreviewNavigation
clicks on it it closes instead of opening. The alternative to doing it this way would be not opening the dropdown inside waitForPreviewNavigation
and instead opening it beforehand if it's not already open. Perhaps it will be less confusing that way.
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.
waitForPreviewNavigation
could also check if the dropdown is already open and only click the toggle when it needs to.
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 thought about that at first, but is it good practice to have conditionals in tests? It always feels a bit wrong to me 😅 and it would probably make the test slower because we'd have to wait to see if the selector was found.
Happy to do it if everyone agrees though!
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 suppose it makes that part of the test no longer deterministic. Maybe the easiest thing would be to break waitForPreviewNavigation
into two functions in that case.
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 don't mind either conditions or breaking into two functions. Other than that, the changes here look good to me.
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.
Done!
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.
This definitely seems to solve the problem and it's great that there are tests too to catch any potential further issues. 🎉
As an aside, I just noticed this issue too - #20677, but it's in master
as well so shouldn't hold up this PR.
Description
Fixes #20404 .
When opening preview externally and returning to the editor tab, the dropdown loses focus, so it doesn't close when clicked outside. This change sets focus back on the preview button after opening the external preview.
How has this been tested?
Tested in browser; ran unit tests and updated selectors for e2e tests.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: