-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 Block Switcher Test case to Playwright #50845
Conversation
Hi @pavanpatil1! This is still on my backlog but I'm currently busy with something else. I'll get back to this as soon as possible! Thanks for the PR! |
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.
Thank you! Sorry for the late review! This is close though! 💯
await pageUtils.pressKeys( 'alt+F10' ); | ||
|
||
// Verify the block switcher exists. | ||
expect( page.locator( 'role=button[name="List"i]' ) ).toBeTruthy(); |
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.
A locator is always truthy. Let's try toBeVisible()
instead? We can also scope it under the block toolbar.
expect( page.locator( 'role=button[name="List"i]' ) ).toBeTruthy(); | |
const blockToolbar = page.getByRole( 'toolbar', { name: 'Block tools' } ); | |
await expect( blockToolbar.getByRole( 'button', { name: 'List' } ) ) ).toBeVisible(); |
|
||
// Remove the quote block from the list of registered blocks. | ||
await page.evaluate( () => { | ||
wp.blocks.unregisterBlockType( 'core/quote' ); |
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.
We can do window.wp
here so we don't need the wp const above.
await pageUtils.pressKeys( 'alt+F10' ); | ||
|
||
// Verify the block switcher exists. | ||
expect( page.locator( 'role=button[name="List"i]' ) ).toBeTruthy(); |
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.
Ditto.
pageUtils, | ||
} ) => { | ||
const wp = ''; | ||
async function getAvailableBlockTransforms() { |
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.
Why not use the function from the utils below?
await pageUtils.pressKeys( 'alt+F10' ); | ||
|
||
// Remove the paragraph and quote block from the list of registered blocks. | ||
await page.evaluate( () => { |
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.
This is executed before the key press in the original test. I think we should follow the original behavior :).
// Verify the block switcher exists. | ||
expect( | ||
page.locator( | ||
'.block-editor-block-toolbar .block-editor-block-switcher' |
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.
Ditto.
await this.page.click( 'role=button[name="List"i]' ); | ||
return this.page.evaluate( ( buttonSelector ) => { | ||
return Array.from( | ||
document.querySelectorAll( buttonSelector ) | ||
).map( ( button ) => { | ||
return button.textContent; | ||
} ); | ||
}, '.block-editor-block-switcher__popover .block-editor-block-switcher__transforms__menugroup button' ); | ||
} |
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.
We can rewrite this into accessible selectors:
await this.getBlockSwitcher( blockName ).click();
return await this.page.getByRole( 'menu', { name: blockName } )
.getByRole( 'menuitem' )
.allTextContents();
I left out the implementation of getBlockSwitcher
here though. Feel free to ask questions if it's not clear!
Migrated via #57381. |
What?
Part of #38851.
Migrate block-switcher.test.js to its Playwright version.
Why?
Part of #38851.
How?
See MIGRATION.md for migration steps.
Testing Instructions
Run
npm run test:e2e:playwright test/e2e/specs/editor/various/block-switcher.spec.js