From 892f501d4bdd495c87a661bb174492b5f0d5d80a Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Thu, 30 May 2024 10:44:57 +0200 Subject: [PATCH] Test protected fields are not editable --- .../editor/various/block-bindings.spec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/e2e/specs/editor/various/block-bindings.spec.js b/test/e2e/specs/editor/various/block-bindings.spec.js index e99e73d858450..658c11f3b709b 100644 --- a/test/e2e/specs/editor/various/block-bindings.spec.js +++ b/test/e2e/specs/editor/various/block-bindings.spec.js @@ -1381,6 +1381,64 @@ test.describe( 'Block bindings', () => { previewPage.locator( '#paragraph-binding' ) ).toHaveText( 'new value' ); } ); + + test( 'should NOT be possible to edit the value of the custom field when it is protected', async ( { + editor, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + anchor: 'protected-field-binding', + content: 'fallback value', + metadata: { + bindings: { + content: { + source: 'core/post-meta', + args: { key: '_protected_field' }, + }, + }, + }, + }, + } ); + + const protectedFieldBlock = editor.canvas.getByRole( + 'document', + { + name: 'Block: Paragraph', + } + ); + + await expect( protectedFieldBlock ).not.toBeEditable(); + } ); + + test( 'should NOT be possible to edit the value of the custom field when it is not shown in the REST API', async ( { + editor, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + anchor: 'show-in-rest-false-binding', + content: 'fallback value', + metadata: { + bindings: { + content: { + source: 'core/post-meta', + args: { key: 'show_in_rest_false_field' }, + }, + }, + }, + }, + } ); + + const showInRestFalseBlock = editor.canvas.getByRole( + 'document', + { + name: 'Block: Paragraph', + } + ); + + await expect( showInRestFalseBlock ).not.toBeEditable(); + } ); } ); test.describe( 'Heading', () => {