-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Transform: select all blocks if the result has more than one block #45015
Changes from 5 commits
8e5705c
8b48865
28b1223
093b38a
55f03fa
ceadd20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- wp:paragraph --> | ||
<p>1</p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:paragraph --> | ||
<p>2</p> | ||
<!-- /wp:paragraph --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!-- wp:list --> | ||
<ul><!-- wp:list-item --> | ||
<li>1</li> | ||
<!-- /wp:list-item --> | ||
|
||
<!-- wp:list-item --> | ||
<li>2</li> | ||
<!-- /wp:list-item --></ul> | ||
<!-- /wp:list --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!-- wp:list --> | ||
<ul><!-- wp:list-item --> | ||
<li>1</li> | ||
<!-- /wp:list-item --> | ||
|
||
<!-- wp:list-item --> | ||
<li>2</li> | ||
<!-- /wp:list-item --></ul> | ||
<!-- /wp:list --> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1231,4 +1231,38 @@ test.describe( 'List', () => { | |||||||||||||||||||||
|
||||||||||||||||||||||
expect( await editor.getEditedPostContent() ).toMatchSnapshot(); | ||||||||||||||||||||||
} ); | ||||||||||||||||||||||
|
||||||||||||||||||||||
test( 'selects all transformed output', async ( { editor, page } ) => { | ||||||||||||||||||||||
await editor.insertBlock( { | ||||||||||||||||||||||
name: 'core/list', | ||||||||||||||||||||||
innerBlocks: [ | ||||||||||||||||||||||
{ name: 'core/list-item', attributes: { content: '1' } }, | ||||||||||||||||||||||
{ name: 'core/list-item', attributes: { content: '2' } }, | ||||||||||||||||||||||
], | ||||||||||||||||||||||
} ); | ||||||||||||||||||||||
|
||||||||||||||||||||||
await editor.selectBlocks( | ||||||||||||||||||||||
page.locator( 'role=document[name="Block: List"i]' ) | ||||||||||||||||||||||
); | ||||||||||||||||||||||
|
||||||||||||||||||||||
await page | ||||||||||||||||||||||
.getByRole( 'button', { | ||||||||||||||||||||||
name: 'List', | ||||||||||||||||||||||
description: 'List: Change block type or style', | ||||||||||||||||||||||
} ) | ||||||||||||||||||||||
.click(); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the In this case, I think we can do this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not that the description was needed, it's that I'd like to use it over more specificity. I would have liked to simply use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! I was looking at the wrong API docs. Strange that it's not an option here, it would be useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we should chain selectors here though. Selecting |
||||||||||||||||||||||
await page.getByRole( 'menuitem', { name: 'Paragraph' } ).click(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
expect( await editor.getEditedPostContent() ).toMatchSnapshot(); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per #45015 (comment), I don't think snapshot testing makes much sense here. The assertions here are not readable and feel disconnected from the title of the test case. Instead, we should prioritize explicit assertions and make them target the selected blocks. The same goes for the last snapshot assertion in this test case. |
||||||||||||||||||||||
|
||||||||||||||||||||||
await page | ||||||||||||||||||||||
.getByRole( 'button', { | ||||||||||||||||||||||
name: 'Paragraph', | ||||||||||||||||||||||
description: 'Change type of 2 blocks', | ||||||||||||||||||||||
} ) | ||||||||||||||||||||||
.click(); | ||||||||||||||||||||||
await page.getByRole( 'menuitem', { name: 'List' } ).click(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
expect( await editor.getEditedPostContent() ).toMatchSnapshot(); | ||||||||||||||||||||||
} ); | ||||||||||||||||||||||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this would be good to be added to the
replaceBlocks
thunk so that everywhere else will get the consistent behavior? TheinsertBlocks
action has a similarupdateSelection
optional options to this, so it might make sense to do something similar toreplaceBlocks
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I would love to do as well, but we can't change the behaviour now, unless we introduce yet another option to select all blocks. I think we shouldn't do that just yet until we find more use cases.