From 570e7d99c5e4e80f654be2f65aecb45d978469dd Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 13 Dec 2022 10:55:26 +0100 Subject: [PATCH] Fix content locked patterns (#46494) --- packages/block-editor/src/store/selectors.js | 4 +-- ...ocks-with-content-only-lock-1-chromium.txt | 5 +++ .../editor/various/content-only-lock.spec.js | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/e2e/specs/editor/various/__snapshots__/Content-only-lock-should-be-able-to-edit-the-content-of-blocks-with-content-only-lock-1-chromium.txt create mode 100644 test/e2e/specs/editor/various/content-only-lock.spec.js diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 36d3f42ae58bc..694f54bacdee0 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2690,8 +2690,8 @@ export const __unstableGetContentLockingParent = createSelector( ( state, clientId ) => { let current = clientId; let result; - while ( !! state.blocks.parents[ current ] ) { - current = state.blocks.parents[ current ]; + while ( state.blocks.parents.has( current ) ) { + current = state.blocks.parents.get( current ); if ( getTemplateLock( state, current ) === 'contentOnly' ) { result = current; } diff --git a/test/e2e/specs/editor/various/__snapshots__/Content-only-lock-should-be-able-to-edit-the-content-of-blocks-with-content-only-lock-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Content-only-lock-should-be-able-to-edit-the-content-of-blocks-with-content-only-lock-1-chromium.txt new file mode 100644 index 0000000000000..18f0839c8dc89 --- /dev/null +++ b/test/e2e/specs/editor/various/__snapshots__/Content-only-lock-should-be-able-to-edit-the-content-of-blocks-with-content-only-lock-1-chromium.txt @@ -0,0 +1,5 @@ + +
+

Hello World

+
+ \ No newline at end of file diff --git a/test/e2e/specs/editor/various/content-only-lock.spec.js b/test/e2e/specs/editor/various/content-only-lock.spec.js new file mode 100644 index 0000000000000..41626ed986b8f --- /dev/null +++ b/test/e2e/specs/editor/various/content-only-lock.spec.js @@ -0,0 +1,31 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Content-only lock', () => { + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test( 'should be able to edit the content of blocks with content-only lock', async ( { + editor, + page, + pageUtils, + } ) => { + // Add content only locked block in the code editor + await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor + await page.click( '.editor-post-text-editor' ); + await page.keyboard + .type( ` +
+

Hello

+
+ ` ); + await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); + + await page.click( 'role=document[name="Paragraph block"i]' ); + await page.keyboard.type( ' World' ); + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + } ); +} );