Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: add a new spec for for adding an unsynced pattern #54892

Merged
merged 10 commits into from
Sep 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test.describe( 'Unsynced pattern', () => {
name: 'core/paragraph',
attributes: { content: 'A useful paragraph to reuse' },
} );
const before = await editor.getBlocks();

// Create an unsynced pattern from the paragraph block.
await editor.showBlockToolbar();
Expand All @@ -31,18 +32,18 @@ test.describe( 'Unsynced pattern', () => {
await createPatternDialog
.getByRole( 'textbox', { name: 'Name' } )
.fill( 'My unsynced pattern' );
await page.getByLabel( 'Synced' ).click();
await createPatternDialog.getByRole( 'checkbox' ).setChecked( false );
glendaviesnz marked this conversation as resolved.
Show resolved Hide resolved

await page.keyboard.press( 'Enter' );
const content = await editor.getEditedPostContent();

// Check that the block content is still the same. If the pattern was added as synced
// the content would be wrapped by a pattern block.
expect( content ).toBe(
`<!-- wp:paragraph -->
<p>A useful paragraph to reuse</p>
<!-- /wp:paragraph -->`
);
await expect
.poll(
editor.getBlocks,
'The block content should be the same after converting to an unsynced pattern'
)
.toEqual( before );

// Check that the new pattern is availble in the inserter and that it gets inserted as
// a plain paragraph block.
Expand All @@ -54,15 +55,18 @@ test.describe( 'Unsynced pattern', () => {
.fill( 'My unsynced pattern' );
await page.getByLabel( 'My unsynced pattern' ).click();

const updatedContent = await editor.getEditedPostContent();
expect( updatedContent ).toBe(
`<!-- wp:paragraph -->
<p>A useful paragraph to reuse</p>
<!-- /wp:paragraph -->
// Just get the block name and content to compare as the clientIDs will be different.
const originalBlock = await before.map( ( block ) => ( {
name: block.name,
content: block.attributes.content,
} ) );

<!-- wp:paragraph -->
<p>A useful paragraph to reuse</p>
<!-- /wp:paragraph -->`
);
const newBlocks = await editor.getBlocks();
expect(
newBlocks.map( ( block ) => ( {
name: block.name,
content: block.attributes.content,
} ) )
).toEqual( [ ...originalBlock, ...originalBlock ] );
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
} );
} );
Loading