@wordpress/e2e-tests 7.19.0 → 7.20.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/LICENSE.md +1 -1
- package/jest.config.js +0 -1
- package/package.json +8 -9
- package/plugins/iframed-block/block.json +1 -0
- package/plugins/iframed-inline-styles/block.json +1 -0
- package/plugins/iframed-masonry-block/block.json +1 -0
- package/plugins/iframed-multiple-stylesheets/block.json +1 -0
- package/plugins/interactive-blocks/directive-bind/block.json +1 -0
- package/plugins/interactive-blocks/directive-body/block.json +1 -0
- package/plugins/interactive-blocks/directive-class/block.json +1 -0
- package/plugins/interactive-blocks/directive-context/block.json +1 -0
- package/plugins/interactive-blocks/directive-init/block.json +1 -0
- package/plugins/interactive-blocks/directive-key/block.json +1 -0
- package/plugins/interactive-blocks/directive-on/block.json +1 -0
- package/plugins/interactive-blocks/directive-priorities/block.json +1 -0
- package/plugins/interactive-blocks/directive-slots/block.json +1 -0
- package/plugins/interactive-blocks/directive-style/block.json +1 -0
- package/plugins/interactive-blocks/directive-text/block.json +1 -0
- package/plugins/interactive-blocks/directive-watch/block.json +1 -0
- package/plugins/interactive-blocks/negation-operator/block.json +1 -0
- package/plugins/interactive-blocks/router-navigate/block.json +1 -0
- package/plugins/interactive-blocks/router-regions/block.json +1 -0
- package/plugins/interactive-blocks/store-tag/block.json +1 -0
- package/plugins/interactive-blocks/tovdom/block.json +1 -0
- package/plugins/interactive-blocks/tovdom-islands/block.json +1 -0
- package/plugins/interactive-blocks/tovdom-islands/render.php +12 -0
- package/plugins/pattern-recursion.php +22 -0
- package/specs/editor/various/inserting-blocks.test.js +3 -5
- package/specs/editor/various/__snapshots__/block-editor-keyboard-shortcuts.test.js.snap +0 -153
- package/specs/editor/various/allowed-patterns.test.js +0 -74
- package/specs/editor/various/block-editor-keyboard-shortcuts.test.js +0 -110
- package/specs/editor/various/block-switcher.test.js +0 -130
- package/specs/editor/various/core-settings.test.js +0 -42
- package/specs/editor/various/datepicker.test.js +0 -148
- package/specs/editor/various/dropdown-menu.test.js +0 -143
- package/specs/editor/various/editor-modes.test.js +0 -163
- package/specs/editor/various/invalid-block.test.js +0 -100
- package/specs/editor/various/nux.test.js +0 -158
- package/specs/editor/various/preferences.test.js +0 -62
- package/specs/editor/various/publish-panel.test.js +0 -82
- package/specs/editor/various/publishing.test.js +0 -176
- package/specs/editor/various/scheduling.test.js +0 -65
- package/specs/editor/various/sidebar.test.js +0 -171
- package/specs/editor/various/taxonomies.test.js +0 -251
- package/specs/experiments/blocks/post-comments-form.test.js +0 -53
- package/specs/experiments/experimental-features.js +0 -39
- package/specs/experiments/fixtures/menu-items-request-fixture.json +0 -84
- package/specs/site-editor/settings-sidebar.test.js +0 -122
- package/specs/widgets/editing-widgets.test.js +0 -962
@@ -1,962 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
__experimentalActivatePlugin as activatePlugin,
|
6
|
-
activateTheme,
|
7
|
-
clickBlockToolbarButton,
|
8
|
-
__experimentalDeactivatePlugin as deactivatePlugin,
|
9
|
-
showBlockToolbar,
|
10
|
-
visitAdminPage,
|
11
|
-
deleteAllWidgets,
|
12
|
-
pressKeyWithModifier,
|
13
|
-
__experimentalRest as rest,
|
14
|
-
openListView,
|
15
|
-
closeListView,
|
16
|
-
openGlobalBlockInserter,
|
17
|
-
searchForBlock,
|
18
|
-
closeGlobalBlockInserter,
|
19
|
-
setBrowserViewport,
|
20
|
-
} from '@wordpress/e2e-test-utils';
|
21
|
-
|
22
|
-
/**
|
23
|
-
* External dependencies
|
24
|
-
*/
|
25
|
-
// eslint-disable-next-line no-restricted-imports
|
26
|
-
import { find, findAll } from 'puppeteer-testing-library';
|
27
|
-
|
28
|
-
describe( 'Widgets screen', () => {
|
29
|
-
beforeEach( async () => {
|
30
|
-
await visitWidgetsScreen();
|
31
|
-
|
32
|
-
// Disable welcome guide if it is enabled.
|
33
|
-
const isWelcomeGuideActive = await page.evaluate(
|
34
|
-
() =>
|
35
|
-
!! wp.data
|
36
|
-
.select( 'core/preferences' )
|
37
|
-
.get( 'core/edit-widgets', 'welcomeGuide' )
|
38
|
-
);
|
39
|
-
if ( isWelcomeGuideActive ) {
|
40
|
-
await page.evaluate( () =>
|
41
|
-
wp.data
|
42
|
-
.dispatch( 'core/preferences' )
|
43
|
-
.toggle( 'core/edit-widgets', 'welcomeGuide' )
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
|
-
// Wait for the widget areas to load.
|
48
|
-
await findAll( {
|
49
|
-
role: 'document',
|
50
|
-
name: 'Block: Widget Area',
|
51
|
-
} );
|
52
|
-
} );
|
53
|
-
|
54
|
-
afterEach( async () => {
|
55
|
-
await deleteAllWidgets();
|
56
|
-
} );
|
57
|
-
|
58
|
-
beforeAll( async () => {
|
59
|
-
// TODO: Ideally we can bundle our test theme directly in the repo.
|
60
|
-
await activateTheme( 'twentytwenty' );
|
61
|
-
await deleteAllWidgets();
|
62
|
-
} );
|
63
|
-
|
64
|
-
afterAll( async () => {
|
65
|
-
await activateTheme( 'twentytwentyone' );
|
66
|
-
} );
|
67
|
-
|
68
|
-
async function getBlockInGlobalInserter( blockName ) {
|
69
|
-
await openGlobalBlockInserter();
|
70
|
-
|
71
|
-
const blockLibrary = await find( {
|
72
|
-
role: 'region',
|
73
|
-
name: 'Block Library',
|
74
|
-
} );
|
75
|
-
|
76
|
-
// Check that there are categorizations in the inserter (#26329).
|
77
|
-
const categoryHeaders = await findAll(
|
78
|
-
{
|
79
|
-
role: 'heading',
|
80
|
-
level: 2,
|
81
|
-
},
|
82
|
-
{
|
83
|
-
root: blockLibrary,
|
84
|
-
}
|
85
|
-
);
|
86
|
-
expect( categoryHeaders.length > 0 ).toBe( true );
|
87
|
-
|
88
|
-
const searchBox = await find( {
|
89
|
-
role: 'searchbox',
|
90
|
-
name: 'Search for blocks and patterns',
|
91
|
-
} );
|
92
|
-
await searchBox.type( blockName );
|
93
|
-
|
94
|
-
await searchForBlock( blockName );
|
95
|
-
|
96
|
-
return await page.waitForXPath(
|
97
|
-
`//button//span[contains(text(), '${ blockName }')]`
|
98
|
-
);
|
99
|
-
}
|
100
|
-
|
101
|
-
async function expectInsertionPointIndicatorToBeBelowLastBlock(
|
102
|
-
widgetArea
|
103
|
-
) {
|
104
|
-
const childBlocks = await findAll(
|
105
|
-
{ selector: '[data-block]' },
|
106
|
-
{ root: widgetArea }
|
107
|
-
);
|
108
|
-
// The initial block appender also has the [data-block] property, adding to the count.
|
109
|
-
const lastBlock = childBlocks[ childBlocks.length - 2 ];
|
110
|
-
const lastBlockBoundingBox = await lastBlock.boundingBox();
|
111
|
-
|
112
|
-
const insertionPointIndicator = await page.$(
|
113
|
-
'.block-editor-block-list__insertion-point-indicator'
|
114
|
-
);
|
115
|
-
const insertionPointIndicatorBoundingBox =
|
116
|
-
await insertionPointIndicator.boundingBox();
|
117
|
-
|
118
|
-
expect(
|
119
|
-
insertionPointIndicatorBoundingBox.y > lastBlockBoundingBox.y
|
120
|
-
).toBe( true );
|
121
|
-
}
|
122
|
-
|
123
|
-
it.skip( 'Should insert content using the global inserter', async () => {
|
124
|
-
const updateButton = await find( {
|
125
|
-
role: 'button',
|
126
|
-
name: 'Update',
|
127
|
-
} );
|
128
|
-
|
129
|
-
// Update button should start out disabled.
|
130
|
-
expect(
|
131
|
-
await updateButton.evaluate( ( button ) => button.disabled )
|
132
|
-
).toBe( true );
|
133
|
-
|
134
|
-
const widgetAreas = await findAll( {
|
135
|
-
role: 'document',
|
136
|
-
name: 'Block: Widget Area',
|
137
|
-
} );
|
138
|
-
const [ firstWidgetArea, secondWidgetArea ] = widgetAreas;
|
139
|
-
|
140
|
-
let addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
141
|
-
await addParagraphBlock.hover();
|
142
|
-
|
143
|
-
// FIXME: The insertion point indicator is not showing when the widget area has no blocks.
|
144
|
-
// await expectInsertionPointIndicatorToBeBelowLastBlock(
|
145
|
-
// firstWidgetArea
|
146
|
-
// );
|
147
|
-
|
148
|
-
await addParagraphBlock.click();
|
149
|
-
|
150
|
-
// Adding content should enable the Update button.
|
151
|
-
expect(
|
152
|
-
await updateButton.evaluate( ( button ) => button.disabled )
|
153
|
-
).toBe( false );
|
154
|
-
|
155
|
-
let addedParagraphBlockInFirstWidgetArea = await find(
|
156
|
-
{
|
157
|
-
name: /^Empty block/,
|
158
|
-
selector: '[data-block][data-type="core/paragraph"]',
|
159
|
-
},
|
160
|
-
{
|
161
|
-
root: firstWidgetArea,
|
162
|
-
}
|
163
|
-
);
|
164
|
-
|
165
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
166
|
-
|
167
|
-
await page.keyboard.type( 'First Paragraph' );
|
168
|
-
|
169
|
-
addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
170
|
-
await page.keyboard.press( 'Tab' );
|
171
|
-
await page.keyboard.press( 'Tab' );
|
172
|
-
|
173
|
-
await expectInsertionPointIndicatorToBeBelowLastBlock(
|
174
|
-
firstWidgetArea
|
175
|
-
);
|
176
|
-
await addParagraphBlock.focus();
|
177
|
-
await addParagraphBlock.click();
|
178
|
-
|
179
|
-
addedParagraphBlockInFirstWidgetArea = await firstWidgetArea.$(
|
180
|
-
'[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
|
181
|
-
);
|
182
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
183
|
-
await page.keyboard.type( 'Second Paragraph' );
|
184
|
-
|
185
|
-
const addShortCodeBlock = await getBlockInGlobalInserter( 'Shortcode' );
|
186
|
-
await addShortCodeBlock.click();
|
187
|
-
|
188
|
-
const shortCodeInput = await page.waitForSelector(
|
189
|
-
'textarea[aria-label="Shortcode text"]'
|
190
|
-
);
|
191
|
-
await shortCodeInput.focus();
|
192
|
-
// The famous Big Buck Bunny video.
|
193
|
-
await shortCodeInput.type(
|
194
|
-
'[video src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"]'
|
195
|
-
);
|
196
|
-
|
197
|
-
// Add to the second widget area.
|
198
|
-
await secondWidgetArea.click();
|
199
|
-
|
200
|
-
addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
201
|
-
await addParagraphBlock.click();
|
202
|
-
|
203
|
-
const addedParagraphBlockInSecondWidgetArea = await secondWidgetArea.$(
|
204
|
-
'[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
|
205
|
-
);
|
206
|
-
await addedParagraphBlockInSecondWidgetArea.focus();
|
207
|
-
await page.keyboard.type( 'Third Paragraph' );
|
208
|
-
|
209
|
-
await saveWidgets();
|
210
|
-
|
211
|
-
// The Update button should be disabled again after saving.
|
212
|
-
expect(
|
213
|
-
await updateButton.evaluate( ( button ) => button.disabled )
|
214
|
-
).toBe( true );
|
215
|
-
|
216
|
-
const serializedWidgetAreas = await getSerializedWidgetAreas();
|
217
|
-
expect( serializedWidgetAreas ).toMatchInlineSnapshot( `
|
218
|
-
Object {
|
219
|
-
"sidebar-1": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
220
|
-
<p>First Paragraph</p>
|
221
|
-
</div></div>
|
222
|
-
<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
223
|
-
<p>Second Paragraph</p>
|
224
|
-
</div></div>
|
225
|
-
<div class=\\"widget widget_block\\"><div class=\\"widget-content\\"><p><div style=\\"width: 580px;\\" class=\\"wp-video\\"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
|
226
|
-
<video class=\\"wp-video-shortcode\\" id=\\"video-0-1\\" width=\\"580\\" height=\\"326\\" preload=\\"metadata\\" controls=\\"controls\\"><source type=\\"video/mp4\\" src=\\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4?_=1\\" /><a href=\\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\\">http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4</a></video></div></p>
|
227
|
-
</div></div>",
|
228
|
-
"sidebar-2": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
229
|
-
<p>Third Paragraph</p>
|
230
|
-
</div></div>",
|
231
|
-
}
|
232
|
-
` );
|
233
|
-
} );
|
234
|
-
|
235
|
-
it.skip( 'Should insert content using the inline inserter', async () => {
|
236
|
-
const [ firstWidgetArea ] = await findAll( {
|
237
|
-
role: 'document',
|
238
|
-
name: 'Block: Widget Area',
|
239
|
-
} );
|
240
|
-
|
241
|
-
// Scroll to the end of the first widget area.
|
242
|
-
await firstWidgetArea.evaluate( ( node ) =>
|
243
|
-
node.scrollIntoView( { block: 'end' } )
|
244
|
-
);
|
245
|
-
|
246
|
-
const firstWidgetAreaBoundingBox = await firstWidgetArea.boundingBox();
|
247
|
-
|
248
|
-
// Click near the end of the widget area to select it.
|
249
|
-
await page.mouse.click(
|
250
|
-
firstWidgetAreaBoundingBox.x + firstWidgetAreaBoundingBox.width / 2,
|
251
|
-
firstWidgetAreaBoundingBox.y +
|
252
|
-
firstWidgetAreaBoundingBox.height -
|
253
|
-
10
|
254
|
-
);
|
255
|
-
|
256
|
-
let inlineInserterButton = await find( {
|
257
|
-
role: 'combobox',
|
258
|
-
name: 'Add block',
|
259
|
-
} );
|
260
|
-
await inlineInserterButton.click();
|
261
|
-
|
262
|
-
let inlineQuickInserter = await find( {
|
263
|
-
role: 'listbox',
|
264
|
-
name: 'Blocks',
|
265
|
-
} );
|
266
|
-
|
267
|
-
const paragraphBlock = await find(
|
268
|
-
{
|
269
|
-
role: 'option',
|
270
|
-
name: 'Paragraph',
|
271
|
-
},
|
272
|
-
{
|
273
|
-
root: inlineQuickInserter,
|
274
|
-
}
|
275
|
-
);
|
276
|
-
await paragraphBlock.click();
|
277
|
-
|
278
|
-
const firstParagraphBlock = await find(
|
279
|
-
{
|
280
|
-
name: /^Empty block/,
|
281
|
-
selector: '[data-block][data-type="core/paragraph"]',
|
282
|
-
},
|
283
|
-
{
|
284
|
-
root: firstWidgetArea,
|
285
|
-
}
|
286
|
-
);
|
287
|
-
|
288
|
-
await firstParagraphBlock.focus();
|
289
|
-
await page.keyboard.type( 'First Paragraph' );
|
290
|
-
|
291
|
-
await page.keyboard.press( 'Enter' );
|
292
|
-
await page.keyboard.type( 'Second Paragraph' );
|
293
|
-
|
294
|
-
const secondParagraphBlock = await page.evaluateHandle(
|
295
|
-
() => document.activeElement
|
296
|
-
);
|
297
|
-
await expect( secondParagraphBlock ).not.toBeElement(
|
298
|
-
firstParagraphBlock
|
299
|
-
);
|
300
|
-
|
301
|
-
const secondParagraphBlockBoundingBox =
|
302
|
-
await secondParagraphBlock.boundingBox();
|
303
|
-
|
304
|
-
// Click outside the block to move the focus back to the widget area.
|
305
|
-
await page.mouse.click(
|
306
|
-
secondParagraphBlockBoundingBox.x +
|
307
|
-
firstWidgetAreaBoundingBox.width / 2,
|
308
|
-
secondParagraphBlockBoundingBox.y +
|
309
|
-
secondParagraphBlockBoundingBox.height +
|
310
|
-
10
|
311
|
-
);
|
312
|
-
|
313
|
-
// Hover above the last block to trigger the inline inserter between blocks.
|
314
|
-
await page.mouse.move(
|
315
|
-
secondParagraphBlockBoundingBox.x +
|
316
|
-
secondParagraphBlockBoundingBox.width / 2,
|
317
|
-
secondParagraphBlockBoundingBox.y - 10
|
318
|
-
);
|
319
|
-
|
320
|
-
// There will be 2 matches here.
|
321
|
-
// One is the in-between inserter,
|
322
|
-
// and the other one is the button block appender.
|
323
|
-
[ inlineInserterButton ] = await findAll( {
|
324
|
-
role: 'combobox',
|
325
|
-
name: 'Add block',
|
326
|
-
} );
|
327
|
-
await inlineInserterButton.click();
|
328
|
-
|
329
|
-
const inserterSearchBox = await find( {
|
330
|
-
role: 'searchbox',
|
331
|
-
name: 'Search for blocks and patterns',
|
332
|
-
} );
|
333
|
-
await expect( inserterSearchBox ).toHaveFocus();
|
334
|
-
|
335
|
-
await page.keyboard.type( 'Heading' );
|
336
|
-
|
337
|
-
inlineQuickInserter = await find( {
|
338
|
-
role: 'listbox',
|
339
|
-
name: 'Blocks',
|
340
|
-
} );
|
341
|
-
const headingBlockOption = await find(
|
342
|
-
{
|
343
|
-
role: 'option',
|
344
|
-
name: 'Heading',
|
345
|
-
},
|
346
|
-
{
|
347
|
-
root: inlineQuickInserter,
|
348
|
-
}
|
349
|
-
);
|
350
|
-
await headingBlockOption.click();
|
351
|
-
|
352
|
-
// Get the added heading block as second last block.
|
353
|
-
const addedHeadingBlock = await secondParagraphBlock.evaluateHandle(
|
354
|
-
( node ) => node.previousSibling
|
355
|
-
);
|
356
|
-
|
357
|
-
await expect( addedHeadingBlock ).toHaveFocus();
|
358
|
-
|
359
|
-
await page.keyboard.type( 'My Heading' );
|
360
|
-
|
361
|
-
await expect( addedHeadingBlock ).toMatchQuery( {
|
362
|
-
name: 'Block: Heading',
|
363
|
-
level: 2,
|
364
|
-
value: 'My Heading',
|
365
|
-
} );
|
366
|
-
|
367
|
-
await saveWidgets();
|
368
|
-
const serializedWidgetAreas = await getSerializedWidgetAreas();
|
369
|
-
expect( serializedWidgetAreas ).toMatchInlineSnapshot( `
|
370
|
-
Object {
|
371
|
-
"sidebar-1": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
372
|
-
<p>First Paragraph</p>
|
373
|
-
</div></div>
|
374
|
-
<div class=\\"widget widget_block\\"><div class=\\"widget-content\\">
|
375
|
-
<h2 id=\\"my-heading\\">My Heading</h2>
|
376
|
-
</div></div>
|
377
|
-
<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
378
|
-
<p>Second Paragraph</p>
|
379
|
-
</div></div>",
|
380
|
-
}
|
381
|
-
` );
|
382
|
-
} );
|
383
|
-
|
384
|
-
describe( 'Function widgets', () => {
|
385
|
-
async function addMarquee( nbExpectedMarquees ) {
|
386
|
-
const [ firstWidgetArea ] = await findAll( {
|
387
|
-
role: 'document',
|
388
|
-
name: 'Block: Widget Area',
|
389
|
-
} );
|
390
|
-
await firstWidgetArea.focus();
|
391
|
-
const marqueeBlock =
|
392
|
-
await getBlockInGlobalInserter( 'Marquee Greeting' );
|
393
|
-
await marqueeBlock.click();
|
394
|
-
await page.waitForFunction(
|
395
|
-
( expectedMarquees ) => {
|
396
|
-
return (
|
397
|
-
document.querySelectorAll(
|
398
|
-
'[data-testid="marquee-greeting"]'
|
399
|
-
).length === expectedMarquees
|
400
|
-
);
|
401
|
-
},
|
402
|
-
{},
|
403
|
-
nbExpectedMarquees
|
404
|
-
);
|
405
|
-
}
|
406
|
-
|
407
|
-
async function deleteExistingMarquees() {
|
408
|
-
const widgetAreasHoldingMarqueeWidgets = await page.$x(
|
409
|
-
'//input[@data-testid="marquee-greeting"]/ancestor::div[@aria-label="Block: Widget Area"]'
|
410
|
-
);
|
411
|
-
for ( const widgetArea of widgetAreasHoldingMarqueeWidgets ) {
|
412
|
-
const closedPanelBody = await widgetArea.$(
|
413
|
-
'.components-panel__body:not(.is-opened)'
|
414
|
-
);
|
415
|
-
if ( closedPanelBody ) {
|
416
|
-
await closedPanelBody.focus();
|
417
|
-
await closedPanelBody.click();
|
418
|
-
}
|
419
|
-
|
420
|
-
const [ existingMarqueeWidgets ] = await widgetArea.$x(
|
421
|
-
'//input[@data-testid="marquee-greeting"]/ancestor::div[@data-block][contains(@class, "wp-block-legacy-widget")]'
|
422
|
-
);
|
423
|
-
if ( existingMarqueeWidgets ) {
|
424
|
-
await existingMarqueeWidgets.focus();
|
425
|
-
await pressKeyWithModifier( 'access', 'z' );
|
426
|
-
}
|
427
|
-
}
|
428
|
-
}
|
429
|
-
|
430
|
-
beforeAll( async () => {
|
431
|
-
await activatePlugin( 'gutenberg-test-marquee-widget' );
|
432
|
-
} );
|
433
|
-
|
434
|
-
beforeEach( async () => {
|
435
|
-
await deleteExistingMarquees();
|
436
|
-
} );
|
437
|
-
|
438
|
-
afterAll( async () => {
|
439
|
-
await deactivatePlugin( 'gutenberg-test-marquee-widget' );
|
440
|
-
} );
|
441
|
-
|
442
|
-
it( 'Should add and save the marquee widget', async () => {
|
443
|
-
await addMarquee( 1 );
|
444
|
-
|
445
|
-
// Use find because the input might not be visible at first.
|
446
|
-
const marqueeInput = await find( {
|
447
|
-
selector: '[data-testid="marquee-greeting"]',
|
448
|
-
} );
|
449
|
-
// Clear the input.
|
450
|
-
await marqueeInput.evaluate( ( input ) => {
|
451
|
-
input.value = '';
|
452
|
-
} );
|
453
|
-
await marqueeInput.type( 'Howdy' );
|
454
|
-
|
455
|
-
// The first marquee is saved after clicking the form save button.
|
456
|
-
const marqueeSaveButton = await marqueeInput.evaluateHandle(
|
457
|
-
( input ) =>
|
458
|
-
input
|
459
|
-
// Get the parent block element.
|
460
|
-
.closest( '[data-block]' )
|
461
|
-
// Get the save button.
|
462
|
-
.querySelector( 'button[type="submit"]' )
|
463
|
-
);
|
464
|
-
await marqueeSaveButton.click();
|
465
|
-
|
466
|
-
await saveWidgets();
|
467
|
-
let editedSerializedWidgetAreas = await getSerializedWidgetAreas();
|
468
|
-
await expect( editedSerializedWidgetAreas ).toMatchInlineSnapshot( `
|
469
|
-
{
|
470
|
-
"sidebar-1": "<marquee>Howdy</marquee>",
|
471
|
-
}
|
472
|
-
` );
|
473
|
-
|
474
|
-
await page.reload();
|
475
|
-
|
476
|
-
editedSerializedWidgetAreas = await getSerializedWidgetAreas();
|
477
|
-
await expect( editedSerializedWidgetAreas ).toMatchInlineSnapshot( `
|
478
|
-
{
|
479
|
-
"sidebar-1": "<marquee>Howdy</marquee>",
|
480
|
-
}
|
481
|
-
` );
|
482
|
-
|
483
|
-
await addMarquee( 2 );
|
484
|
-
|
485
|
-
const marqueeInputs = await page.$$(
|
486
|
-
'[data-testid="marquee-greeting"]'
|
487
|
-
);
|
488
|
-
|
489
|
-
expect( marqueeInputs ).toHaveLength( 2 );
|
490
|
-
await marqueeInputs[ 0 ].type( 'first ' );
|
491
|
-
await marqueeInputs[ 1 ].type( 'Second ' );
|
492
|
-
|
493
|
-
// No marquee should be changed without clicking on their "save" button.
|
494
|
-
// The second marquee shouldn't be stored as a widget.
|
495
|
-
// See #32978 for more info.
|
496
|
-
await saveWidgets();
|
497
|
-
editedSerializedWidgetAreas = await getSerializedWidgetAreas();
|
498
|
-
await expect( editedSerializedWidgetAreas ).toMatchInlineSnapshot( `
|
499
|
-
{
|
500
|
-
"sidebar-1": "<marquee>Howdy</marquee>",
|
501
|
-
}
|
502
|
-
` );
|
503
|
-
|
504
|
-
await page.reload();
|
505
|
-
const marqueesAfter = await findAll( {
|
506
|
-
selector: '[data-testid="marquee-greeting"]',
|
507
|
-
} );
|
508
|
-
expect( marqueesAfter ).toHaveLength( 1 );
|
509
|
-
} );
|
510
|
-
} );
|
511
|
-
|
512
|
-
it.skip( 'Should duplicate the widgets', async () => {
|
513
|
-
let [ firstWidgetArea ] = await findAll( {
|
514
|
-
role: 'document',
|
515
|
-
name: 'Block: Widget Area',
|
516
|
-
} );
|
517
|
-
|
518
|
-
const addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
519
|
-
await addParagraphBlock.click();
|
520
|
-
|
521
|
-
let firstParagraphBlock = await find(
|
522
|
-
{
|
523
|
-
role: 'document',
|
524
|
-
name: /^Empty block/,
|
525
|
-
},
|
526
|
-
{ root: firstWidgetArea }
|
527
|
-
);
|
528
|
-
await firstParagraphBlock.focus();
|
529
|
-
await page.keyboard.type( 'First Paragraph' );
|
530
|
-
|
531
|
-
await saveWidgets();
|
532
|
-
await page.reload();
|
533
|
-
// Wait for the widget areas to load.
|
534
|
-
[ firstWidgetArea ] = await findAll( {
|
535
|
-
role: 'document',
|
536
|
-
name: 'Block: Widget Area',
|
537
|
-
} );
|
538
|
-
|
539
|
-
const initialSerializedWidgetAreas = await getSerializedWidgetAreas();
|
540
|
-
expect( initialSerializedWidgetAreas ).toMatchInlineSnapshot( `
|
541
|
-
Object {
|
542
|
-
"sidebar-1": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
543
|
-
<p>First Paragraph</p>
|
544
|
-
</div></div>",
|
545
|
-
}
|
546
|
-
` );
|
547
|
-
|
548
|
-
firstParagraphBlock = await firstWidgetArea.$(
|
549
|
-
'[data-block][data-type="core/paragraph"]'
|
550
|
-
);
|
551
|
-
await firstParagraphBlock.focus();
|
552
|
-
|
553
|
-
await showBlockToolbar();
|
554
|
-
await clickBlockToolbarButton( 'Options' );
|
555
|
-
const duplicateButton = await find( {
|
556
|
-
role: 'menuitem',
|
557
|
-
name: /^Duplicate/,
|
558
|
-
} );
|
559
|
-
await duplicateButton.click();
|
560
|
-
|
561
|
-
await page.waitForFunction(
|
562
|
-
( paragraph ) =>
|
563
|
-
paragraph.nextSibling &&
|
564
|
-
paragraph.nextSibling.matches( '[data-block]' ),
|
565
|
-
{},
|
566
|
-
firstParagraphBlock
|
567
|
-
);
|
568
|
-
const duplicatedParagraphBlock =
|
569
|
-
await firstParagraphBlock.evaluateHandle(
|
570
|
-
( paragraph ) => paragraph.nextSibling
|
571
|
-
);
|
572
|
-
|
573
|
-
const firstParagraphBlockClientId = await firstParagraphBlock.evaluate(
|
574
|
-
( node ) => node.dataset.block
|
575
|
-
);
|
576
|
-
const duplicatedParagraphBlockClientId =
|
577
|
-
await duplicatedParagraphBlock.evaluate(
|
578
|
-
( node ) => node.dataset.block
|
579
|
-
);
|
580
|
-
|
581
|
-
expect( firstParagraphBlockClientId ).not.toBe(
|
582
|
-
duplicatedParagraphBlockClientId
|
583
|
-
);
|
584
|
-
await expect( duplicatedParagraphBlock ).toMatchQuery( {
|
585
|
-
text: 'First Paragraph',
|
586
|
-
} );
|
587
|
-
await expect( duplicatedParagraphBlock ).toHaveFocus();
|
588
|
-
|
589
|
-
await saveWidgets();
|
590
|
-
const editedSerializedWidgetAreas = await getSerializedWidgetAreas();
|
591
|
-
expect( editedSerializedWidgetAreas ).toMatchInlineSnapshot( `
|
592
|
-
Object {
|
593
|
-
"sidebar-1": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
594
|
-
<p>First Paragraph</p>
|
595
|
-
</div></div>
|
596
|
-
<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
597
|
-
<p>First Paragraph</p>
|
598
|
-
</div></div>",
|
599
|
-
}
|
600
|
-
` );
|
601
|
-
expect( editedSerializedWidgetAreas[ 'sidebar-1' ] ).toBe(
|
602
|
-
[
|
603
|
-
initialSerializedWidgetAreas[ 'sidebar-1' ],
|
604
|
-
initialSerializedWidgetAreas[ 'sidebar-1' ],
|
605
|
-
].join( '\n' )
|
606
|
-
);
|
607
|
-
} );
|
608
|
-
|
609
|
-
it.skip( 'Should display legacy widgets', async () => {
|
610
|
-
// Get the default empty instance of a legacy search widget.
|
611
|
-
const { instance: defaultSearchInstance } = await rest( {
|
612
|
-
method: 'POST',
|
613
|
-
path: '/wp/v2/widget-types/search/encode',
|
614
|
-
data: { instance: {} },
|
615
|
-
} );
|
616
|
-
|
617
|
-
// Create a search widget in the first sidebar using the default instance.
|
618
|
-
await rest( {
|
619
|
-
method: 'POST',
|
620
|
-
path: '/wp/v2/widgets',
|
621
|
-
data: {
|
622
|
-
id_base: 'search',
|
623
|
-
sidebar: 'sidebar-1',
|
624
|
-
instance: defaultSearchInstance,
|
625
|
-
},
|
626
|
-
} );
|
627
|
-
|
628
|
-
await page.reload();
|
629
|
-
|
630
|
-
// Wait for the Legacy Widget block's preview iframe to load.
|
631
|
-
const frame = await new Promise( ( resolve ) => {
|
632
|
-
const checkFrame = async () => {
|
633
|
-
const frameElement = await page.$(
|
634
|
-
'iframe.wp-block-legacy-widget__edit-preview-iframe'
|
635
|
-
);
|
636
|
-
if ( frameElement ) {
|
637
|
-
page.off( 'frameattached', checkFrame );
|
638
|
-
page.off( 'framenavigated', checkFrame );
|
639
|
-
resolve( frameElement.contentFrame() );
|
640
|
-
}
|
641
|
-
};
|
642
|
-
page.on( 'frameattached', checkFrame );
|
643
|
-
page.on( 'framenavigated', checkFrame );
|
644
|
-
} );
|
645
|
-
|
646
|
-
// Expect to have search input.
|
647
|
-
await find(
|
648
|
-
{
|
649
|
-
role: 'searchbox',
|
650
|
-
},
|
651
|
-
{
|
652
|
-
page: frame,
|
653
|
-
}
|
654
|
-
);
|
655
|
-
|
656
|
-
// Focus the Legacy Widget block.
|
657
|
-
const legacyWidget = await find( {
|
658
|
-
role: 'document',
|
659
|
-
name: 'Block: Legacy Widget',
|
660
|
-
} );
|
661
|
-
await legacyWidget.focus();
|
662
|
-
|
663
|
-
// There should be a title at the top of the widget form.
|
664
|
-
const legacyWidgetName = await find(
|
665
|
-
{
|
666
|
-
role: 'heading',
|
667
|
-
level: 3,
|
668
|
-
},
|
669
|
-
{
|
670
|
-
root: legacyWidget,
|
671
|
-
}
|
672
|
-
);
|
673
|
-
expect( legacyWidgetName ).toMatchQuery( { text: 'Search' } );
|
674
|
-
|
675
|
-
// Update the widget form.
|
676
|
-
// TODO: Convert to find() API from puppeteer-testing-library.
|
677
|
-
const titleInput = await page.waitForSelector(
|
678
|
-
`#widget-search-1-title`
|
679
|
-
);
|
680
|
-
await titleInput.type( 'Search Title' );
|
681
|
-
|
682
|
-
// Switch to Navigation mode.
|
683
|
-
await page.keyboard.press( 'Escape' );
|
684
|
-
|
685
|
-
// Wait for the preview to update.
|
686
|
-
await frame.waitForNavigation();
|
687
|
-
|
688
|
-
// Expect to have search title.
|
689
|
-
await find(
|
690
|
-
{
|
691
|
-
role: 'heading',
|
692
|
-
name: 'Search Title',
|
693
|
-
},
|
694
|
-
{
|
695
|
-
page: frame,
|
696
|
-
}
|
697
|
-
);
|
698
|
-
|
699
|
-
await saveWidgets();
|
700
|
-
const serializedWidgetAreas = await getSerializedWidgetAreas();
|
701
|
-
expect( serializedWidgetAreas ).toMatchInlineSnapshot( `
|
702
|
-
Object {
|
703
|
-
"sidebar-1": "<div class=\\"widget widget_search\\"><div class=\\"widget-content\\"><h2 class=\\"widget-title subheading heading-size-3\\">Search Title</h2><form role=\\"search\\" method=\\"get\\" class=\\"search-form\\" action=\\"http://localhost:8889/\\">
|
704
|
-
<label for=\\"search-form-1\\">
|
705
|
-
<span class=\\"screen-reader-text\\">Search for:</span>
|
706
|
-
<input type=\\"search\\" id=\\"search-form-1\\" class=\\"search-field\\" placeholder=\\"Search …\\" value=\\"\\" name=\\"s\\" />
|
707
|
-
</label>
|
708
|
-
<input type=\\"submit\\" class=\\"search-submit\\" value=\\"Search\\" />
|
709
|
-
</form>
|
710
|
-
</div></div>",
|
711
|
-
}
|
712
|
-
` );
|
713
|
-
} );
|
714
|
-
|
715
|
-
it.skip( 'allows widgets to be moved between widget areas using the dropdown in the block toolbar', async () => {
|
716
|
-
const widgetAreas = await findAll( {
|
717
|
-
role: 'document',
|
718
|
-
name: 'Block: Widget Area',
|
719
|
-
} );
|
720
|
-
const [ firstWidgetArea, secondWidgetArea ] = widgetAreas;
|
721
|
-
|
722
|
-
// Insert a paragraph it should be in the first widget area.
|
723
|
-
const inserterParagraphBlock =
|
724
|
-
await getBlockInGlobalInserter( 'Paragraph' );
|
725
|
-
await inserterParagraphBlock.hover();
|
726
|
-
await inserterParagraphBlock.click();
|
727
|
-
const addedParagraphBlockInFirstWidgetArea = await find(
|
728
|
-
{
|
729
|
-
role: 'document',
|
730
|
-
name: /^Empty block/,
|
731
|
-
},
|
732
|
-
{ root: firstWidgetArea }
|
733
|
-
);
|
734
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
735
|
-
await page.keyboard.type( 'First Paragraph' );
|
736
|
-
|
737
|
-
// Check that the block exists in the first widget area.
|
738
|
-
await find(
|
739
|
-
{
|
740
|
-
role: 'document',
|
741
|
-
name: 'Block: Paragraph',
|
742
|
-
value: 'First Paragraph',
|
743
|
-
},
|
744
|
-
{
|
745
|
-
root: firstWidgetArea,
|
746
|
-
}
|
747
|
-
);
|
748
|
-
|
749
|
-
// Move the block to the second widget area.
|
750
|
-
await showBlockToolbar();
|
751
|
-
await clickBlockToolbarButton( 'Move to widget area' );
|
752
|
-
const widgetAreaButton = await find( {
|
753
|
-
role: 'menuitemradio',
|
754
|
-
name: /^Footer #2/,
|
755
|
-
} );
|
756
|
-
await widgetAreaButton.click();
|
757
|
-
|
758
|
-
// Check that the block exists in the second widget area.
|
759
|
-
await find(
|
760
|
-
{
|
761
|
-
role: 'document',
|
762
|
-
name: 'Block: Paragraph',
|
763
|
-
value: 'First Paragraph',
|
764
|
-
},
|
765
|
-
{
|
766
|
-
root: secondWidgetArea,
|
767
|
-
}
|
768
|
-
);
|
769
|
-
|
770
|
-
// Assert that the serialized widget areas shows the block as in the second widget area.
|
771
|
-
await saveWidgets();
|
772
|
-
const serializedWidgetAreas2 = await getSerializedWidgetAreas();
|
773
|
-
expect( serializedWidgetAreas2 ).toMatchInlineSnapshot( `
|
774
|
-
Object {
|
775
|
-
"sidebar-2": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
|
776
|
-
<p>First Paragraph</p>
|
777
|
-
</div></div>",
|
778
|
-
}
|
779
|
-
` );
|
780
|
-
} );
|
781
|
-
|
782
|
-
it( 'Allows widget deletion to be undone', async () => {
|
783
|
-
const [ firstWidgetArea ] = await findAll( {
|
784
|
-
role: 'document',
|
785
|
-
name: 'Block: Widget Area',
|
786
|
-
} );
|
787
|
-
|
788
|
-
let addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
789
|
-
await addParagraphBlock.click();
|
790
|
-
|
791
|
-
let addedParagraphBlockInFirstWidgetArea = await find(
|
792
|
-
{
|
793
|
-
name: /^Empty block/,
|
794
|
-
selector: '[data-block][data-type="core/paragraph"]',
|
795
|
-
},
|
796
|
-
{
|
797
|
-
root: firstWidgetArea,
|
798
|
-
}
|
799
|
-
);
|
800
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
801
|
-
await page.keyboard.type( 'First Paragraph' );
|
802
|
-
|
803
|
-
addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
804
|
-
await addParagraphBlock.click();
|
805
|
-
|
806
|
-
addedParagraphBlockInFirstWidgetArea = await firstWidgetArea.$(
|
807
|
-
'[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
|
808
|
-
);
|
809
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
810
|
-
await page.keyboard.type( 'Second Paragraph' );
|
811
|
-
|
812
|
-
await saveWidgets();
|
813
|
-
await page.focus( '.block-editor-writing-flow' );
|
814
|
-
|
815
|
-
// Delete the last block and save again.
|
816
|
-
await pressKeyWithModifier( 'access', 'z' );
|
817
|
-
await saveWidgets();
|
818
|
-
// To do: clicking on the Snackbar causes focus loss.
|
819
|
-
await page.focus( '.block-editor-writing-flow' );
|
820
|
-
|
821
|
-
// Undo block deletion and save again.
|
822
|
-
await pressKeyWithModifier( 'primary', 'z' );
|
823
|
-
await saveWidgets();
|
824
|
-
|
825
|
-
// Reload the page to make sure changes were actually saved.
|
826
|
-
await page.reload();
|
827
|
-
|
828
|
-
const serializedWidgetAreas = await getSerializedWidgetAreas();
|
829
|
-
expect( serializedWidgetAreas ).toMatchInlineSnapshot( `
|
830
|
-
{
|
831
|
-
"sidebar-1": "<div class="widget widget_block widget_text"><div class="widget-content">
|
832
|
-
<p>First Paragraph</p>
|
833
|
-
</div></div>
|
834
|
-
<div class="widget widget_block widget_text"><div class="widget-content">
|
835
|
-
<p>Second Paragraph</p>
|
836
|
-
</div></div>",
|
837
|
-
}
|
838
|
-
` );
|
839
|
-
} );
|
840
|
-
|
841
|
-
it( 'can toggle sidebar list view', async () => {
|
842
|
-
const widgetAreas = await findAll( {
|
843
|
-
role: 'document',
|
844
|
-
name: 'Block: Widget Area',
|
845
|
-
} );
|
846
|
-
await openListView();
|
847
|
-
const listItems = await page.$$(
|
848
|
-
'.edit-widgets-editor__list-view-panel .block-editor-list-view-leaf'
|
849
|
-
);
|
850
|
-
expect( listItems.length >= widgetAreas.length ).toEqual( true );
|
851
|
-
await closeListView();
|
852
|
-
} );
|
853
|
-
|
854
|
-
// Check for regressions of https://github.com/WordPress/gutenberg/issues/38002.
|
855
|
-
it( 'allows blocks to be added on mobile viewports', async () => {
|
856
|
-
await setBrowserViewport( 'small' );
|
857
|
-
const [ firstWidgetArea ] = await findAll( {
|
858
|
-
role: 'document',
|
859
|
-
name: 'Block: Widget Area',
|
860
|
-
} );
|
861
|
-
|
862
|
-
const addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' );
|
863
|
-
await addParagraphBlock.click();
|
864
|
-
|
865
|
-
const addedParagraphBlockInFirstWidgetArea = await find(
|
866
|
-
{
|
867
|
-
name: /^Empty block/,
|
868
|
-
selector: '[data-block][data-type="core/paragraph"]',
|
869
|
-
},
|
870
|
-
{
|
871
|
-
root: firstWidgetArea,
|
872
|
-
}
|
873
|
-
);
|
874
|
-
await addedParagraphBlockInFirstWidgetArea.focus();
|
875
|
-
await page.keyboard.type( 'First Paragraph' );
|
876
|
-
const updatedParagraphBlockInFirstWidgetArea = await find(
|
877
|
-
{
|
878
|
-
name: 'Block: Paragraph',
|
879
|
-
value: 'First Paragraph',
|
880
|
-
},
|
881
|
-
{
|
882
|
-
root: firstWidgetArea,
|
883
|
-
}
|
884
|
-
);
|
885
|
-
|
886
|
-
expect( updatedParagraphBlockInFirstWidgetArea ).toBeTruthy();
|
887
|
-
} );
|
888
|
-
} );
|
889
|
-
|
890
|
-
/**
|
891
|
-
* Visit the widgets screen via link clicking. The widgets screen currently
|
892
|
-
* has different URLs during the integration to core.
|
893
|
-
* We should be able to refactor it once it's fully merged into core.
|
894
|
-
*/
|
895
|
-
async function visitWidgetsScreen() {
|
896
|
-
// Visit the Appearance page.
|
897
|
-
await visitAdminPage( 'themes.php' );
|
898
|
-
|
899
|
-
// Go to the Widgets page.
|
900
|
-
const appearanceMenu = await page.$( '#menu-appearance' );
|
901
|
-
await appearanceMenu.hover();
|
902
|
-
const widgetsLink = await find(
|
903
|
-
{ role: 'link', name: 'Widgets' },
|
904
|
-
{ root: appearanceMenu }
|
905
|
-
);
|
906
|
-
await Promise.all( [
|
907
|
-
page.waitForNavigation(),
|
908
|
-
// Click on the link no matter if it's visible or not.
|
909
|
-
widgetsLink.evaluate( ( link ) => {
|
910
|
-
link.click();
|
911
|
-
} ),
|
912
|
-
] );
|
913
|
-
}
|
914
|
-
|
915
|
-
async function saveWidgets() {
|
916
|
-
await closeListView();
|
917
|
-
await closeGlobalBlockInserter();
|
918
|
-
const updateButton = await find( {
|
919
|
-
role: 'button',
|
920
|
-
name: 'Update',
|
921
|
-
} );
|
922
|
-
await updateButton.click();
|
923
|
-
|
924
|
-
// Expect the "Widgets saved." snackbar to appear.
|
925
|
-
const savedSnackbarQuery = {
|
926
|
-
role: 'button',
|
927
|
-
name: 'Dismiss this notice',
|
928
|
-
text: 'Widgets saved.',
|
929
|
-
};
|
930
|
-
await expect( savedSnackbarQuery ).toBeFound();
|
931
|
-
|
932
|
-
// Close the snackbar.
|
933
|
-
const savedSnackbar = await find( savedSnackbarQuery );
|
934
|
-
await savedSnackbar.click();
|
935
|
-
// Expect focus not to be lost.
|
936
|
-
await expect(
|
937
|
-
await page.evaluate( () => document.activeElement.className )
|
938
|
-
).toBe( 'components-snackbar-list edit-widgets-notices__snackbar' );
|
939
|
-
await expect( savedSnackbarQuery ).not.toBeFound();
|
940
|
-
}
|
941
|
-
|
942
|
-
async function getSerializedWidgetAreas() {
|
943
|
-
const widgets = await rest( { path: '/wp/v2/widgets' } );
|
944
|
-
|
945
|
-
const serializedWidgetAreas = widgets.reduce(
|
946
|
-
( acc, { sidebar, rendered } ) => {
|
947
|
-
const currentWidgets = acc[ sidebar ] || '';
|
948
|
-
let newWidgets = Boolean( rendered ) ? rendered : '';
|
949
|
-
if ( currentWidgets.length && newWidgets.length ) {
|
950
|
-
newWidgets = '\n' + newWidgets;
|
951
|
-
}
|
952
|
-
|
953
|
-
return {
|
954
|
-
...acc,
|
955
|
-
[ sidebar ]: currentWidgets + newWidgets,
|
956
|
-
};
|
957
|
-
},
|
958
|
-
{}
|
959
|
-
);
|
960
|
-
|
961
|
-
return serializedWidgetAreas;
|
962
|
-
}
|