-
Notifications
You must be signed in to change notification settings - Fork 2k
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 Tracking: Remove "wpcom_block_editor_close_click" from W button #53864
Conversation
Link to Calypso live: https://calypso.live?image=registry.a8c.com/calypso/app:build-9241 |
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
This PR modifies the release build for wpcom-block-editor To test your changes on WordPress.com, run To deploy your changes after merging, see the documentation: PCYsg-l4k-p2 |
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 is working well in my testing!
const editorCloseClickNotFired = | ||
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' ) | ||
.length === 0; | ||
assert.strictEqual( |
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.
Should we add a second test to ensure this fires as expected on < All Pages
/ < All Posts
/ < Dashboard
?
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.
Any idea how to tackle this? I've the tests written (locally) but clicking on the button closes the editor. Which removes the E2E events stack.
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.
Ohh good point. Im not quite sure the best way to handle that. Maybe a simple way would be to define the selector for this tracks event as a constant, use that import in both the test and the tracks event, and have the test just verify that selector is present where we would expect it to be? It wouldn't technically test that the event is firing, but it would at least notify us if the selector that event is tied to is no longer present 🤔 .
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.
@WunderBart Any idea? Is there a way to disable/prevent navigations? Googled it but no luck 😞
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.
Not sure I understand the issue here, could you elaborate please?
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.
Actually, should we even test it here? Isn't that something we should do in ETK?
} else { | ||
await driverHelper.clickWhenClickable( | ||
this.driver, | ||
By.css( '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button' ) |
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 this selector works for toggling regardless of open/close state.
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.
It doesn't work. The button is not visible so Selenium can't click on it. That's why we need to use the button in the sidebar.
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 if you let CSS select the first available element it should toggle the sidebar alright:
const dismissSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-nav-sidebar__dismiss-sidebar-button';
const toggleSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button';
async toggleNavigationSidebar() {
return await driverHelper.clickWhenClickable(
this.driver,
By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
);
}
...assuming those selectors are correct 😉
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.
Just checked those out in Gutenberg, and it seems we can use aria attributes as selectors. It's generally a better practice to use user-facing attributes as selectors as they're less likely to change and break the test. Notice also the rename to toggleBlockEditorSidebar
as it seems to be the UI component name. Here's the updated version of the above toggle method:
async toggleBlockEditorSidebar() {
const dismissSidebarButtonSelector = 'button[aria-label="Block editor sidebar"][aria-expanded="false"]';
const toggleSidebarButtonSelector = 'button[aria-label="Close block editor sidebar"]';
return await driverHelper.clickWhenClickable(
this.driver,
By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
);
}
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.
Im noticing there are calypso_editor_sidebar_*
events set up in the editing toolkit for the opening the panel and closing the editor via the dotcom sidebar version. It seems like some of this in the post editor might be redundant.
export default () => ( { | ||
id: 'wpcom-block-editor-nav-sidebar-open', | ||
selector: | ||
'.edit-post-header .wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button[aria-expanded="false"]', | ||
type: 'click', | ||
capture: true, | ||
handler: () => tracksRecordEvent( 'wpcom_block_editor_nav_sidebar_open' ), | ||
} ); |
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.
Looking more, I don't think we need to add this for the post-editor. It is already tracking calypso_editor_sidebar_open
:
Line 30 in f2af217
recordTracksEvent( `calypso_editor_sidebar_open` ); |
We don't easily see it in our logs since that comes from editing-toolkit and not wpcom-block-editor, but looking at t.gif under network requests should show it happening.
export default () => ( { | ||
id: 'wpcom-block-editor-close-click', | ||
selector: '.edit-post-header .edit-post-fullscreen-mode-close', | ||
selector: | ||
'.edit-post-header .edit-post-fullscreen-mode-close:not(.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button), .wpcom-block-editor-nav-sidebar-nav-sidebar__home-button', | ||
type: 'click', |
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.
Im starting to second guess our decision on this now. Looking further there is also a calypso_editor_sidebar_editor_close
set up:
Line 131 in f2af217
recordTracksEvent( 'calypso_editor_sidebar_editor_close' ); |
Although, I am not seeing this one firing when I use this close button for some reason. 🤔 I see it in recent tracks history though, there must be some inconsistency with the conditional, maybe it needs to record the event regardless of that condition.
That's a nice find @Addison-Stavlo ! Since the ETK is tracking open, dismiss and editor close, I guess we can just scope this down to removing the |
async toggleNavigationSidebar() { | ||
const isOpen = await driverHelper.isElementLocated( | ||
this.driver, | ||
By.css( '.wpcom-block-editor-nav-sidebar-nav-sidebar__click-guard' ) |
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.
Is this nav-sidebar-nav-sidebar
part intended here?
} else { | ||
await driverHelper.clickWhenClickable( | ||
this.driver, | ||
By.css( '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button' ) |
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 if you let CSS select the first available element it should toggle the sidebar alright:
const dismissSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-nav-sidebar__dismiss-sidebar-button';
const toggleSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button';
async toggleNavigationSidebar() {
return await driverHelper.clickWhenClickable(
this.driver,
By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
);
}
...assuming those selectors are correct 😉
const editor = await EditorComponent.Expect( this.driver, gutenbergEditorType ); | ||
|
||
await editor.toggleNavigationSidebar(); | ||
await editor.toggleNavigationSidebar(); |
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.
Why a double call 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.
To make sure we don't leave it open for the next test. And it's also to make sure the event isn't triggered for both open and close action.
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.
Ah, gotcha. A short explanation comment would be nice then! 🙏
assert.strictEqual( | ||
editorCloseClickNotFired, | ||
true, | ||
'"wpcom_block_editor_close_click" editor tracking event fired' | ||
); |
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.
IMO this would be a cleaner way for this kind of assertions:
assert.strictEqual( | |
editorCloseClickNotFired, | |
true, | |
'"wpcom_block_editor_close_click" editor tracking event fired' | |
); | |
assert( editorCloseClickNotFired, '"wpcom_block_editor_close_click" editor tracking event fired' ); |
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' ) | ||
.length === 0; |
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.
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' ) | |
.length === 0; | |
! eventsStack.some( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' ); |
This PR modifies the release build for editing-toolkit To test your changes on WordPress.com, run To deploy your changes after merging, see the documentation: PCYsg-mMA-p2 |
Thanks @WunderBart ! Made some changes according to your suggestions. |
/** | ||
* Alias for `toggleNavigationSidebar`. | ||
* We need to have the same function names in both | ||
* this and gutenberg editor component to | ||
* make sure general tests are working as expected. | ||
*/ |
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.
tip
: If you're using VSCode, there's a neat extension that wraps the comments automatically for you: https://marketplace.visualstudio.com/items?itemName=stkb.rewrap. I've set it up to wrap at 100th column as it's what we've set for Prettier.
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 just installed this per your suggestion and its great!
@@ -158,6 +158,22 @@ export function createGeneralTests( { it, editorType, postType } ) { | |||
); | |||
} ); | |||
|
|||
it( `W button should not trigger the "wpcom_block_editor_close_click" event when it's connected to a sidebar`, async function () { |
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.
Could you explain how this test ensures that the W
button is not triggering this event? I don't see that button being pressed anywhere... 🤔
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.
Ah, scratch that. I thought is's about a W
key, like in WSAD
😅. Anyway, what that W
button actually is on the page? 😄
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.
Right! We don't really have an offical name for the button. Either W Button, WP Button or Site Icon Button
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 PR modifies the release build for notifications To test your changes on WordPress.com, run To deploy your changes after merging, see the documentation: PCYsg-elI-p2 |
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 looks good and works well on my end.
Changes proposed in this Pull Request
This is a companion PR to #53500
wpcom_block_editor_close_click
is used to track when the editor is closed. A few months ago a navigation sidebar was implemented for the post editor, that time the W button's behaviour changed. It opened the navigation sidebar rather than closing the editor. To make sure we are tracking the right behaviour, this PR changes the following:wpcom_block_editor_close_click
from the WP button when it's supposed to open a navigation sidebar.Testing instructions
E2E test will fail for Site Editor.
Related to #53500 #53410