-
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
Migrate remaining 'block switcher' e2e tests to Playwright #57381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,7 +8,183 @@ test.describe( 'Block Switcher', () => { | |||||
await admin.createNewPost(); | ||||||
} ); | ||||||
|
||||||
test( 'Block variation transforms', async ( { editor, page } ) => { | ||||||
test( 'Should show the expected block transforms on the list block when the blocks are removed', async ( { | ||||||
editor, | ||||||
page, | ||||||
pageUtils, | ||||||
} ) => { | ||||||
await editor.canvas | ||||||
.getByRole( 'button', { name: 'Add default block' } ) | ||||||
.click(); | ||||||
await page.keyboard.type( '- List content' ); | ||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await pageUtils.pressKeys( 'alt+F10' ); | ||||||
|
||||||
const blockSwitcher = page | ||||||
.getByRole( 'toolbar', { name: 'Block tools' } ) | ||||||
.getByRole( 'button', { name: 'List' } ); | ||||||
|
||||||
// Verify the block switcher exists. | ||||||
await expect( blockSwitcher ).toHaveAttribute( | ||||||
'aria-haspopup', | ||||||
'true' | ||||||
); | ||||||
|
||||||
// Verify the correct block transforms appear. | ||||||
await blockSwitcher.click(); | ||||||
await expect( | ||||||
page.getByRole( 'menu', { name: 'List' } ).getByRole( 'menuitem' ) | ||||||
).toHaveText( [ 'Paragraph', 'Heading', 'Quote', 'Columns', 'Group' ] ); | ||||||
} ); | ||||||
|
||||||
test( 'Should show the expected block transforms on the list block when the quote block is removed', async ( { | ||||||
editor, | ||||||
page, | ||||||
pageUtils, | ||||||
} ) => { | ||||||
// Remove the quote block from the list of registered blocks. | ||||||
await page.waitForFunction( () => { | ||||||
try { | ||||||
window.wp.blocks.unregisterBlockType( 'core/quote' ); | ||||||
return true; | ||||||
} catch { | ||||||
return false; | ||||||
} | ||||||
} ); | ||||||
|
||||||
// Insert a list block. | ||||||
await editor.canvas | ||||||
.getByRole( 'button', { name: 'Add default block' } ) | ||||||
.click(); | ||||||
await page.keyboard.type( '- List content' ); | ||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await pageUtils.pressKeys( 'alt+F10' ); | ||||||
|
||||||
const blockSwitcher = page | ||||||
.getByRole( 'toolbar', { name: 'Block tools' } ) | ||||||
.getByRole( 'button', { name: 'List' } ); | ||||||
|
||||||
// Verify the block switcher exists. | ||||||
await expect( blockSwitcher ).toHaveAttribute( | ||||||
'aria-haspopup', | ||||||
'true' | ||||||
); | ||||||
|
||||||
// Verify the correct block transforms appear. | ||||||
await blockSwitcher.click(); | ||||||
await expect( | ||||||
page.getByRole( 'menu', { name: 'List' } ).getByRole( 'menuitem' ) | ||||||
).toHaveText( [ 'Paragraph', 'Heading', 'Columns', 'Group' ] ); | ||||||
} ); | ||||||
|
||||||
test( 'Should not show the block switcher if all the blocks the list block transforms into are removed', async ( { | ||||||
editor, | ||||||
page, | ||||||
pageUtils, | ||||||
} ) => { | ||||||
// Insert a list block. | ||||||
await editor.canvas | ||||||
.getByRole( 'button', { name: 'Add default block' } ) | ||||||
.click(); | ||||||
await page.keyboard.type( '- List content' ); | ||||||
|
||||||
// Remove blocks. | ||||||
await page.waitForFunction( () => { | ||||||
try { | ||||||
window.wp.data | ||||||
.dispatch( 'core/blocks' ) | ||||||
.removeBlockTypes( [ | ||||||
'core/quote', | ||||||
'core/pullquote', | ||||||
'core/paragraph', | ||||||
'core/group', | ||||||
'core/heading', | ||||||
'core/columns', | ||||||
] ); | ||||||
return true; | ||||||
} catch { | ||||||
return false; | ||||||
} | ||||||
} ); | ||||||
|
||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await pageUtils.pressKeys( 'alt+F10' ); | ||||||
|
||||||
// Verify the block switcher isn't enabled. | ||||||
await expect( | ||||||
page | ||||||
.getByRole( 'toolbar', { name: 'Block tools' } ) | ||||||
.getByRole( 'button', { name: 'List' } ) | ||||||
).toBeDisabled(); | ||||||
} ); | ||||||
|
||||||
test( 'Should show Columns block only if selected blocks are between limits (1-6)', async ( { | ||||||
editor, | ||||||
page, | ||||||
} ) => { | ||||||
await editor.canvas | ||||||
.getByRole( 'button', { name: 'Add default block' } ) | ||||||
.click(); | ||||||
await page.keyboard.type( '- List content' ); | ||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( '## I am a header' ); | ||||||
await page.keyboard.down( 'Shift' ); | ||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await page.keyboard.up( 'Shift' ); | ||||||
|
||||||
await page | ||||||
.getByRole( 'toolbar', { name: 'Block tools' } ) | ||||||
.getByRole( 'button', { name: 'Multiple blocks selected' } ) | ||||||
.click(); | ||||||
|
||||||
await expect( | ||||||
page | ||||||
.getByRole( 'menu', { name: 'Multiple blocks selected' } ) | ||||||
.getByRole( 'menuitem', { name: 'Columns' } ) | ||||||
).toBeVisible(); | ||||||
} ); | ||||||
|
||||||
test( 'Should NOT show Columns transform only if selected blocks are more than max limit(6)', async ( { | ||||||
editor, | ||||||
page, | ||||||
pageUtils, | ||||||
} ) => { | ||||||
await editor.canvas | ||||||
.getByRole( 'button', { name: 'Add default block' } ) | ||||||
.click(); | ||||||
await page.keyboard.type( '- List content' ); | ||||||
await page.keyboard.press( 'ArrowUp' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( '## I am a header' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( 'First paragraph' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( 'Second paragraph' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( 'Third paragraph' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( 'Fourth paragraph' ); | ||||||
await page.keyboard.press( 'Enter' ); | ||||||
await page.keyboard.type( 'Fifth paragraph' ); | ||||||
await pageUtils.pressKeys( 'primary+a', { times: 2 } ); | ||||||
|
||||||
await page | ||||||
.getByRole( 'toolbar', { name: 'Block tools' } ) | ||||||
.getByRole( 'button', { name: 'Multiple blocks selected' } ) | ||||||
.click(); | ||||||
|
||||||
await expect( | ||||||
page | ||||||
.getByRole( 'menu', { name: 'Multiple blocks selected' } ) | ||||||
.getByRole( 'menuitem', { name: 'Columns' } ) | ||||||
).toBeHidden(); | ||||||
} ); | ||||||
|
||||||
test( 'should be able to transform to block variations', async ( { | ||||||
editor, | ||||||
page, | ||||||
} ) => { | ||||||
// This is the `stack` Group variation. | ||||||
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.
Suggested change
This looks like a typo. 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 don't think so; the variation name is |
||||||
await editor.insertBlock( { | ||||||
name: 'core/group', | ||||||
|
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.
Note for future me: If this fails again, ensure the block toolbar is displayed by adding
await pageUtils.pressKeys( 'alt+F10' );
.Currently, I can reproduce the scenario with Playwright, but I can do it manually sometimes.