From 226df919cb5b467352abc01d493baa50ec46d07a Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com> Date: Mon, 29 May 2023 10:47:00 +0200 Subject: [PATCH] Lightbox UI appearing with interactivity experiment disabled (#51025) * Fix lightbox ui appearing with interactivity experiment disabled * Update e2e tests to enable the experiment --- lib/experimental/editor-settings.php | 3 +++ packages/block-editor/src/hooks/behaviors.js | 13 +++++----- .../specs/editor/various/behaviors.spec.js | 25 ++++++++++++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 67e08265558e1..f0b16eeb7f257 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -89,6 +89,9 @@ function gutenberg_enable_experiments() { if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-enhancements', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnablePatternEnhancements = true', 'before' ); } + if ( $gutenberg_experiments && array_key_exists( 'gutenberg-interactivity-api-core-blocks', $gutenberg_experiments ) ) { + wp_add_inline_script( 'wp-block-editor', 'window.__experimentalInteractivityAPI = true', 'before' ); + } } diff --git a/packages/block-editor/src/hooks/behaviors.js b/packages/block-editor/src/hooks/behaviors.js index 7c2c0164640b2..8e6ce479f174d 100644 --- a/packages/block-editor/src/hooks/behaviors.js +++ b/packages/block-editor/src/hooks/behaviors.js @@ -38,7 +38,6 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => { const settings = select( blockEditorStore ).getSettings()?.__experimentalFeatures ?.blocks?.[ props.name ]?.behaviors; - if ( ! settings || // If every behavior is disabled, do not show the behaviors inspector control. @@ -102,8 +101,10 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => { }; }, 'withBehaviors' ); -addFilter( - 'editor.BlockEdit', - 'core/behaviors/with-inspector-control', - withBehaviors -); +if ( window?.__experimentalInteractivityAPI ) { + addFilter( + 'editor.BlockEdit', + 'core/behaviors/with-inspector-control', + withBehaviors + ); +} diff --git a/test/e2e/specs/editor/various/behaviors.spec.js b/test/e2e/specs/editor/various/behaviors.spec.js index 1559723a944bd..12be68b8f9479 100644 --- a/test/e2e/specs/editor/various/behaviors.spec.js +++ b/test/e2e/specs/editor/various/behaviors.spec.js @@ -21,9 +21,32 @@ test.describe( 'Testing behaviors functionality', () => { await requestUtils.activateTheme( 'twentytwentyone' ); await requestUtils.deleteAllPosts(); } ); + test.beforeEach( async ( { admin, page, requestUtils } ) => { + await requestUtils.deleteAllMedia(); + await admin.visitAdminPage( + '/admin.php', + 'page=gutenberg-experiments' + ); + + await page + .locator( `#gutenberg-interactivity-api-core-blocks` ) + .setChecked( true ); + await page.locator( `input[name="submit"]` ).click(); + await page.waitForLoadState(); + } ); - test.afterEach( async ( { requestUtils } ) => { + test.afterEach( async ( { admin, page, requestUtils } ) => { await requestUtils.deleteAllMedia(); + await admin.visitAdminPage( + '/admin.php', + 'page=gutenberg-experiments' + ); + + await page + .locator( `#gutenberg-interactivity-api-core-blocks` ) + .setChecked( false ); + await page.locator( `input[name="submit"]` ).click(); + await page.waitForLoadState(); } ); test( '`No Behaviors` should be the default as defined in the core theme.json', async ( {