-
Notifications
You must be signed in to change notification settings - Fork 58
/
gutenberg-editor-functionality-test-1-visual.test.js
379 lines (329 loc) · 12.3 KB
/
gutenberg-editor-functionality-test-1-visual.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/**
* Internal dependencies
*/
const { blockNames } = editorPage;
import { takeScreenshot, takeScreenshotByElement } from './utils';
const {
clickIfClickable,
toggleOrientation,
isAndroid,
swipeFromTo,
toggleDarkMode,
typeString,
waitForVisible,
} = e2eUtils;
import { NESTED_COLUMNS_3_LEVELS } from './test-editor-data';
const ANDROID_COLUMN_APPENDER_BUTTON_XPATH =
'//android.widget.Button[@content-desc="Column Block. Row 1"]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.Button';
describe( 'Gutenberg Editor - Test Suite 1', () => {
describe( 'Columns block', () => {
it( 'displays placeholders when unselected', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.columns );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Select title to unfocus the block
const titleElement = await editorPage.getTitleElement();
await titleElement.click();
await editorPage.dismissKeyboard();
// Visual test check for portrait orientation
let screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
// Visual test check for landscape orientation
screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
} );
it( 'displays correctly in portrait and landscape orientations', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.columns );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Click the block appender within the first column
if ( isAndroid() ) {
await editorPage.driver.$( '~Column Block. Row 1' ).click();
const appenderButton =
await editorPage.waitForElementToBeDisplayedByXPath(
ANDROID_COLUMN_APPENDER_BUTTON_XPATH
);
await appenderButton.click();
} else {
const firstColum = await editorPage.driver.$(
'~Column Block. Row 1'
);
await firstColum.click();
await firstColum.click();
}
await editorPage.addNewBlock( blockNames.columns, {
skipInserterOpen: true,
} );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Navigate upwards in block hierarchy
await editorPage.moveBlockSelectionUp( { toRoot: true } );
await editorPage.driver.pause( 1000 );
// Visual test check for portrait orientation
let screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
// Visual test check for landscape orientation
screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
} );
it( 'mover buttons display in the correct positions', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.columns );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Click the block appender within the first column
if ( isAndroid() ) {
await editorPage.driver.$( '~Column Block. Row 1' ).click();
const appenderButton =
await editorPage.waitForElementToBeDisplayedByXPath(
ANDROID_COLUMN_APPENDER_BUTTON_XPATH
);
await appenderButton.click();
} else {
const firstColum = await editorPage.driver.$(
'~Column Block. Row 1'
);
await firstColum.click();
await firstColum.click();
}
await editorPage.addNewBlock( blockNames.columns, {
skipInserterOpen: true,
} );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
// Visual test check for landscape orientation
let screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
// Navigate upwards in block hierarchy
await editorPage.moveBlockSelectionUp();
await editorPage.driver.pause( 1000 );
// Visual test check for landscape orientation
screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleOrientation( editorPage.driver );
// Wait for the device to finish rotating
await editorPage.driver.pause( 3000 );
} );
it( 'displays with correct colors with dark mode enabled', async () => {
await toggleDarkMode( editorPage.driver, true );
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.columns );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
// Dismiss columns layout picker
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Visual test check for placeholders
let screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
// Click the block appender within the first column
if ( isAndroid() ) {
await editorPage.driver.$( '~Column Block. Row 1' ).click();
const appenderButton =
await editorPage.waitForElementToBeDisplayedByXPath(
ANDROID_COLUMN_APPENDER_BUTTON_XPATH
);
await appenderButton.click();
} else {
const firstColum = await editorPage.driver.$(
'~Column Block. Row 1'
);
await firstColum.click();
await firstColum.click();
}
// Append a Preformatted block
const blockButton = await editorPage.findBlockButton(
blockNames.preformatted
);
await blockButton.click();
// TODO: determine a way to type a text block nested within a Columns block
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
// Navigate upwards in block hierarchy
await editorPage.moveBlockSelectionUp( { toRoot: true } );
await editorPage.waitForKeyboardToBeHidden();
// Android fails to display the keyboard at times, which can cause the
// above `waitForKeyboardToBeHidden` to finish prematurely.
await editorPage.driver.pause( 1000 );
// Visual test check for nested content
screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
await toggleDarkMode( editorPage.driver, false );
} );
it( 'sliders display proportionate fill level previews', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.columns );
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
await editorPage.dismissBottomSheet();
await editorPage.openBlockSettings();
// Wait for the modal to open
await editorPage.driver.pause( 3000 );
const cellId = '~Column 1. Width is 50 Percent (%).';
const cell = await editorPage.driver.$( cellId );
const cellSize = await cell.getSize();
const cellLocation = await cell.getLocation();
const scrollOffset = isAndroid() ? 350 : 100;
const windowSize = await editorPage.driver.getWindowSize();
// Reveal default column width cells
await swipeFromTo(
editorPage.driver,
{
x: cellLocation.x + cellSize.width / 2,
y: cellLocation.y + cellSize.height / 2,
},
{
x: cellLocation.x + cellSize.width / 2,
y: windowSize.height / 2,
},
1000
);
// Shrink the first column
await swipeFromTo(
editorPage.driver,
{
x: cellLocation.x + cellSize.width * 0.42,
y: cellLocation.y - scrollOffset + cellSize.height * 0.69,
},
{
x:
cellLocation.x +
cellSize.width * 0.42 -
cellSize.width * 0.15,
y: cellLocation.y - scrollOffset + cellSize.height * 0.69,
},
1000
);
// Wait for the scrollbars to hide
await editorPage.driver.pause( 3000 );
// Visual test check for adjusted columns
const screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
} );
it( 'allows deep nesting to at least 3 levels', async () => {
await editorPage.initializeEditor( {
initialData: NESTED_COLUMNS_3_LEVELS,
} );
// Wait for the block to be rendered
await editorPage.driver.pause( 3000 );
// Visual test check
const screenshot = await takeScreenshot();
expect( screenshot ).toMatchImageSnapshot();
} );
} );
describe( 'Social Icons block', () => {
it( 'should display active icon colors', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.socialIcons );
const twitterIconXpath = isAndroid()
? '//android.widget.Button[@content-desc="Twitter social icon"]'
: '//XCUIElementTypeButton[@name="Twitter social icon"]';
await clickIfClickable( editorPage.driver, twitterIconXpath );
await editorPage.toggleFormatting( 'Add link to Twitter' );
const uRLFieldXpath = isAndroid()
? '//android.widget.Button[@content-desc="URL. Empty"]/android.view.ViewGroup[1]/android.widget.EditText'
: '//XCUIElementTypeOther[@name="Add URL"]/XCUIElementTypeTextField';
const uRLField = await waitForVisible(
editorPage.driver,
uRLFieldXpath
);
await typeString(
editorPage.driver,
uRLField,
'https://twitter.com/WordPress'
);
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
const socialLinksBlockXpath = isAndroid()
? '//android.widget.Button[@content-desc="Social Icons Block. Row 1"]'
: '(//XCUIElementTypeOther[@name="Social Icons Block. Row 1"])[1]';
const socialLinksBlock = await editorPage.driver.$(
socialLinksBlockXpath
);
const screenshot = await takeScreenshotByElement(
socialLinksBlock,
{ padding: 7 }
);
expect( screenshot ).toMatchImageSnapshot();
} );
it( 'should display the block outline of a block inserted from the appender', async () => {
await editorPage.initializeEditor();
await editorPage.addNewBlock( blockNames.socialIcons );
const appenderButton = isAndroid()
? await editorPage.waitForElementToBeDisplayedByXPath(
`//android.widget.Button[@resource-id="appender-button"]`
)
: await editorPage.waitForElementToBeDisplayedById(
'appender-button'
);
await appenderButton.click();
const amazonBlockXPath = isAndroid()
? '//android.widget.Button[@content-desc="Amazon block"]'
: '//XCUIElementTypeButton[@name="Amazon block"]';
await clickIfClickable( editorPage.driver, amazonBlockXPath );
const uRLFieldXpath = isAndroid()
? '//android.widget.Button[@content-desc="URL. Empty"]/android.view.ViewGroup[1]/android.widget.EditText'
: '//XCUIElementTypeOther[@name="Add URL"]/XCUIElementTypeTextField';
const uRLField = await waitForVisible(
editorPage.driver,
uRLFieldXpath
);
await typeString(
editorPage.driver,
uRLField,
'https://amazon.com'
);
await editorPage.dismissBottomSheet();
// Wait for the modal to close
await editorPage.driver.pause( 3000 );
const socialLinksBlockXpath = isAndroid()
? '//android.widget.Button[@content-desc="Social Icons Block. Row 1"]'
: '(//XCUIElementTypeOther[@name="Social Icons Block. Row 1"])[1]';
const socialLinksBlock = await editorPage.driver.$(
socialLinksBlockXpath
);
const screenshot = await takeScreenshotByElement(
socialLinksBlock,
{ padding: 7 }
);
expect( screenshot ).toMatchImageSnapshot();
} );
} );
} );