-
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 Mover Test For Playwright #42039
Changes from 3 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'block mover', () => { | ||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'should show block mover when more than one block exists', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
// Create a two blocks on the page. | ||
await page.click( '.block-editor-default-block-appender' ); | ||
await page.keyboard.type( 'First Paragraph' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( 'Second Paragraph' ); | ||
|
||
// Select a block so the block mover is rendered. | ||
await page.focus( 'text=First Paragraph' ); | ||
await editor.showBlockToolbar(); | ||
const count = await page.$$eval( | ||
'.block-editor-block-mover', | ||
( el ) => el.length | ||
); | ||
expect( count ).toBe( 1 ); | ||
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'd be good to take advantage of Playwright's locator system here, and use the role selector: const moveDownButton = page.locator( 'role=toolbar[name="Block tools"i] >> role=button[name="Move down"i]' );
const moveUpButton = page.locator( 'role=toolbar[name="Block tools"i] >> role=button[name="Move up"i]' );
await expect( moveDownButton ).toBeVisible();
await expect( moveUpButton ).toBeVisible(); 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. Worked on the feedbacks |
||
} ); | ||
|
||
test( 'should hide block mover when only one block exists', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
// Create a single block on the page. | ||
await page.click( '.block-editor-default-block-appender' ); | ||
await page.keyboard.type( 'First Paragraph' ); | ||
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. Similar to the previous comment, this can change to: await editor.insertBlock( { name: 'core/paragraph', attributes: { content: 'First Paragraph' } ); 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. Worked on the feedbacks |
||
|
||
// Select a block so the block mover has the possibility of being rendered. | ||
await page.focus( 'text=First Paragraph' ); | ||
await editor.showBlockToolbar(); | ||
|
||
// Ensure no block mover exists when only one block exists on the page. | ||
const count = await page.$$eval( | ||
'.block-editor-block-mover', | ||
( el ) => el.length | ||
); | ||
expect( count ).toBe( 0 ); | ||
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. And this part could also be refactored to be use locators: const moveDownButton = page.locator( 'role=toolbar[name="Block tools"i] >> role=button[name="Move down"i]' );
const moveUpButton = page.locator( 'role=toolbar[name="Block tools"i] >> role=button[name="Move up"i]' );
await expect( moveDownButton ).toBeHidden();
await expect( moveUpButton ).toBeHidden(); 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. Worked on the feedbacks. |
||
} ); | ||
} ); |
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 think it would be good to simplify this part with something like:
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.
Worked on the feedbacks