-
Notifications
You must be signed in to change notification settings - Fork 4k
/
gutenberg-editor-block-insertion.test.js
125 lines (109 loc) · 3.59 KB
/
gutenberg-editor-block-insertion.test.js
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
/**
* Internal dependencies
*/
import { blockNames } from './pages/editor-page';
import { isAndroid, swipeDown, clickMiddleOfElement } from './helpers/utils';
import testData from './helpers/test-data';
describe( 'Gutenberg Editor tests for Block insertion', () => {
it( 'should be able to insert block into post', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
let paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
await paragraphBlockElement.click();
}
await editorPage.sendTextToParagraphBlock( 1, testData.longText );
// Should have 3 paragraph blocks at this point
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph,
2
);
await paragraphBlockElement.click();
await editorPage.addNewBlock( blockNames.paragraph );
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph,
3
);
await paragraphBlockElement.click();
await editorPage.sendTextToParagraphBlock( 3, testData.mediumText );
const html = await editorPage.getHtmlContent();
expect( testData.blockInsertionHtml.toLowerCase() ).toBe(
html.toLowerCase()
);
// wait for the block editor to load and for accessibility ids to update
await editorPage.driver.sleep( 3000 );
// Workaround for now since deleting the first element causes a crash on CI for Android
if ( isAndroid() ) {
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph,
3,
{
autoscroll: true,
}
);
await paragraphBlockElement.click();
await editorPage.removeBlockAtPosition( blockNames.paragraph, 3 );
for ( let i = 3; i > 0; i-- ) {
// wait for accessibility ids to update
await editorPage.driver.sleep( 1000 );
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph,
i,
{
autoscroll: true,
}
);
await paragraphBlockElement.click();
await editorPage.removeBlockAtPosition(
blockNames.paragraph,
i
);
}
} else {
for ( let i = 4; i > 0; i-- ) {
// wait for accessibility ids to update
await editorPage.driver.sleep( 1000 );
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph
);
await clickMiddleOfElement(
editorPage.driver,
paragraphBlockElement
);
await editorPage.removeBlockAtPosition( blockNames.paragraph );
}
}
} );
it( 'should be able to insert block at the beginning of post from the title', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
let paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
await paragraphBlockElement.click();
}
await editorPage.sendTextToParagraphBlock( 1, testData.longText );
// Should have 3 paragraph blocks at this point
if ( isAndroid() ) {
await editorPage.dismissKeyboard();
}
await swipeDown( editorPage.driver );
const titleElement = await editorPage.getTitleElement( {
autoscroll: true,
} );
await titleElement.click();
await titleElement.click();
await editorPage.addNewBlock( blockNames.paragraph );
paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph
);
await clickMiddleOfElement( editorPage.driver, paragraphBlockElement );
await editorPage.sendTextToParagraphBlock( 1, testData.mediumText );
await paragraphBlockElement.click();
const html = await editorPage.getHtmlContent();
expect( testData.blockInsertionHtmlFromTitle.toLowerCase() ).toBe(
html.toLowerCase()
);
} );
} );