From 8bd6729054f01e080b9a1a5883d25ab89f9c0cb0 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 3 Oct 2023 22:26:44 +0400 Subject: [PATCH 1/3] Migrate 'iframed masonry block' tests to Playwright --- .../plugins/iframed-masonry-block.php | 7 --- .../plugins/iframed-masonry-block.spec.js | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js diff --git a/packages/e2e-tests/plugins/iframed-masonry-block.php b/packages/e2e-tests/plugins/iframed-masonry-block.php index ebfbdb6b1257ec..51109bbbfb8195 100644 --- a/packages/e2e-tests/plugins/iframed-masonry-block.php +++ b/packages/e2e-tests/plugins/iframed-masonry-block.php @@ -7,13 +7,6 @@ * @package gutenberg-test-iframed-masonry-block */ -add_action( - 'setup_theme', - static function () { - add_theme_support( 'block-templates' ); - } -); - add_action( 'init', static function () { diff --git a/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js b/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js new file mode 100644 index 00000000000000..e96235c724bf44 --- /dev/null +++ b/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js @@ -0,0 +1,46 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'iframed masonry block', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activatePlugin( + 'gutenberg-test-iframed-masonry-block' + ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deactivatePlugin( + 'gutenberg-test-iframed-masonry-block' + ); + } ); + + test( 'should load script and dependencies in iframe', async ( { + editor, + } ) => { + await editor.insertBlock( { name: 'test/iframed-masonry-block' } ); + + const masonry = editor.canvas.getByRole( 'document', { + name: 'Block: Iframed Masonry Block', + } ); + await expect( masonry ).toBeVisible(); + + const masonryHeight = await masonry.evaluate( ( node ) => + parseInt( node.style.height, 10 ) + ); + + // Expect Masonry to set a non-zero height. + expect( masonryHeight ).toBeGreaterThan( 0 ); + + // Expect Masonry to absolute position items. + await expect( masonry.locator( '.grid-item' ).first() ).toHaveCSS( + 'position', + 'absolute' + ); + } ); +} ); From 6b4433e4a533d0f7b938a218855c523c1a3b4381 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 3 Oct 2023 22:27:51 +0400 Subject: [PATCH 2/3] Remove old test files --- .../iframed-masonry-block.test.js.snap | 7 --- .../plugins/iframed-masonry-block.test.js | 49 ------------------- 2 files changed, 56 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/plugins/__snapshots__/iframed-masonry-block.test.js.snap delete mode 100644 packages/e2e-tests/specs/editor/plugins/iframed-masonry-block.test.js diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/iframed-masonry-block.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/iframed-masonry-block.test.js.snap deleted file mode 100644 index a37b33cdc3f410..00000000000000 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/iframed-masonry-block.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`iframed masonry block should load script and dependencies in iframe 1`] = ` -" -
-" -`; diff --git a/packages/e2e-tests/specs/editor/plugins/iframed-masonry-block.test.js b/packages/e2e-tests/specs/editor/plugins/iframed-masonry-block.test.js deleted file mode 100644 index 503beeb92e1642..00000000000000 --- a/packages/e2e-tests/specs/editor/plugins/iframed-masonry-block.test.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * WordPress dependencies - */ -import { - activatePlugin, - createNewPost, - deactivatePlugin, - insertBlock, - getEditedPostContent, - canvas, - createNewTemplate, -} from '@wordpress/e2e-test-utils'; - -async function didMasonryLoadCorrectly( context ) { - return await context.evaluate( () => { - const container = document.querySelector( - '.wp-block-test-iframed-masonry-block' - ); - return ( - // Expect Masonry to set a non-zero height. - parseInt( container.style.height, 10 ) > 0 && - // Expect Masonry to absolute position items. - container.firstElementChild.style.position === 'absolute' - ); - } ); -} - -describe( 'iframed masonry block', () => { - beforeEach( async () => { - await activatePlugin( 'gutenberg-test-iframed-masonry-block' ); - await createNewPost( { postType: 'page' } ); - } ); - - afterEach( async () => { - await deactivatePlugin( 'gutenberg-test-iframed-masonry-block' ); - } ); - - it( 'should load script and dependencies in iframe', async () => { - await insertBlock( 'Iframed Masonry Block' ); - - expect( await getEditedPostContent() ).toMatchSnapshot(); - expect( await didMasonryLoadCorrectly( canvas() ) ).toBe( true ); - - await createNewTemplate( 'Iframed Test' ); - await canvas().waitForSelector( '.grid-item[style]' ); - - expect( await didMasonryLoadCorrectly( canvas() ) ).toBe( true ); - } ); -} ); From 9a66431a2f755331fcef34bd1b9f0fe8428f1dcd Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 4 Oct 2023 08:18:39 +0400 Subject: [PATCH 3/3] Use boundingBox --- test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js b/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js index e96235c724bf44..edc6b0a68cd4ab 100644 --- a/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js +++ b/test/e2e/specs/editor/plugins/iframed-masonry-block.spec.js @@ -30,12 +30,10 @@ test.describe( 'iframed masonry block', () => { } ); await expect( masonry ).toBeVisible(); - const masonryHeight = await masonry.evaluate( ( node ) => - parseInt( node.style.height, 10 ) - ); + const masonryBox = await masonry.boundingBox(); // Expect Masonry to set a non-zero height. - expect( masonryHeight ).toBeGreaterThan( 0 ); + expect( masonryBox.height ).toBeGreaterThan( 0 ); // Expect Masonry to absolute position items. await expect( masonry.locator( '.grid-item' ).first() ).toHaveCSS(