Skip to content

Commit

Permalink
Fix detaching patterns when a pattern has overrides, but there are no…
Browse files Browse the repository at this point in the history
… override values (WordPress#62014)

* Fix detaching patterns when there are no overrides

* Add e2e test for detaching pattern that supports overrides but has no override values

Co-authored-by: talldan <[email protected]>
Co-authored-by: SantosGuillamot <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
4 people authored May 27, 2024
1 parent a251d11 commit d6ff9bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/patterns/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export const convertSyncedPatternToStatic =
metadata = { ...metadata };
delete metadata.id;
delete metadata.bindings;
// Use overriden values of the pattern block if they exist.
if ( existingOverrides[ metadata.name ] ) {
// Use overridden values of the pattern block if they exist.
if ( existingOverrides?.[ metadata.name ] ) {
// Iterate over each overriden attribute.
for ( const [ attributeName, value ] of Object.entries(
existingOverrides[ metadata.name ]
Expand Down
41 changes: 41 additions & 0 deletions test/e2e/specs/editor/various/pattern-overrides.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,47 @@ test.describe( 'Pattern Overrides', () => {
] );
} );

// See https://github.com/WordPress/gutenberg/pull/62014.
test( 'can convert a pattern block to regular blocks when the pattern supports overrides but not override values', async ( {
admin,
requestUtils,
editor,
} ) => {
const paragraphName = 'paragraph-name';
const { id } = await requestUtils.createBlock( {
title: 'Pattern',
content: `<!-- wp:paragraph {"metadata":{"name":"${ paragraphName }","bindings":{"content":{"source":"core/pattern-overrides"}}}} -->
<p>Editable</p>
<!-- /wp:paragraph -->`,
status: 'publish',
} );

await admin.createNewPost();

await editor.insertBlock( {
name: 'core/block',
attributes: { ref: id },
} );

// Convert back to regular blocks.
await editor.selectBlocks(
editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } )
);
await editor.showBlockToolbar();
await editor.clickBlockOptionsMenuItem( 'Detach' );

// Check that the overrides remain.
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: {
content: 'Editable',
metadata: { name: paragraphName },
},
},
] );
} );

test( "handles button's link settings", async ( {
page,
admin,
Expand Down

0 comments on commit d6ff9bf

Please sign in to comment.