Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ function Navigation( {
[ setAttributes ]
);

// Reset submenuVisibility to default if orientation changes to horizontal while "always" is selected
useEffect( () => {
if ( orientation === 'horizontal' && submenuVisibility === 'always' ) {
setAttributes( {
submenuVisibility: 'hover',
showSubmenuIcon: true,
} );
}
}, [ orientation, submenuVisibility, setAttributes ] );

const recursionId = `navigationMenu/${ ref }`;

// Skip recursion check when in preview mode.
Expand Down Expand Up @@ -372,6 +362,29 @@ function Navigation( {
innerBlocks,
} = useInnerBlocks( clientId );

// Reset submenuVisibility to default if orientation changes to horizontal
// while "always" is selected, but only when the Navigation block or one
// of its inner blocks is being edited. Rendering related template parts
// should not mark them dirty.
useEffect( () => {
if (
( isSelected || isInnerBlockSelected ) &&
orientation === 'horizontal' &&
submenuVisibility === 'always'
) {
setAttributes( {
submenuVisibility: 'hover',
showSubmenuIcon: true,
} );
}
}, [
isSelected,
isInnerBlockSelected,
orientation,
submenuVisibility,
setAttributes,
] );

// Use a ref to store whether we've confirmed a page-list has submenus.
// Once confirmed, we don't need to keep checking the page-list blocks.
const hasPageListWithSubmenuRef = useRef( false );
Expand Down
130 changes: 130 additions & 0 deletions test/e2e/specs/editor/blocks/navigation-passive-rendering.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

async function getDirtyEntityRecords( page ) {
return page.evaluate( () =>
window.wp.data
.select( 'core' )
.__experimentalGetDirtyEntityRecords()
.map( ( { kind, name, key } ) => ( { kind, name, key } ) )
);
}

async function enableShowTemplate( page, editor ) {
await page.evaluate( () => {
window.wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
} );
await editor.openDocumentSettingsSidebar();

await page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', { name: 'Template options' } )
.click();

const showTemplateButton = page.getByRole( 'menuitemcheckbox', {
name: 'Show template',
} );
const isChecked = await showTemplateButton.getAttribute( 'aria-checked' );
if ( isChecked !== 'true' ) {
await showTemplateButton.click();
} else {
await page.keyboard.press( 'Escape' );
}
}

test.describe( 'Navigation passive rendering', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.beforeEach( async ( { requestUtils } ) => {
await requestUtils.resetPreferences();
} );

test.afterEach( async ( { requestUtils } ) => {
await Promise.all( [
requestUtils.deleteAllPosts(),
requestUtils.deleteAllPages(),
requestUtils.deleteAllMenus(),
requestUtils.deleteAllTemplates( 'wp_template' ),
requestUtils.deleteAllTemplates( 'wp_template_part' ),
requestUtils.resetPreferences(),
] );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'does not dirty related template parts or navigation menus when rendered in the post editor', async ( {
admin,
editor,
page,
requestUtils,
} ) => {
const parentPage = await requestUtils.createPage( {
title: 'Products',
status: 'publish',
} );
await requestUtils.createPage( {
title: 'Laptops',
status: 'publish',
parent: parentPage.id,
} );

const menu = await requestUtils.createNavigationMenu( {
title: 'Related menu',
content: '<!-- wp:page-list {"isNested":true} /-->',
} );

await requestUtils.createTemplate( 'wp_template_part', {
slug: 'header',
title: 'Header',
content: `<!-- wp:navigation {"ref":${ menu.id },"overlayMenu":"off","submenuVisibility":"always"} /-->`,
} );

await requestUtils.createTemplate( 'wp_template', {
slug: 'singular',
title: 'Singular',
content: [
'<!-- wp:template-part {"slug":"header","tagName":"header","theme":"emptytheme"} /-->',
'<!-- wp:post-content {"layout":{"inherit":true}} /-->',
].join( '\n' ),
} );

const post = await requestUtils.createPost( {
title: 'Passive render test',
content:
'<!-- wp:paragraph --><p>Original content.</p><!-- /wp:paragraph -->',
status: 'draft',
} );

await admin.editPost( post.id );
await enableShowTemplate( page, editor );

await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Navigation',
} )
).toBeVisible();
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Page List',
} )
).toBeVisible();

Check failure on line 116 in test/e2e/specs/editor/blocks/navigation-passive-rendering.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › specs/editor/blocks/navigation-passive-rendering.spec.js:61:2 › Navigation passive rendering › does not dirty related template parts or navigation menus when rendered in the post editor

1) [chromium] › specs/editor/blocks/navigation-passive-rendering.spec.js:61:2 › Navigation passive rendering › does not dirty related template parts or navigation menus when rendered in the post editor Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeVisible() failed Locator: locator('[name="editor-canvas"]').contentFrame().getByRole('document', { name: 'Block: Page List' }) Expected: visible Error: strict mode violation: getByRole('document', { name: 'Block: Page List' }) resolved to 2 elements: 1) <ul inert="true" tabindex="-1" role="document" data-title="Page List" data-type="core/page-list" aria-label="Block: Page List" id="block-a5538fd1-e438-4c73-bfbf-f39c8aae792a" data-block="a5538fd1-e438-4c73-bfbf-f39c8aae792a" class="block-editor-block-list__block wp-block is-editing-disabled wp-block-page-list open-always wp-block-page-list block-editor-block-list__layout">…</ul> aka getByRole('document', { name: 'Block: Page List', exact: true }) 2) <ul inert="true" tabindex="-1" role="document" data-title="Page List Item" data-type="core/page-list-item" aria-label="Block: Page List Item" id="block-befeca2d-91c9-40b6-8cbc-75f4ecdee2da" data-block="befeca2d-91c9-40b6-8cbc-75f4ecdee2da" class="block-editor-block-list__block wp-block is-editing-disabled wp-block-navigation__submenu-container wp-block-page-list-item block-editor-block-list__layout">…</ul> aka getByRole('document', { name: 'Block: Page List Item' }) Call log: - Expect "toBeVisible" with timeout 5000ms - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('document', { name: 'Block: Page List' }) 114 | name: 'Block: Page List', 115 | } ) > 116 | ).toBeVisible(); | ^ 117 | 118 | await expect.poll( () => getDirtyEntityRecords( page ) ).toEqual( [] ); 119 | at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-passive-rendering.spec.js:116:5

Check failure on line 116 in test/e2e/specs/editor/blocks/navigation-passive-rendering.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › specs/editor/blocks/navigation-passive-rendering.spec.js:61:2 › Navigation passive rendering › does not dirty related template parts or navigation menus when rendered in the post editor

1) [chromium] › specs/editor/blocks/navigation-passive-rendering.spec.js:61:2 › Navigation passive rendering › does not dirty related template parts or navigation menus when rendered in the post editor Error: expect(locator).toBeVisible() failed Locator: locator('[name="editor-canvas"]').contentFrame().getByRole('document', { name: 'Block: Page List' }) Expected: visible Error: strict mode violation: getByRole('document', { name: 'Block: Page List' }) resolved to 2 elements: 1) <ul inert="true" tabindex="-1" role="document" data-title="Page List" data-type="core/page-list" aria-label="Block: Page List" id="block-c05e297b-061b-4598-8d93-812389f45285" data-block="c05e297b-061b-4598-8d93-812389f45285" class="block-editor-block-list__block wp-block is-editing-disabled wp-block-page-list open-always wp-block-page-list block-editor-block-list__layout">…</ul> aka getByRole('document', { name: 'Block: Page List', exact: true }) 2) <ul inert="true" tabindex="-1" role="document" data-title="Page List Item" data-type="core/page-list-item" aria-label="Block: Page List Item" id="block-96c3354b-edb7-4c5c-840a-923dce2d8c39" data-block="96c3354b-edb7-4c5c-840a-923dce2d8c39" class="block-editor-block-list__block wp-block is-editing-disabled wp-block-navigation__submenu-container wp-block-page-list-item block-editor-block-list__layout">…</ul> aka getByRole('document', { name: 'Block: Page List Item' }) Call log: - Expect "toBeVisible" with timeout 5000ms - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('document', { name: 'Block: Page List' }) 114 | name: 'Block: Page List', 115 | } ) > 116 | ).toBeVisible(); | ^ 117 | 118 | await expect.poll( () => getDirtyEntityRecords( page ) ).toEqual( [] ); 119 | at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-passive-rendering.spec.js:116:5

await expect.poll( () => getDirtyEntityRecords( page ) ).toEqual( [] );
Comment thread
adamziel marked this conversation as resolved.
Resolved

await editor.canvas
.getByRole( 'document', { name: 'Block: Paragraph' } )
.click();
await page.keyboard.press( 'End' );
await page.keyboard.type( ' Edited.' );

await expect
.poll( () => getDirtyEntityRecords( page ) )
.toEqual( [ { kind: 'postType', name: 'post', key: post.id } ] );
} );
} );
Loading