-
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
Add regresion E2E test for the empty reusable block causing WSODs issue #26913
Changes from all commits
0cf0237
c054069
aea0867
e99ec76
044c358
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,8 @@ import { | |||
searchForReusableBlock, | ||||
getEditedPostContent, | ||||
trashAllPosts, | ||||
visitAdminPage, | ||||
toggleGlobalBlockInserter, | ||||
} from '@wordpress/e2e-test-utils'; | ||||
|
||||
function waitForAndAcceptDialog() { | ||||
|
@@ -330,4 +332,44 @@ describe( 'Reusable blocks', () => { | |||
// Check that we have two paragraph blocks on the page | ||||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||||
} ); | ||||
|
||||
it( 'will not break the editor if empty', async () => { | ||||
await insertReusableBlock( 'Awesome block' ); | ||||
|
||||
await visitAdminPage( 'edit.php', [ 'post_type=wp_block' ] ); | ||||
|
||||
const [ editButton ] = await page.$x( | ||||
`//a[contains(@aria-label, 'Awesome block')]` | ||||
); | ||||
await editButton.click(); | ||||
|
||||
await page.waitForNavigation(); | ||||
|
||||
// Give focus to the editor | ||||
await page.waitForSelector( '.block-editor-writing-flow' ); | ||||
await page.click( '.block-editor-writing-flow' ); | ||||
|
||||
// Move focus to the paragraph block | ||||
await page.keyboard.press( 'Tab' ); | ||||
await page.keyboard.press( 'Tab' ); | ||||
|
||||
// Delete the block, leaving the reusable block empty | ||||
await clickBlockToolbarButton( 'More options' ); | ||||
const deleteButton = await page.waitForXPath( | ||||
'//button/span[text()="Remove block"]' | ||||
); | ||||
deleteButton.click(); | ||||
|
||||
// Save the reusable block | ||||
await page.click( '.editor-post-publish-button__button' ); | ||||
await page.waitForXPath( | ||||
'//*[contains(@class, "components-snackbar")]/*[text()="Reusable Block updated."]' | ||||
); | ||||
|
||||
await createNewPost(); | ||||
|
||||
await toggleGlobalBlockInserter(); | ||||
|
||||
expect( console ).not.toHaveErrored(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is scoped only to the e2e spec. It isn't possible to catch errors on the page this way. We have a global verification for the page:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, interesting. It seemed like it did catch the error when I tested. Or maybe it was just the error bubbling up. Maybe I missed something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean then this assertion is not needed at all? Any hints on how I should rewrite that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would mean there is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I double-checked (by re-introducing the bug that caused the regression) and that expect does seem to work for the purposes of the test, see the output in the gist: https://gist.github.com/fullofcaffeine/453e58fba78d902bc690e0b6994e7b31 It is true that it might be considered redundant because if I remove it, the test still fails because the error bubbles up (as described here) and it caught from within the console object: https://gist.github.com/fullofcaffeine/ade1be595e7f1c5bd46ed5b652814934 That being said, I'd rather keep the expect there as it communicates what the test is not expecting. So, it seems it's fine the way it is? Let me know if I missed 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.
There are 2 existing helpers to control the block inserter. Would it be possible to use them instead of introducing another helper 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.
👋🏻 Hi Greg! I tried
openGlobalBlockInserter
but it waits for the actual inserter el to be present on the page. In the case the error ever regresses, it would cause a timeout because the inserter is never shown. What we really need is to just click to show the inserter, and this helper does just that. What's the other helper?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.
Also, this is actually an existing helper, I just exported it.
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 looks like
openGlobalBlockInserter
is exactly what fits best here.toggleGlobalBlockInserter
only verifies if the button can be clicked. The waiting part is crucial here to prevent regression. If it would timeout in the future, that's a proper way to signal that something went wrong.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.
Hmm, it actually wraps a
click
call: https://github.com/WordPress/gutenberg/blob/master/packages/e2e-test-utils/src/inserter.js#L49. For the purposes of this regression test, that's all we need.If we decide to use
openGlobalBlockInserter
, there's another potential problem as well (which I just tested): if it the bug regresses, it will fail with the timeout and not with the expect below it. It also means it will slow down the actual test that would finish faster if we weren't waiting for an inserter we know won't appear.