Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
78f9601
Pattern overrides: use block binding editing API
ellatrix May 9, 2024
17b31b8
Update only the needed attributes with bindings
SantosGuillamot May 9, 2024
63c6b6d
Keep blocks as normal when editing pattern
SantosGuillamot May 9, 2024
46063db
Use inner blocks for set edit mode
SantosGuillamot May 9, 2024
f1f78ae
Change indiviual reset logic
SantosGuillamot May 9, 2024
8121723
Move variable after early return
SantosGuillamot May 9, 2024
ec4daec
Add inline comment for bindings setAttributes
SantosGuillamot May 9, 2024
35aa0ab
Change variable to isOverriden
SantosGuillamot May 9, 2024
a71ba38
Change missing isOverriden
SantosGuillamot May 9, 2024
29afc1f
Fix detaching of synced patterns
SantosGuillamot May 9, 2024
31bf94c
Sync values of bound attributes
SantosGuillamot May 9, 2024
6c60eb3
Adapt synced pattern tests
SantosGuillamot May 9, 2024
49b062a
Use overriden values when detaching pattern
SantosGuillamot May 9, 2024
766a762
Adapt pattern-overrides tests
SantosGuillamot May 9, 2024
49286e1
Add workaround for pattern overrides
SantosGuillamot May 9, 2024
ef29ab3
Don't update non-bound attributes when using patterns
SantosGuillamot May 9, 2024
ba8b618
Add test for blocks with a shared name
SantosGuillamot May 9, 2024
e695fb4
Support button rel in bindings editor logic
SantosGuillamot May 9, 2024
d9d9fd6
Solve undo/redo issues
SantosGuillamot May 9, 2024
4a4465f
Stop using syncDerivedUpdates
SantosGuillamot May 9, 2024
1101667
Ensure change is marked as persistent in pattern overrides
SantosGuillamot May 9, 2024
a95749f
Try to solve undo/redo issues
SantosGuillamot May 9, 2024
e2a1b8a
Manage undefined attrs in pattern overrides
SantosGuillamot May 9, 2024
9d444a3
Remove `content` pattern property if empty
SantosGuillamot May 9, 2024
e28da53
Remove pattern-overrides specific code from `withBlockBindingSupport`…
talldan May 13, 2024
ae534d8
Fix persistent issues with setValues API
ellatrix May 13, 2024
4ec7315
Fall back to ''
ellatrix May 13, 2024
3a7311d
Make sure any previous changes are persisted before resetting.
ellatrix May 13, 2024
e013f6d
Add undo/redo test for resetting
kevin940726 May 13, 2024
950aab9
Fix test... 🤦
kevin940726 May 13, 2024
d99ecb7
Fix remaining undo test
ellatrix May 13, 2024
9ec9bba
Fix individual reset
ellatrix May 13, 2024
7d72a34
Add test for undoing loses the focus
kevin940726 May 13, 2024
4ebdb09
Fix reset button test
ellatrix May 13, 2024
44b51dd
Simplify pattern synced blocks test
SantosGuillamot May 13, 2024
5975f74
Remove focus test
SantosGuillamot May 13, 2024
10fa4e8
Use getBlockParentsByBlockName
SantosGuillamot May 14, 2024
3cfdd44
Add early return if blockName doesn't exist
SantosGuillamot May 14, 2024
8c5f574
Add comment for undefined values
SantosGuillamot May 14, 2024
3866446
Remove comment typo
SantosGuillamot May 14, 2024
33bfb86
Remove unnecessary includeHidden from tests
SantosGuillamot May 14, 2024
d80aba7
Check the frontend in patterns test
SantosGuillamot May 14, 2024
6b97321
Check frontend in updated pattern
SantosGuillamot May 14, 2024
c122b79
Stop using `getPatternRecord`
SantosGuillamot May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt synced pattern tests
  • Loading branch information
SantosGuillamot committed May 9, 2024
commit 6c60eb3990c772bcfe3f246981060829dda1b338
186 changes: 113 additions & 73 deletions test/e2e/specs/editor/various/patterns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
*/
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();
Expand Down Expand Up @@ -149,28 +157,22 @@ test.describe( 'Synced pattern', () => {
.getByRole( 'button', { name: 'Create' } )
.click();

await expect
.poll(
editor.getBlocks,
'The block content should be wrapped by a pattern block wrapper'
)
.toEqual( [
{
name: 'core/block',
attributes: { ref: expect.any( Number ) },
innerBlocks: [
{
attributes: {
content: 'A useful paragraph to reuse',
dropCap: false,
},
innerBlocks: [],
name: 'core/paragraph',
},
],
},
] );
const after = await editor.getBlocks();
// Wait until the pattern is inserted.
await editor.canvas
.getByRole( 'document', {
name: 'Block: Pattern',
} )
.waitFor();

const [ syncedPattern ] = await editor.getBlocks();
const patternRecord = await getPatternRecord(
page,
syncedPattern?.attributes?.ref
);

expect( patternRecord?.content ).toBe(
'<!-- wp:paragraph -->\n<p>A useful paragraph to reuse</p>\n<!-- /wp:paragraph -->'
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. We can just assert that the post content includes the <!-- wp:block --> block. Then we can visit the frontend to verify that the rendered post includes the pattern content (paragraph in this case.)

This kind of test only has to be done once and we only have to check that it contains wp:block in the remaining tests.

I think this also matches more closely to what the end users would expect. The tests are only what they seem because it's easier this way in the previous implementation, but they are technically testing implementation details.


const patternBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Pattern',
Expand All @@ -191,7 +193,30 @@ test.describe( 'Synced pattern', () => {
.click();
await page.getByRole( 'option', { name: 'My synced pattern' } ).click();

await expect.poll( editor.getBlocks ).toEqual( [ ...after, ...after ] );
const [ firstSyncedPattern, secondSyncedPattern ] =
await editor.getBlocks();
const firstSyncedPatternRecord = await getPatternRecord(
page,
firstSyncedPattern?.attributes?.ref
);
const secondSyncedPatternRecord = await getPatternRecord(
page,
secondSyncedPattern?.attributes?.ref
);
// Check first pattern is "My synced pattern".
expect( firstSyncedPatternRecord?.title ).toEqual(
'My synced pattern'
);
expect( firstSyncedPatternRecord?.content ).toEqual(
'<!-- wp:paragraph -->\n<p>A useful paragraph to reuse</p>\n<!-- /wp:paragraph -->'
);
// Check second pattern is "My synced pattern".
expect( secondSyncedPatternRecord?.title ).toEqual(
'My synced pattern'
);
expect( secondSyncedPatternRecord?.content ).toEqual(
'<!-- wp:paragraph -->\n<p>A useful paragraph to reuse</p>\n<!-- /wp:paragraph -->'
);
} );

// Check for regressions of https://github.com/WordPress/gutenberg/issues/33072.
Expand Down Expand Up @@ -254,22 +279,15 @@ test.describe( 'Synced pattern', () => {
// Go back to the post.
await editorTopBar.getByRole( 'button', { name: 'Back' } ).click();

await expect.poll( editor.getBlocks ).toEqual( [
{
name: 'core/block',
attributes: { ref: id },
innerBlocks: [
{
name: 'core/paragraph',
attributes: {
content: 'Einen Guten Tag!',
dropCap: false,
},
innerBlocks: [],
},
],
},
] );
const [ syncedPattern ] = await editor.getBlocks();
const patternRecord = await getPatternRecord(
page,
syncedPattern?.attributes?.ref
);

expect( patternRecord?.content ).toBe(
'<!-- wp:paragraph -->\n<p>Einen Guten Tag!</p>\n<!-- /wp:paragraph -->'
);
} );

// Check for regressions of https://github.com/WordPress/gutenberg/issues/26421.
Expand Down Expand Up @@ -325,13 +343,16 @@ test.describe( 'Synced pattern', () => {
attributes: { content: 'After Edit' },
};

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/block',
attributes: { ref: id },
innerBlocks: [ expectedParagraphBlock ],
},
] );
// 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' } )
Expand All @@ -345,6 +366,7 @@ test.describe( 'Synced pattern', () => {

test( 'can be created, inserted, and converted to a regular block', async ( {
editor,
page,
requestUtils,
} ) => {
const { id } = await requestUtils.createBlock( {
Expand All @@ -359,19 +381,24 @@ 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(
'<!-- wp:paragraph -->\n<p>Hello there!</p>\n<!-- /wp:paragraph -->'
);

const expectedParagraphBlock = {
name: 'core/paragraph',
attributes: { content: 'Hello there!' },
};

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/block',
attributes: { ref: id },
innerBlocks: [ expectedParagraphBlock ],
},
] );

await editor.selectBlocks(
editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } )
);
Expand Down Expand Up @@ -413,22 +440,20 @@ test.describe( 'Synced pattern', () => {
await page.keyboard.type( '/Awesome block' );
await page.getByRole( 'option', { name: 'Awesome block' } ).click();

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/block',
attributes: { ref: expect.any( Number ) },
innerBlocks: [
{
name: 'core/paragraph',
attributes: { content: 'Awesome Paragraph' },
},
],
},
] );
const [ syncedPattern ] = await editor.getBlocks();
const patternRecord = await getPatternRecord(
page,
syncedPattern?.attributes?.ref
);

expect( patternRecord?.content ).toBe(
'<!-- wp:paragraph -->\n<p>Awesome Paragraph</p>\n<!-- /wp:paragraph -->'
);
} );

test( 'can be created from multiselection and converted back to regular blocks', async ( {
editor,
page,
pageUtils,
} ) => {
await editor.insertBlock( {
Expand Down Expand Up @@ -467,13 +492,28 @@ test.describe( 'Synced pattern', () => {
},
];

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/block',
attributes: { ref: expect.any( Number ) },
innerBlocks: expectedParagraphBlocks,
},
] );
// Wait until the pattern is created.
await editor.canvas
.getByRole( 'document', {
name: 'Block: Pattern',
} )
.waitFor();

const [ syncedPattern ] = await editor.getBlocks();
const patternRecord = await getPatternRecord(
page,
syncedPattern?.attributes?.ref
);

expect( patternRecord?.content ).toBe(
`<!-- wp:paragraph -->
<p>Hello there!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Second paragraph</p>
<!-- /wp:paragraph -->`
);

await editor.selectBlocks(
editor.canvas.getByRole( 'document', { name: 'Block: Pattern' } )
Expand Down