-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Search Block not updating in Nav block (#54823)
* Avoid setState in render * Attempt at test coverage * Improve tests and make them work
- Loading branch information
Showing
2 changed files
with
110 additions
and
10 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Search', () => { | ||
test.beforeEach( async ( { admin, requestUtils } ) => { | ||
await requestUtils.deleteAllMenus(); | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllMenus(); | ||
} ); | ||
|
||
test.afterEach( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.deleteAllPosts(), | ||
requestUtils.deleteAllMenus(), | ||
] ); | ||
} ); | ||
|
||
test( 'should auto-configure itself to sensible defaults when inserted into a Navigation block', async ( { | ||
page, | ||
editor, | ||
requestUtils, | ||
} ) => { | ||
const createdMenu = await requestUtils.createNavigationMenu( { | ||
title: 'Test Menu', | ||
content: `<!-- wp:spacer --> | ||
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div> | ||
<!-- /wp:spacer -->`, | ||
} ); | ||
|
||
await editor.insertBlock( { | ||
name: 'core/navigation', | ||
attributes: { | ||
ref: createdMenu?.id, | ||
}, | ||
} ); | ||
|
||
const navBlockInserter = editor.canvas.getByRole( 'button', { | ||
name: 'Add block', | ||
} ); | ||
await navBlockInserter.click(); | ||
|
||
// Expect to see the block inserter. | ||
await expect( | ||
page.getByRole( 'searchbox', { | ||
name: 'Search for blocks and patterns', | ||
} ) | ||
).toBeFocused(); | ||
|
||
// Search for the Search block. | ||
await page.keyboard.type( 'Search' ); | ||
|
||
const blockResults = page.getByRole( 'listbox', { | ||
name: 'Blocks', | ||
} ); | ||
|
||
await expect( blockResults ).toBeVisible(); | ||
|
||
const searchBlockResult = blockResults.getByRole( 'option', { | ||
name: 'Search', | ||
} ); | ||
|
||
// Select the Search block. | ||
await searchBlockResult.click(); | ||
|
||
// Expect to see the Search block. | ||
const searchBlock = editor.canvas.getByRole( 'document', { | ||
name: 'Block: Search', | ||
} ); | ||
|
||
await expect( searchBlock ).toBeVisible(); | ||
|
||
// The only way to access the inner controlled blocks of the Navigation block | ||
// is to access the edited entity record for the associated Navigation Menu record. | ||
const editedMenuRecord = await page.evaluate( ( menuId ) => { | ||
return window.wp.data | ||
.select( 'core' ) | ||
.getEditedEntityRecord( 'postType', 'wp_navigation', menuId ); | ||
}, createdMenu?.id ); | ||
|
||
// The 2nd block in the Navigation block is the Search block. | ||
const searchBlockAttributes = editedMenuRecord.blocks[ 1 ].attributes; | ||
|
||
expect( searchBlockAttributes ).toMatchObject( { | ||
showLabel: false, | ||
buttonUseIcon: true, | ||
buttonPosition: 'button-inside', | ||
} ); | ||
} ); | ||
} ); |
4cec468
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.
Flaky tests detected in 4cec468.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6330976994
📝 Reported issues:
/test/e2e/specs/editor/various/multi-block-selection.spec.js