-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Migrate draggable block tests to Playwright #43798
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
406cbb7
WIP
Mamaduka 9428ff5
Get the first draggable test to work in Playwright
kevin940726 205916c
Try adding remaining test
Mamaduka 52e1b7d
Move mouse in addition to hovering
talldan e6dc8e2
Set the viewport size
talldan ca97f56
Fix the tests
kevin940726 de436b9
Make sure to focus on the correct paragraph block
kevin940726 8475658
Set viewport in test.use
kevin940726 4895b8a
Try steps
kevin940726 2d99682
Remove puppeteer test
talldan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
packages/e2e-tests/specs/editor/various/__snapshots__/draggable-block.test.js.snap
This file was deleted.
Oops, something went wrong.
128 changes: 0 additions & 128 deletions
128
packages/e2e-tests/specs/editor/various/draggable-block.test.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
|
||
| test.use( { | ||
| // Make the viewport large enough so that a scrollbar isn't displayed. | ||
| // Otherwise, the page scrolling can interfere with the test runner's | ||
| // ability to drop a block in the right location. | ||
| viewport: { | ||
| width: 960, | ||
| height: 1024, | ||
| }, | ||
| } ); | ||
|
|
||
| test.describe( 'Draggable block', () => { | ||
| test.beforeEach( async ( { admin } ) => { | ||
| await admin.createNewPost(); | ||
| } ); | ||
|
|
||
| test( 'can drag and drop to the top of a block list', async ( { | ||
| editor, | ||
| page, | ||
| } ) => { | ||
| await page.keyboard.press( 'Enter' ); | ||
| await page.keyboard.type( '1' ); | ||
| await page.keyboard.press( 'Enter' ); | ||
| await page.keyboard.type( '2' ); | ||
|
|
||
| // Confirm correct setup. | ||
| await expect.poll( editor.getEditedPostContent ) | ||
| .toBe( `<!-- wp:paragraph --> | ||
| <p>1</p> | ||
| <!-- /wp:paragraph --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p>2</p> | ||
| <!-- /wp:paragraph -->` ); | ||
|
|
||
| await page.focus( 'role=document[name="Paragraph block"i] >> text=2' ); | ||
| await editor.showBlockToolbar(); | ||
|
|
||
| const dragHandle = page.locator( | ||
| 'role=toolbar[name="Block tools"i] >> role=button[name="Drag"i][include-hidden]' | ||
|
kevin940726 marked this conversation as resolved.
|
||
| ); | ||
| // Hover to the center of the drag handle. | ||
| await dragHandle.hover(); | ||
| // Start dragging. | ||
| await page.mouse.down(); | ||
|
|
||
| // Move to and hover on the upper half of the paragraph block to trigger the indicator. | ||
| const firstParagraph = page.locator( | ||
| 'role=document[name="Paragraph block"i] >> text=1' | ||
| ); | ||
| const firstParagraphBound = await firstParagraph.boundingBox(); | ||
| await page.mouse.move( firstParagraphBound.x, firstParagraphBound.y, { | ||
| steps: 10, | ||
| } ); | ||
|
|
||
| await expect( | ||
| page.locator( 'data-testid=block-draggable-chip >> visible=true' ) | ||
| ).toBeVisible(); | ||
|
|
||
| const indicator = page.locator( | ||
| 'data-testid=block-list-insertion-point-indicator' | ||
| ); | ||
| await expect( indicator ).toBeVisible(); | ||
| // Expect the indicator to be above the first paragraph. | ||
| await expect | ||
| .poll( () => indicator.boundingBox().then( ( { y } ) => y ) ) | ||
| .toBeLessThan( firstParagraphBound.y ); | ||
|
|
||
| // Drop the paragraph block. | ||
| await page.mouse.up(); | ||
|
|
||
| await expect.poll( editor.getEditedPostContent ) | ||
| .toBe( `<!-- wp:paragraph --> | ||
| <p>2</p> | ||
| <!-- /wp:paragraph --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p>1</p> | ||
| <!-- /wp:paragraph -->` ); | ||
| } ); | ||
|
|
||
| test( 'can drag and drop to the bottom of a block list', async ( { | ||
| editor, | ||
| page, | ||
| } ) => { | ||
| await page.keyboard.press( 'Enter' ); | ||
| await page.keyboard.type( '1' ); | ||
| await page.keyboard.press( 'Enter' ); | ||
| await page.keyboard.type( '2' ); | ||
|
|
||
| // Confirm correct setup. | ||
| await expect.poll( editor.getEditedPostContent ) | ||
| .toBe( `<!-- wp:paragraph --> | ||
| <p>1</p> | ||
| <!-- /wp:paragraph --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p>2</p> | ||
| <!-- /wp:paragraph -->` ); | ||
|
|
||
| await page.focus( 'role=document[name="Paragraph block"i] >> text=1' ); | ||
| await editor.showBlockToolbar(); | ||
|
|
||
| const dragHandle = page.locator( | ||
| 'role=toolbar[name="Block tools"i] >> role=button[name="Drag"i][include-hidden]' | ||
| ); | ||
| // Hover to the center of the drag handle. | ||
| await dragHandle.hover(); | ||
| // Start dragging. | ||
| await page.mouse.down(); | ||
|
|
||
| // Move to and hover on the bottom half of the paragraph block to trigger the indicator. | ||
| const secondParagraph = page.locator( | ||
| 'role=document[name="Paragraph block"i] >> text=2' | ||
| ); | ||
| const secondParagraphBound = await secondParagraph.boundingBox(); | ||
| await page.mouse.move( | ||
| secondParagraphBound.x, | ||
| secondParagraphBound.y + secondParagraphBound.height * 0.75, | ||
| { steps: 10 } | ||
| ); | ||
|
|
||
| await expect( | ||
| page.locator( 'data-testid=block-draggable-chip >> visible=true' ) | ||
| ).toBeVisible(); | ||
|
|
||
| const indicator = page.locator( | ||
| 'data-testid=block-list-insertion-point-indicator' | ||
| ); | ||
| await expect( indicator ).toBeVisible(); | ||
| // Expect the indicator to be below the second paragraph. | ||
| await expect | ||
| .poll( () => | ||
| indicator.boundingBox().then( ( { y, height } ) => y + height ) | ||
| ) | ||
| .toBeGreaterThan( | ||
| secondParagraphBound.y + secondParagraphBound.height | ||
| ); | ||
|
|
||
| // Drop the paragraph block. | ||
| await page.mouse.up(); | ||
|
|
||
| await expect.poll( editor.getEditedPostContent ) | ||
| .toBe( `<!-- wp:paragraph --> | ||
| <p>2</p> | ||
| <!-- /wp:paragraph --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p>1</p> | ||
| <!-- /wp:paragraph -->` ); | ||
| } ); | ||
| } ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.