-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathgutenberg-editor-drag-and-drop.test.js
More file actions
165 lines (140 loc) · 4.92 KB
/
gutenberg-editor-drag-and-drop.test.js
File metadata and controls
165 lines (140 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* 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 );
} );
// skip iOS for now
if ( isAndroid() ) {
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 );
} );
}
// skip iOS for now
if ( isAndroid() ) {
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 );
} );
} );