diff --git a/test/e2e/specs/editor/various/patterns.spec.js b/test/e2e/specs/editor/various/patterns.spec.js index 395c1234f54613..48eaf9e08c9b94 100644 --- a/test/e2e/specs/editor/various/patterns.spec.js +++ b/test/e2e/specs/editor/various/patterns.spec.js @@ -3,14 +3,6 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -async function getPatternRecord( page, patternRef ) { - return await page.evaluate( async ( ref ) => { - return window.wp.data - .select( 'core' ) - .getEditedEntityRecord( 'postType', 'wp_block', ref ); - }, patternRef ); -} - test.describe( 'Unsynced pattern', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.deleteAllBlocks(); @@ -324,35 +316,21 @@ test.describe( 'Synced pattern', () => { // Go back to the post. await editorTopBar.getByRole( 'button', { name: 'Back' } ).click(); - const expectedParagraphBlock = { - name: 'core/paragraph', - attributes: { content: 'After Edit' }, - }; - - // It seems edited values are stored in the `blocks` array. - const [ syncedPattern ] = await editor.getBlocks(); - const [ modifiedBlock ] = ( - await getPatternRecord( page, syncedPattern?.attributes?.ref ) - )?.blocks; - - expect( modifiedBlock?.name ).toBe( expectedParagraphBlock.name ); - expect( modifiedBlock?.attributes?.content ).toBe( - expectedParagraphBlock.attributes.content - ); - await editor.selectBlocks( editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } ) ); await editor.clickBlockOptionsMenuItem( 'Detach' ); - await expect - .poll( editor.getBlocks ) - .toMatchObject( [ expectedParagraphBlock ] ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: 'After Edit' }, + }, + ] ); } ); test( 'can be created, inserted, and converted to a regular block', async ( { editor, - page, requestUtils, } ) => { const { id } = await requestUtils.createBlock( { @@ -367,32 +345,23 @@ test.describe( 'Synced pattern', () => { attributes: { ref: id }, } ); - // Wait until the pattern is created and inserted. - await editor.canvas.locator( 'text=Hello there!' ).waitFor(); - - const [ syncedPattern ] = await editor.getBlocks(); - const patternRecord = await getPatternRecord( - page, - syncedPattern?.attributes?.ref - ); - - expect( patternRecord?.content ).toBe( - '\n

Hello there!

\n' - ); - - const expectedParagraphBlock = { - name: 'core/paragraph', - attributes: { content: 'Hello there!' }, - }; + // Check that only the pattern block is present. + const existingBlocks = await editor.getBlocks(); + expect( + existingBlocks.every( ( block ) => block.name === 'core/block' ) + ).toBe( true ); await editor.selectBlocks( editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } ) ); await editor.clickBlockOptionsMenuItem( 'Detach' ); - await expect - .poll( editor.getBlocks ) - .toMatchObject( [ expectedParagraphBlock ] ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: 'Hello there!' }, + }, + ] ); } ); test( 'can be inserted after refresh', async ( { @@ -426,20 +395,15 @@ test.describe( 'Synced pattern', () => { await page.keyboard.type( '/Awesome block' ); await page.getByRole( 'option', { name: 'Awesome block' } ).click(); - const [ syncedPattern ] = await editor.getBlocks(); - const patternRecord = await getPatternRecord( - page, - syncedPattern?.attributes?.ref - ); - - expect( patternRecord?.content ).toBe( - '\n

Awesome Paragraph

\n' - ); + // Check that the pattern block is present. + const existingBlocks = await editor.getBlocks(); + expect( + existingBlocks.every( ( block ) => block.name === 'core/block' ) + ).toBe( true ); } ); test( 'can be created from multiselection and converted back to regular blocks', async ( { editor, - page, pageUtils, } ) => { await editor.insertBlock( { @@ -467,17 +431,6 @@ test.describe( 'Synced pattern', () => { .getByRole( 'button', { name: 'Create' } ) .click(); - const expectedParagraphBlocks = [ - { - name: 'core/paragraph', - attributes: { content: 'Hello there!' }, - }, - { - name: 'core/paragraph', - attributes: { content: 'Second paragraph' }, - }, - ]; - // Wait until the pattern is created. await editor.canvas .getByRole( 'document', { @@ -485,30 +438,28 @@ test.describe( 'Synced pattern', () => { } ) .waitFor(); - const [ syncedPattern ] = await editor.getBlocks(); - const patternRecord = await getPatternRecord( - page, - syncedPattern?.attributes?.ref - ); - - expect( patternRecord?.content ).toBe( - ` -

Hello there!

- - - -

Second paragraph

-` - ); + // Check that only the pattern block is present. + const existingBlocks = await editor.getBlocks(); + expect( + existingBlocks.every( ( block ) => block.name === 'core/block' ) + ).toBe( true ); + // Convert the pattern back to regular blocks. await editor.selectBlocks( editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } ) ); await editor.clickBlockOptionsMenuItem( 'Detach' ); - await expect - .poll( editor.getBlocks ) - .toMatchObject( expectedParagraphBlocks ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: 'Hello there!' }, + }, + { + name: 'core/paragraph', + attributes: { content: 'Second paragraph' }, + }, + ] ); } ); // Check for regressions of https://github.com/WordPress/gutenberg/pull/26484.