-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mobile] - Add E2E tests for the Drag & Drop blocks feature (#41368)
* Mobile - Add E2E tests for the Drag & Drop blocks feature * Update longPress action * Use clickIfClickable * Use longPress instead of press * Fix clipboard typo * Add setClipboard and clearClipboard helpers
- Loading branch information
Gerardo Pacheco
authored
May 31, 2022
1 parent
29a170b
commit c032635
Showing
5 changed files
with
286 additions
and
24 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
packages/react-native-editor/__device-tests__/gutenberg-editor-drag-and-drop.test.js
This file contains 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,153 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { blockNames } from './pages/editor-page'; | ||
import { | ||
clearClipboard, | ||
clickElementOutsideOfTextInput, | ||
dragAndDropAfterElement, | ||
isAndroid, | ||
setClipboard, | ||
tapPasteAboveElement, | ||
} from './helpers/utils'; | ||
import testData from './helpers/test-data'; | ||
|
||
describe( 'Gutenberg Editor Drag & Drop blocks tests', () => { | ||
beforeEach( async () => { | ||
await clearClipboard( editorPage.driver ); | ||
} ); | ||
|
||
it( 'should be able to drag & drop a block', async () => { | ||
// Initialize the editor with a Spacer and Paragraph block | ||
await editorPage.setHtmlContent( | ||
[ testData.spacerBlock, testData.paragraphBlockShortText ].join( | ||
'\n\n' | ||
) | ||
); | ||
|
||
// Get elements for both blocks | ||
const spacerBlock = await editorPage.getBlockAtPosition( | ||
blockNames.spacer | ||
); | ||
const paragraphBlock = await editorPage.getParagraphBlockWrapperAtPosition( | ||
2 | ||
); | ||
|
||
// Drag & drop the Spacer block after the Paragraph block | ||
await dragAndDropAfterElement( | ||
editorPage.driver, | ||
spacerBlock, | ||
paragraphBlock | ||
); | ||
|
||
// Get the first block, in this case the Paragraph block | ||
// and check the text value is the expected one | ||
const firstBlockText = await editorPage.getTextForParagraphBlockAtPosition( | ||
1 | ||
); | ||
expect( firstBlockText ).toMatch( testData.shortText ); | ||
|
||
// Remove the blocks | ||
await spacerBlock.click(); | ||
await editorPage.removeBlockAtPosition( blockNames.spacer, 2 ); | ||
await editorPage.removeBlockAtPosition( blockNames.paragraph, 1 ); | ||
} ); | ||
|
||
it( 'should be able to long-press on a text-based block to paste a text in a focused textinput', async () => { | ||
// Add a Paragraph block | ||
await editorPage.addNewBlock( blockNames.paragraph ); | ||
const paragraphBlockElement = await editorPage.getTextBlockAtPosition( | ||
blockNames.paragraph | ||
); | ||
|
||
// Set clipboard text | ||
await setClipboard( editorPage.driver, testData.shortText ); | ||
|
||
// Dismiss auto-suggestion popup | ||
if ( isAndroid() ) { | ||
// On Andrdoid 10 a new auto-suggestion popup is appearing to let the user paste text recently put in the clipboard. Let's dismiss it. | ||
await editorPage.dismissAndroidClipboardSmartSuggestion(); | ||
} | ||
|
||
// Paste into the Paragraph block | ||
await tapPasteAboveElement( editorPage.driver, paragraphBlockElement ); | ||
const paragraphText = await editorPage.getTextForParagraphBlockAtPosition( | ||
1 | ||
); | ||
|
||
// Expect to have the pasted text in the Paragraph block | ||
expect( paragraphText ).toMatch( testData.shortText ); | ||
|
||
// Remove the block | ||
await editorPage.removeBlockAtPosition( blockNames.paragraph ); | ||
} ); | ||
|
||
it( 'should be able to long-press on a text-based block using the PlainText component to paste a text in a focused textinput', async () => { | ||
// Add a Shortcode block | ||
await editorPage.addNewBlock( blockNames.shortcode ); | ||
const shortcodeBlockElement = await editorPage.getShortBlockTextInputAtPosition( | ||
blockNames.shortcode | ||
); | ||
|
||
// Set clipboard text | ||
await setClipboard( editorPage.driver, testData.shortText ); | ||
|
||
// Dismiss auto-suggestion popup | ||
if ( isAndroid() ) { | ||
// On Andrdoid 10 a new auto-suggestion popup is appearing to let the user paste text recently put in the clipboard. Let's dismiss it. | ||
await editorPage.dismissAndroidClipboardSmartSuggestion(); | ||
} | ||
|
||
// Paste into the Shortcode block | ||
await tapPasteAboveElement( editorPage.driver, shortcodeBlockElement ); | ||
const shortcodeText = await shortcodeBlockElement.text(); | ||
|
||
// Expect to have the pasted text in the Shortcode block | ||
expect( shortcodeText ).toMatch( testData.shortText ); | ||
|
||
// Remove the block | ||
await editorPage.removeBlockAtPosition( blockNames.shortcode ); | ||
} ); | ||
|
||
it( 'should be able to drag & drop a text-based block when the textinput is not focused', async () => { | ||
// Initialize the editor with two Paragraph blocks | ||
await editorPage.setHtmlContent( | ||
[ | ||
testData.paragraphBlockShortText, | ||
testData.paragraphBlockEmpty, | ||
].join( '\n\n' ) | ||
); | ||
|
||
// Get elements for both blocks | ||
const firstParagraphBlock = await editorPage.getParagraphBlockWrapperAtPosition( | ||
1 | ||
); | ||
const secondParagraphBlock = await editorPage.getParagraphBlockWrapperAtPosition( | ||
2 | ||
); | ||
|
||
// Tap on the first Paragraph block outside of the textinput | ||
await clickElementOutsideOfTextInput( | ||
editorPage.driver, | ||
firstParagraphBlock | ||
); | ||
|
||
// Drag & drop the first Paragraph block after the second Paragraph block | ||
await dragAndDropAfterElement( | ||
editorPage.driver, | ||
firstParagraphBlock, | ||
secondParagraphBlock | ||
); | ||
|
||
// Get the current second Paragraph block in the editor after dragging & dropping | ||
const secondBlockText = await editorPage.getTextForParagraphBlockAtPosition( | ||
2 | ||
); | ||
|
||
// Expect the second Paragraph block to have the expected content | ||
expect( secondBlockText ).toMatch( testData.shortText ); | ||
|
||
// Remove the block | ||
await editorPage.removeBlockAtPosition( blockNames.paragraph ); | ||
} ); | ||
} ); |
This file contains 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 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 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
Oops, something went wrong.