@wordpress/e2e-tests 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/jest.config.js +4 -0
- package/package.json +7 -7
- package/specs/editor/blocks/pullquote.test.js +3 -3
- package/specs/editor/plugins/__snapshots__/align-hook.test.js.snap +11 -11
- package/specs/editor/plugins/__snapshots__/container-blocks.test.js.snap +14 -14
- package/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +29 -29
- package/specs/editor/plugins/__snapshots__/iframed-inline-styles.test.js.snap +1 -1
- package/specs/editor/plugins/__snapshots__/iframed-masonry-block.test.js.snap +1 -1
- package/specs/editor/plugins/__snapshots__/inner-blocks-render-appender.test.js.snap +5 -5
- package/specs/editor/plugins/__snapshots__/plugins-api.test.js.snap +2 -2
- package/specs/editor/various/__snapshots__/adding-patterns.test.js.snap +4 -4
- package/specs/editor/various/__snapshots__/block-grouping.test.js.snap +21 -21
- package/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap +12 -12
- package/specs/editor/various/__snapshots__/embedding.test.js.snap +19 -19
- package/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap +8 -8
- package/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap +11 -11
- package/specs/editor/various/__snapshots__/links.test.js.snap +9 -9
- package/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap +17 -17
- package/specs/editor/various/__snapshots__/rich-text.test.js.snap +5 -5
- package/specs/editor/various/block-grouping.test.js +3 -3
- package/specs/editor/various/format-library/__snapshots__/text-color.test.js.snap +1 -1
- package/specs/editor/various/links.test.js +7 -7
- package/specs/editor/various/multi-block-selection.test.js +2 -2
- package/specs/performance/front-end-block-theme.test.js +13 -24
- package/specs/performance/front-end-classic-theme.test.js +13 -24
- package/specs/performance/post-editor.test.js +14 -12
- package/specs/performance/site-editor.test.js +1 -2
- package/specs/performance/utils.js +12 -1
- package/specs/site-editor/multi-entity-saving.test.js +0 -2
- package/specs/site-editor/settings-sidebar.test.js +0 -1
- package/specs/widgets/editing-widgets.test.js +20 -15
- package/specs/editor/blocks/__snapshots__/navigation.test.js.snap +0 -47
- package/specs/editor/blocks/navigation.test.js +0 -1723
- package/specs/editor/various/__snapshots__/block-deletion.test.js.snap +0 -111
- package/specs/editor/various/__snapshots__/list-view.test.js.snap +0 -15
- package/specs/editor/various/block-deletion.test.js +0 -209
- package/specs/editor/various/list-view.test.js +0 -414
- package/specs/editor/various/switch-to-draft.test.js +0 -254
@@ -1,414 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
createNewPost,
|
6
|
-
insertBlock,
|
7
|
-
getEditedPostContent,
|
8
|
-
isListViewOpen,
|
9
|
-
openListView,
|
10
|
-
pressKeyWithModifier,
|
11
|
-
pressKeyTimes,
|
12
|
-
} from '@wordpress/e2e-test-utils';
|
13
|
-
|
14
|
-
async function dragAndDrop( draggableElement, targetElement, offsetY ) {
|
15
|
-
const draggablePoint = await draggableElement.clickablePoint();
|
16
|
-
const targetClickablePoint = await targetElement.clickablePoint();
|
17
|
-
const targetPoint = {
|
18
|
-
x: targetClickablePoint.x,
|
19
|
-
y: targetClickablePoint.y + offsetY,
|
20
|
-
};
|
21
|
-
|
22
|
-
return await page.mouse.dragAndDrop( draggablePoint, targetPoint );
|
23
|
-
}
|
24
|
-
|
25
|
-
async function getBlockListLeafNodes() {
|
26
|
-
return await page.$$( '.block-editor-list-view-leaf' );
|
27
|
-
}
|
28
|
-
|
29
|
-
describe( 'List view', () => {
|
30
|
-
beforeAll( async () => {
|
31
|
-
await page.setDragInterception( true );
|
32
|
-
} );
|
33
|
-
|
34
|
-
beforeEach( async () => {
|
35
|
-
await createNewPost();
|
36
|
-
} );
|
37
|
-
|
38
|
-
afterAll( async () => {
|
39
|
-
await page.setDragInterception( false );
|
40
|
-
} );
|
41
|
-
|
42
|
-
it( 'allows a user to drag a block to a new sibling position', async () => {
|
43
|
-
// Insert some blocks of different types.
|
44
|
-
await insertBlock( 'Heading' );
|
45
|
-
await insertBlock( 'Image' );
|
46
|
-
await insertBlock( 'Paragraph' );
|
47
|
-
|
48
|
-
// Open list view.
|
49
|
-
await pressKeyWithModifier( 'access', 'o' );
|
50
|
-
|
51
|
-
const paragraphBlock = await page.waitForXPath(
|
52
|
-
'//a[contains(., "Paragraph")][@draggable="true"]'
|
53
|
-
);
|
54
|
-
|
55
|
-
// Drag above the heading block.
|
56
|
-
const headingBlock = await page.waitForXPath(
|
57
|
-
'//a[contains(., "Heading")][@draggable="true"]'
|
58
|
-
);
|
59
|
-
|
60
|
-
await dragAndDrop( paragraphBlock, headingBlock, -5 );
|
61
|
-
|
62
|
-
expect( await getEditedPostContent() ).toMatchSnapshot();
|
63
|
-
} );
|
64
|
-
|
65
|
-
// Check for regressions of https://github.com/WordPress/gutenberg/issues/38763.
|
66
|
-
it( 'shows the correct amount of blocks after a block is removed in the canvas', async () => {
|
67
|
-
// Insert some blocks of different types.
|
68
|
-
await insertBlock( 'Image' );
|
69
|
-
await insertBlock( 'Heading' );
|
70
|
-
await insertBlock( 'Paragraph' );
|
71
|
-
|
72
|
-
// Open list view.
|
73
|
-
await pressKeyWithModifier( 'access', 'o' );
|
74
|
-
|
75
|
-
// The last inserted paragraph block should be selected in List View.
|
76
|
-
await page.waitForSelector(
|
77
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Paragraph"]'
|
78
|
-
);
|
79
|
-
|
80
|
-
// Go to the image block in list view.
|
81
|
-
await pressKeyTimes( 'ArrowUp', 2 );
|
82
|
-
const listViewImageBlock = await page.waitForXPath(
|
83
|
-
'//a[contains(., "Image")]'
|
84
|
-
);
|
85
|
-
await expect( listViewImageBlock ).toHaveFocus();
|
86
|
-
|
87
|
-
// Select the image block in the canvas.
|
88
|
-
await page.keyboard.press( 'Enter' );
|
89
|
-
|
90
|
-
const uploadButton = await page.waitForXPath(
|
91
|
-
'//button[contains( text(), "Upload" ) ]'
|
92
|
-
);
|
93
|
-
await expect( uploadButton ).toHaveFocus();
|
94
|
-
|
95
|
-
// Delete the image block in the canvas.
|
96
|
-
await page.keyboard.press( 'ArrowUp' );
|
97
|
-
await page.keyboard.press( 'Backspace' );
|
98
|
-
|
99
|
-
// List view should have two rows.
|
100
|
-
const listViewRows = await page.$$( 'tr.block-editor-list-view-leaf' );
|
101
|
-
expect( listViewRows ).toHaveLength( 2 );
|
102
|
-
|
103
|
-
// The console didn't throw an error as reported in
|
104
|
-
// https://github.com/WordPress/gutenberg/issues/38763.
|
105
|
-
expect( console ).not.toHaveErrored();
|
106
|
-
} );
|
107
|
-
|
108
|
-
// Check for regression of https://github.com/WordPress/gutenberg/issues/39026
|
109
|
-
it( 'should select previous block after removing selected one', async () => {
|
110
|
-
// Insert some blocks of different types.
|
111
|
-
await insertBlock( 'Image' );
|
112
|
-
await insertBlock( 'Heading' );
|
113
|
-
await insertBlock( 'Paragraph' );
|
114
|
-
|
115
|
-
// Open list view.
|
116
|
-
await openListView();
|
117
|
-
|
118
|
-
// The last inserted paragraph block should be selected in List View.
|
119
|
-
await page.waitForSelector(
|
120
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Paragraph"]'
|
121
|
-
);
|
122
|
-
|
123
|
-
// Paragraph options button.
|
124
|
-
const paragraphOptionsButton = await page.waitForSelector(
|
125
|
-
'tr.block-editor-list-view-leaf:last-child button[aria-label="Options for Paragraph block"]'
|
126
|
-
);
|
127
|
-
|
128
|
-
await paragraphOptionsButton.click();
|
129
|
-
|
130
|
-
const paragraphRemoveButton = await page.waitForXPath(
|
131
|
-
'//button[contains(., "Remove Paragraph")]'
|
132
|
-
);
|
133
|
-
|
134
|
-
// Remove paragraph.
|
135
|
-
await paragraphRemoveButton.click();
|
136
|
-
|
137
|
-
// Heading block should be selected as previous block.
|
138
|
-
await page.waitForSelector(
|
139
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Heading"]'
|
140
|
-
);
|
141
|
-
} );
|
142
|
-
|
143
|
-
// Check for regression of https://github.com/WordPress/gutenberg/issues/39026
|
144
|
-
it( 'should select next block after removing the very first block', async () => {
|
145
|
-
// Insert some blocks of different types.
|
146
|
-
await insertBlock( 'Image' );
|
147
|
-
await insertBlock( 'Heading' );
|
148
|
-
await insertBlock( 'Paragraph' );
|
149
|
-
|
150
|
-
// Open list view.
|
151
|
-
await openListView();
|
152
|
-
|
153
|
-
// The last inserted paragraph block should be selected in List View.
|
154
|
-
await page.waitForSelector(
|
155
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Paragraph"]'
|
156
|
-
);
|
157
|
-
|
158
|
-
// Go to the image block in list view.
|
159
|
-
await pressKeyTimes( 'ArrowUp', 2 );
|
160
|
-
await pressKeyTimes( 'Enter', 1 );
|
161
|
-
|
162
|
-
// Image block should have selected.
|
163
|
-
await page.waitForSelector(
|
164
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Image"]'
|
165
|
-
);
|
166
|
-
|
167
|
-
// Image options dropdown.
|
168
|
-
const imageOptionsButton = await page.waitForSelector(
|
169
|
-
'tr.block-editor-list-view-leaf:first-child button[aria-label="Options for Image block"]'
|
170
|
-
);
|
171
|
-
|
172
|
-
await imageOptionsButton.click();
|
173
|
-
|
174
|
-
const imageRemoveButton = await page.waitForXPath(
|
175
|
-
'//button[contains(., "Remove Image")]'
|
176
|
-
);
|
177
|
-
|
178
|
-
// Remove Image block.
|
179
|
-
await imageRemoveButton.click();
|
180
|
-
|
181
|
-
// Heading block should be selected as next block.
|
182
|
-
await page.waitForSelector(
|
183
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Heading"]'
|
184
|
-
);
|
185
|
-
} );
|
186
|
-
|
187
|
-
/**
|
188
|
-
* When all the blocks gets removed from the editor, it inserts a default paragraph block;
|
189
|
-
* make sure that paragraph block gets selected after removing blocks from ListView.
|
190
|
-
*/
|
191
|
-
it( 'should select default paragraph block after removing all blocks', async () => {
|
192
|
-
// Insert some blocks of different types.
|
193
|
-
await insertBlock( 'Image' );
|
194
|
-
await insertBlock( 'Heading' );
|
195
|
-
|
196
|
-
// Open list view.
|
197
|
-
await openListView();
|
198
|
-
|
199
|
-
// The last inserted heading block should be selected in List View.
|
200
|
-
const headingBlock = await page.waitForSelector(
|
201
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Heading"]'
|
202
|
-
);
|
203
|
-
|
204
|
-
await headingBlock.click();
|
205
|
-
|
206
|
-
// Select all two blocks.
|
207
|
-
await pressKeyWithModifier( 'shift', 'ArrowUp' );
|
208
|
-
|
209
|
-
// Both Image and Heading blocks should have selected.
|
210
|
-
await page.waitForSelector(
|
211
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Heading"]'
|
212
|
-
);
|
213
|
-
await page.waitForSelector(
|
214
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Image"]'
|
215
|
-
);
|
216
|
-
|
217
|
-
const imageOptionsButton = await page.waitForSelector(
|
218
|
-
'tr.block-editor-list-view-leaf:first-child button[aria-label="Options for Image block"]'
|
219
|
-
);
|
220
|
-
|
221
|
-
// Blocks options dropdown.
|
222
|
-
await imageOptionsButton.click();
|
223
|
-
|
224
|
-
const blocksRemoveButton = await page.waitForXPath(
|
225
|
-
'//button[contains(., "Remove blocks")]'
|
226
|
-
);
|
227
|
-
|
228
|
-
// Remove all blocks.
|
229
|
-
await blocksRemoveButton.click();
|
230
|
-
|
231
|
-
// Newly created default paragraph block should be selected.
|
232
|
-
await page.waitForSelector(
|
233
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Paragraph"]'
|
234
|
-
);
|
235
|
-
} );
|
236
|
-
|
237
|
-
it( 'should expand nested list items', async () => {
|
238
|
-
// Insert some blocks of different types.
|
239
|
-
await insertBlock( 'Cover' );
|
240
|
-
|
241
|
-
// Click first color option from the block placeholder's color picker to make the inner blocks appear.
|
242
|
-
const colorPickerButton = await page.waitForSelector(
|
243
|
-
'.wp-block-cover__placeholder-background-options .components-circular-option-picker__option-wrapper:first-child button'
|
244
|
-
);
|
245
|
-
await colorPickerButton.click();
|
246
|
-
|
247
|
-
// Open list view.
|
248
|
-
await openListView();
|
249
|
-
|
250
|
-
// Things start off expanded.
|
251
|
-
expect( await getBlockListLeafNodes() ).toHaveLength( 2 );
|
252
|
-
|
253
|
-
const blockListExpanders = await page.$$(
|
254
|
-
'.block-editor-list-view__expander'
|
255
|
-
);
|
256
|
-
|
257
|
-
// Collapse the first block
|
258
|
-
await blockListExpanders[ 0 ].click();
|
259
|
-
|
260
|
-
// Check that we're collapsed
|
261
|
-
expect( await getBlockListLeafNodes() ).toHaveLength( 1 );
|
262
|
-
|
263
|
-
// Focus the cover block. The paragraph is not focussed by default.
|
264
|
-
const coverBlock = await page.waitForSelector( '.wp-block-cover' );
|
265
|
-
|
266
|
-
await coverBlock.focus();
|
267
|
-
|
268
|
-
// Click the cover title placeholder.
|
269
|
-
const coverTitle = await page.waitForSelector(
|
270
|
-
'.wp-block-cover .wp-block-paragraph'
|
271
|
-
);
|
272
|
-
|
273
|
-
await coverTitle.click();
|
274
|
-
|
275
|
-
// The block list should contain two leafs and the second should be selected (and be a paragraph).
|
276
|
-
const selectedElementText = await page.$eval(
|
277
|
-
'.block-editor-list-view-leaf.is-selected .block-editor-list-view-block-contents',
|
278
|
-
( element ) => element.innerText
|
279
|
-
);
|
280
|
-
|
281
|
-
expect( selectedElementText ).toContain( 'Paragraph' );
|
282
|
-
} );
|
283
|
-
|
284
|
-
// Test keyboard Home/End keys.
|
285
|
-
it( 'ensures the Home/End keyboard keys move focus to start/end of list', async () => {
|
286
|
-
// Insert some blocks of different types.
|
287
|
-
await insertBlock( 'Image' );
|
288
|
-
await insertBlock( 'Heading' );
|
289
|
-
await insertBlock( 'Paragraph' );
|
290
|
-
await insertBlock( 'Columns' );
|
291
|
-
await insertBlock( 'Group' );
|
292
|
-
|
293
|
-
// Open list view.
|
294
|
-
await pressKeyWithModifier( 'access', 'o' );
|
295
|
-
|
296
|
-
// The last inserted group block should be selected in list view.
|
297
|
-
await page.waitForSelector(
|
298
|
-
'.block-editor-list-view-block__contents-cell[aria-selected="true"][aria-label^="Group"]'
|
299
|
-
);
|
300
|
-
|
301
|
-
// Press Home to go to the first inserted block (image).
|
302
|
-
await page.keyboard.press( 'Home' );
|
303
|
-
const listViewImageBlock = await page.waitForXPath(
|
304
|
-
'//a[contains(., "Image")]'
|
305
|
-
);
|
306
|
-
await expect( listViewImageBlock ).toHaveFocus();
|
307
|
-
|
308
|
-
// Press End followed by Arrow Up to go to the second to last block (columns).
|
309
|
-
await page.keyboard.press( 'End' );
|
310
|
-
await page.keyboard.press( 'ArrowUp' );
|
311
|
-
const listViewColumnsBlock = await page.waitForXPath(
|
312
|
-
'//a[contains(., "Columns")]'
|
313
|
-
);
|
314
|
-
await expect( listViewColumnsBlock ).toHaveFocus();
|
315
|
-
|
316
|
-
// Try navigating the right column to image block options button via Home key.
|
317
|
-
await page.keyboard.press( 'ArrowRight' );
|
318
|
-
await page.keyboard.press( 'Home' );
|
319
|
-
const listViewImageBlockRight = await page.waitForSelector(
|
320
|
-
'button[aria-label="Options for Image block"]'
|
321
|
-
);
|
322
|
-
await expect( listViewImageBlockRight ).toHaveFocus();
|
323
|
-
|
324
|
-
// Try navigating the right column to group block options button.
|
325
|
-
await page.keyboard.press( 'End' );
|
326
|
-
const listViewGroupBlockRight = await page.waitForSelector(
|
327
|
-
'button[aria-label="Options for Group block"]'
|
328
|
-
);
|
329
|
-
await expect( listViewGroupBlockRight ).toHaveFocus();
|
330
|
-
} );
|
331
|
-
|
332
|
-
async function getActiveElementLabel() {
|
333
|
-
return page.evaluate(
|
334
|
-
() =>
|
335
|
-
document.activeElement.getAttribute( 'aria-label' ) ||
|
336
|
-
document.activeElement.textContent
|
337
|
-
);
|
338
|
-
}
|
339
|
-
|
340
|
-
// If list view sidebar is open and focus is not inside the sidebar, move focus to the sidebar when using the shortcut. If focus is inside the sidebar, shortcut should close the sidebar.
|
341
|
-
it( 'ensures the list view global shortcut works properly', async () => {
|
342
|
-
// Insert some blocks of different types.
|
343
|
-
await insertBlock( 'Image' );
|
344
|
-
await insertBlock( 'Paragraph' );
|
345
|
-
await page.keyboard.type( 'Paragraph text.' );
|
346
|
-
|
347
|
-
// Open list view sidebar.
|
348
|
-
await pressKeyWithModifier( 'access', 'o' );
|
349
|
-
|
350
|
-
// Navigate to the image block.
|
351
|
-
await page.keyboard.press( 'ArrowUp' );
|
352
|
-
// Check if image block link in the list view has focus by XPath selector.
|
353
|
-
const listViewImageBlock = await page.waitForXPath(
|
354
|
-
'//a[contains(., "Image")]'
|
355
|
-
);
|
356
|
-
await expect( listViewImageBlock ).toHaveFocus();
|
357
|
-
// Select the image block in the list view to move focus to it in the canvas.
|
358
|
-
await page.keyboard.press( 'Enter' );
|
359
|
-
|
360
|
-
// Check if image block upload button has focus by XPath selector.
|
361
|
-
const imageBlockUploadButton = await page.waitForXPath(
|
362
|
-
'//button[contains(text(), "Upload")]'
|
363
|
-
);
|
364
|
-
await expect( imageBlockUploadButton ).toHaveFocus();
|
365
|
-
|
366
|
-
// Since focus is now at the image block upload button in the canvas, pressing the list view shortcut should bring focus back to the image block in the list view.
|
367
|
-
await pressKeyWithModifier( 'access', 'o' );
|
368
|
-
await expect( listViewImageBlock ).toHaveFocus();
|
369
|
-
|
370
|
-
// Since focus is now inside the list view, the shortcut should close the sidebar.
|
371
|
-
await pressKeyWithModifier( 'access', 'o' );
|
372
|
-
// Focus should now be on the paragraph block since that is where we opened the list view sidebar. This is not a perfect solution, but current functionality prevents a better way at the moment. Get the current block aria-label and compare.
|
373
|
-
await expect( await getActiveElementLabel() ).toEqual(
|
374
|
-
'Paragraph block'
|
375
|
-
);
|
376
|
-
// List view sidebar should be closed.
|
377
|
-
await expect( await isListViewOpen() ).toBeFalsy();
|
378
|
-
|
379
|
-
// Open list view sidebar.
|
380
|
-
await pressKeyWithModifier( 'access', 'o' );
|
381
|
-
|
382
|
-
// Focus the list view close button and make sure the shortcut will close the list view. This is to catch a bug where elements could be out of range of the sidebar region. Must shift+tab 3 times to reach cclose button before tabs.
|
383
|
-
await pressKeyWithModifier( 'shift', 'Tab' );
|
384
|
-
await pressKeyWithModifier( 'shift', 'Tab' );
|
385
|
-
await pressKeyWithModifier( 'shift', 'Tab' );
|
386
|
-
await expect( await getActiveElementLabel() ).toEqual(
|
387
|
-
'Close Document Overview Sidebar'
|
388
|
-
);
|
389
|
-
|
390
|
-
// Close the list view sidebar.
|
391
|
-
await pressKeyWithModifier( 'access', 'o' );
|
392
|
-
// List view sidebar should be closed.
|
393
|
-
await expect( await isListViewOpen() ).toBeFalsy();
|
394
|
-
|
395
|
-
// Open list view sidebar.
|
396
|
-
await pressKeyWithModifier( 'access', 'o' );
|
397
|
-
|
398
|
-
// Focus the outline tab and select it. This test ensures the outline tab receives similar focus events based on the shortcut.
|
399
|
-
await pressKeyWithModifier( 'shift', 'Tab' );
|
400
|
-
await expect( await getActiveElementLabel() ).toEqual( 'Outline' );
|
401
|
-
await page.keyboard.press( 'Enter' );
|
402
|
-
|
403
|
-
// From here, tab in to the editor so focus can be checked on return to the outline tab in the sidebar.
|
404
|
-
await pressKeyTimes( 'Tab', 2 );
|
405
|
-
// Focus should be placed on the outline tab button since there is nothing to focus inside the tab itself.
|
406
|
-
await pressKeyWithModifier( 'access', 'o' );
|
407
|
-
await expect( await getActiveElementLabel() ).toEqual( 'Outline' );
|
408
|
-
|
409
|
-
// Close the list view sidebar.
|
410
|
-
await pressKeyWithModifier( 'access', 'o' );
|
411
|
-
// List view sidebar should be closed.
|
412
|
-
await expect( await isListViewOpen() ).toBeFalsy();
|
413
|
-
} );
|
414
|
-
} );
|
@@ -1,254 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
createNewPost,
|
6
|
-
openDocumentSettingsSidebar,
|
7
|
-
publishPost,
|
8
|
-
setBrowserViewport,
|
9
|
-
trashAllPosts,
|
10
|
-
} from '@wordpress/e2e-test-utils';
|
11
|
-
|
12
|
-
async function prepTestPost( postType, viewport ) {
|
13
|
-
// Create a post
|
14
|
-
await createNewPost( { postType } );
|
15
|
-
|
16
|
-
await page.type(
|
17
|
-
'.editor-post-title__input',
|
18
|
-
`Switch scheduled ${ postType } to draft`
|
19
|
-
);
|
20
|
-
await page.keyboard.press( 'Enter' );
|
21
|
-
await page.keyboard.type(
|
22
|
-
`This will be a scheduled ${ postType } edited in a ${ viewport } viewport`
|
23
|
-
);
|
24
|
-
|
25
|
-
// Unselect the blocks.
|
26
|
-
await page.evaluate( () => {
|
27
|
-
wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
|
28
|
-
} );
|
29
|
-
}
|
30
|
-
|
31
|
-
async function publishTestPost( postType, viewport ) {
|
32
|
-
// Create a post
|
33
|
-
await prepTestPost( postType, viewport );
|
34
|
-
|
35
|
-
// Publish the post
|
36
|
-
await publishPost();
|
37
|
-
|
38
|
-
const publishedSnackBar = await page.waitForXPath(
|
39
|
-
`//*[@aria-label="Dismiss this notice"][@role="button"]/div[contains(text(),"published")]`
|
40
|
-
);
|
41
|
-
|
42
|
-
const snackBarText = await (
|
43
|
-
await publishedSnackBar.getProperty( 'textContent' )
|
44
|
-
).jsonValue();
|
45
|
-
|
46
|
-
expect( snackBarText.toLowerCase() ).toBe(
|
47
|
-
`${ postType } published.view ${ postType }`
|
48
|
-
);
|
49
|
-
|
50
|
-
const closePublishingPanel = await page.waitForXPath(
|
51
|
-
'//button[@aria-label="Close panel"]'
|
52
|
-
);
|
53
|
-
await closePublishingPanel.click();
|
54
|
-
}
|
55
|
-
|
56
|
-
async function scheduleTestPost( postType, viewport ) {
|
57
|
-
// Create a post
|
58
|
-
await prepTestPost( postType, viewport );
|
59
|
-
|
60
|
-
if ( viewport === 'small' ) {
|
61
|
-
await openDocumentSettingsSidebar();
|
62
|
-
}
|
63
|
-
// Set a publish date for the next month.
|
64
|
-
await page.click( '.edit-post-post-schedule__toggle' );
|
65
|
-
await page.click( '*[aria-label="View next month"]' );
|
66
|
-
|
67
|
-
await (
|
68
|
-
await page.$x(
|
69
|
-
'//*[@role="application"][@aria-label="Calendar"]//button[text()="15"]'
|
70
|
-
)
|
71
|
-
)[ 0 ].click();
|
72
|
-
|
73
|
-
await page.click( '.edit-post-post-schedule__toggle' );
|
74
|
-
|
75
|
-
if ( viewport === 'small' ) {
|
76
|
-
const closeDocumentSettingsButton = await page.waitForXPath(
|
77
|
-
'//div[@aria-label="Editor settings"]//button[@aria-label="Close settings"]'
|
78
|
-
);
|
79
|
-
await closeDocumentSettingsButton.click();
|
80
|
-
}
|
81
|
-
|
82
|
-
// Important: target an ellipsis (…) and not three dots (...)
|
83
|
-
const scheduleButton = await page.waitForXPath(
|
84
|
-
'//button[text()="Schedule…"]'
|
85
|
-
);
|
86
|
-
await scheduleButton.click();
|
87
|
-
const secondScheduleButton = await page.waitForXPath(
|
88
|
-
'//button[text()="Schedule"]'
|
89
|
-
);
|
90
|
-
await secondScheduleButton.click();
|
91
|
-
|
92
|
-
const closePublishingPanel = await page.waitForXPath(
|
93
|
-
'//button[@aria-label="Close panel"]'
|
94
|
-
);
|
95
|
-
await closePublishingPanel.click();
|
96
|
-
}
|
97
|
-
|
98
|
-
async function verifyRevertToDraft( postType ) {
|
99
|
-
const revertedSnackBar = await page.waitForXPath(
|
100
|
-
`//*[@aria-label="Dismiss this notice"][@role="button"]/div[contains(text(),"reverted")]`
|
101
|
-
);
|
102
|
-
|
103
|
-
const revertedSnackBarText = await (
|
104
|
-
await revertedSnackBar.getProperty( 'textContent' )
|
105
|
-
).jsonValue();
|
106
|
-
|
107
|
-
expect( revertedSnackBarText.toLowerCase() ).toBe(
|
108
|
-
`${ postType } reverted to draft.`
|
109
|
-
);
|
110
|
-
}
|
111
|
-
|
112
|
-
describe( 'Clicking "Switch to draft" on a published post/page', () => {
|
113
|
-
beforeAll( async () => {
|
114
|
-
await trashAllPosts( 'post' );
|
115
|
-
await trashAllPosts( 'page' );
|
116
|
-
} );
|
117
|
-
afterEach( async () => {
|
118
|
-
await setBrowserViewport( 'large' );
|
119
|
-
} );
|
120
|
-
|
121
|
-
[ 'large', 'small' ].forEach( ( viewport ) => {
|
122
|
-
describe( `in a ${ viewport } viewport`, () => {
|
123
|
-
[ 'post', 'page' ].forEach( ( postType ) => {
|
124
|
-
const buttonText =
|
125
|
-
viewport === 'large' ? 'Switch to draft' : 'Draft';
|
126
|
-
beforeEach( async () => {
|
127
|
-
await setBrowserViewport( viewport );
|
128
|
-
} );
|
129
|
-
|
130
|
-
it( `should leave a published ${ postType } published if canceled`, async () => {
|
131
|
-
publishTestPost( postType, viewport );
|
132
|
-
|
133
|
-
const switchToDraftButton = await page.waitForXPath(
|
134
|
-
`//button[contains(text(), "${ buttonText }")]`
|
135
|
-
);
|
136
|
-
await switchToDraftButton.click();
|
137
|
-
|
138
|
-
// Process the ConfirmDialog
|
139
|
-
await page.waitForXPath(
|
140
|
-
'//*[text()="Are you sure you want to unpublish this post?"]'
|
141
|
-
);
|
142
|
-
const [ cancelButton ] = await page.$x(
|
143
|
-
'//*[@role="dialog"][not(@id="wp-link-wrap")]//button[text()="Cancel"]'
|
144
|
-
);
|
145
|
-
await cancelButton.click();
|
146
|
-
|
147
|
-
const postStatus = await page.evaluate( () => {
|
148
|
-
return wp.data
|
149
|
-
.select( 'core/editor' )
|
150
|
-
.getEditedPostAttribute( 'status' );
|
151
|
-
} );
|
152
|
-
expect( postStatus ).toBe( 'publish' );
|
153
|
-
} );
|
154
|
-
it( `should revert a published ${ postType } to a draft if confirmed`, async () => {
|
155
|
-
// Switch to draft
|
156
|
-
const switchToDraftButton = await page.waitForXPath(
|
157
|
-
`//button[contains(text(), "${ buttonText }")]`
|
158
|
-
);
|
159
|
-
await switchToDraftButton.click();
|
160
|
-
|
161
|
-
// Process the ConfirmDialog
|
162
|
-
await page.waitForXPath(
|
163
|
-
'//*[text()="Are you sure you want to unpublish this post?"]'
|
164
|
-
);
|
165
|
-
const [ confirmButton ] = await page.$x(
|
166
|
-
'//*[@role="dialog"]//button[text()="OK"]'
|
167
|
-
);
|
168
|
-
await confirmButton.click();
|
169
|
-
|
170
|
-
await verifyRevertToDraft( postType );
|
171
|
-
|
172
|
-
const postStatus = await page.evaluate( () => {
|
173
|
-
return wp.data
|
174
|
-
.select( 'core/editor' )
|
175
|
-
.getEditedPostAttribute( 'status' );
|
176
|
-
} );
|
177
|
-
expect( postStatus ).toBe( 'draft' );
|
178
|
-
} );
|
179
|
-
} );
|
180
|
-
} );
|
181
|
-
} );
|
182
|
-
} );
|
183
|
-
describe( 'Clicking "Switch to draft" on a scheduled post/page', () => {
|
184
|
-
beforeAll( async () => {
|
185
|
-
await trashAllPosts( 'post' );
|
186
|
-
await trashAllPosts( 'page' );
|
187
|
-
} );
|
188
|
-
afterEach( async () => {
|
189
|
-
await setBrowserViewport( 'large' );
|
190
|
-
} );
|
191
|
-
|
192
|
-
[ 'large', 'small' ].forEach( ( viewport ) => {
|
193
|
-
describe( `in a ${ viewport } viewport`, () => {
|
194
|
-
[ 'post', 'page' ].forEach( ( postType ) => {
|
195
|
-
const buttonText =
|
196
|
-
viewport === 'large' ? 'Switch to draft' : 'Draft';
|
197
|
-
beforeEach( async () => {
|
198
|
-
await setBrowserViewport( viewport );
|
199
|
-
} );
|
200
|
-
|
201
|
-
it( `should leave a scheduled ${ postType } scheduled if canceled`, async () => {
|
202
|
-
scheduleTestPost( postType, viewport );
|
203
|
-
|
204
|
-
const switchToDraftButton = await page.waitForXPath(
|
205
|
-
`//button[contains(text(), "${ buttonText }")]`
|
206
|
-
);
|
207
|
-
await switchToDraftButton.click();
|
208
|
-
|
209
|
-
// Process the ConfirmDialog
|
210
|
-
await page.waitForXPath(
|
211
|
-
'//*[text()="Are you sure you want to unschedule this post?"]'
|
212
|
-
);
|
213
|
-
const [ cancelButton ] = await page.$x(
|
214
|
-
'//*[@role="dialog"][not(@id="wp-link-wrap")]//button[text()="Cancel"]'
|
215
|
-
);
|
216
|
-
await cancelButton.click();
|
217
|
-
|
218
|
-
// Confirm post is still scheduled
|
219
|
-
const postStatus = await page.evaluate( () => {
|
220
|
-
return wp.data
|
221
|
-
.select( 'core/editor' )
|
222
|
-
.getEditedPostAttribute( 'status' );
|
223
|
-
} );
|
224
|
-
expect( postStatus ).toBe( 'future' );
|
225
|
-
} );
|
226
|
-
it( `should revert a scheduled ${ postType } to a draft if confirmed`, async () => {
|
227
|
-
// Switch to draft
|
228
|
-
const switchToDraftButton = await page.waitForXPath(
|
229
|
-
`//button[contains(text(), "${ buttonText }")]`
|
230
|
-
);
|
231
|
-
await switchToDraftButton.click();
|
232
|
-
|
233
|
-
// Process the ConfirmDialog
|
234
|
-
await page.waitForXPath(
|
235
|
-
'//*[text()="Are you sure you want to unschedule this post?"]'
|
236
|
-
);
|
237
|
-
const [ confirmButton ] = await page.$x(
|
238
|
-
'//*[@role="dialog"]//button[text()="OK"]'
|
239
|
-
);
|
240
|
-
await confirmButton.click();
|
241
|
-
|
242
|
-
await verifyRevertToDraft( postType );
|
243
|
-
|
244
|
-
const postStatus = await page.evaluate( () => {
|
245
|
-
return wp.data
|
246
|
-
.select( 'core/editor' )
|
247
|
-
.getEditedPostAttribute( 'status' );
|
248
|
-
} );
|
249
|
-
expect( postStatus ).toBe( 'draft' );
|
250
|
-
} );
|
251
|
-
} );
|
252
|
-
} );
|
253
|
-
} );
|
254
|
-
} );
|