Skip to content

Commit

Permalink
WIP - add first pass at initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed May 5, 2024
1 parent f9908e5 commit 6fe9729
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Lightbox Allow Editing False Enabled False
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-lightbox-allow-editing-false-enabled-false
*/

function filter_theme_json_theme( $theme_json ) {
$new_data = array(
'version' => 2,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'allowEditing' => false,
'enabled' => false,
),
),
),
),
);
// $theme_json = WP_Theme_JSON_Resolver::get_theme_data();
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'filter_theme_json_theme' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Lightbox Allow Editing False Enabled True
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-lightbox-allow-editing-false-enabled-true
*/

function filter_theme_json_theme( $theme_json ) {
$new_data = array(
'version' => 2,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'allowEditing' => false,
'enabled' => true,
),
),
),
),
);
// $theme_json = WP_Theme_JSON_Resolver::get_theme_data();
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'filter_theme_json_theme' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Lightbox Allow Editing True Enabled False
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-lightbox-allow-editing-true-enabled-false
*/

function filter_theme_json_theme( $theme_json ) {
$new_data = array(
'version' => 2,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'allowEditing' => true,
'enabled' => false,
),
),
),
),
);
// $theme_json = WP_Theme_JSON_Resolver::get_theme_data();
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'filter_theme_json_theme' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Lightbox Allow Editing True Enabled true
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-lightbox-allow-editing-true-enabled-true
*/

function filter_theme_json_theme( $theme_json ) {
$new_data = array(
'version' => 2,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'allowEditing' => true,
'enabled' => true,
),
),
),
),
);
// $theme_json = WP_Theme_JSON_Resolver::get_theme_data();
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'filter_theme_json_theme' );
57 changes: 51 additions & 6 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,7 @@ test.describe( 'Image', () => {
} );
} );

// Skipping these tests for now as we plan
// to update them to use the new lightbox syntax
// once it's merged -- see the following PRs
// https://github.com/WordPress/gutenberg/pull/53851
// https://github.com/WordPress/gutenberg/pull/54071
test.describe.skip( 'Image - interactivity', () => {
test.describe.only( 'Image - lightbox', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllMedia();
} );
Expand All @@ -865,6 +860,56 @@ test.describe.skip( 'Image - interactivity', () => {
await requestUtils.deleteAllMedia();
} );

test.describe.only( 'should respect theme.json settings and block overrides', () => {
let uploadedMedia;

test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllMedia();

uploadedMedia = await requestUtils.uploadMedia(
path.resolve(
process.cwd(),
'test/e2e/assets/10x10_e2e_test_image_z9T8jK.png'
)
);
} );

test( 'Block settings - link DISABLED, lightbox UNDEFINED - should hide UI and disable lightbox when block override is undefined', async ( {
admin,
editor,
page,
requestUtils,
} ) => {
await requestUtils.activatePlugin(
'lightbox-allow-editing-false-enabled-false'
);

await admin.createNewPost(
'post',
'Lightbox Test',
`<!-- wp:image {"id":${ uploadedMedia.id },"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="${ uploadedMedia.url }" alt="" class="wp-image-${ uploadedMedia.id }"/></figure>
<!-- /wp:image --> `
);

const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);

await imageBlock.click();
await page.getByLabel( 'Block tools' ).getByLabel( 'Link' ).click();

await expect(
page.getByRole( 'menuitem', {
name: 'Expand on click',
} )
).toBeHidden();

const postId = await editor.publishPost();
await page.goto( `/?p=${ postId }` );
} );
} );

test.describe( 'tests using uploaded image', () => {
let filename = null;

Expand Down

0 comments on commit 6fe9729

Please sign in to comment.