@wordpress/e2e-tests 2.5.12 → 3.0.1-next.33ec3857e2.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/config/flaky-tests-reporter.js +2 -1
  3. package/package.json +10 -9
  4. package/specs/editor/blocks/__snapshots__/heading.test.js.snap +2 -2
  5. package/specs/editor/blocks/__snapshots__/navigation.test.js.snap +27 -59
  6. package/specs/editor/blocks/columns.test.js +1 -1
  7. package/specs/editor/blocks/cover.test.js +1 -1
  8. package/specs/editor/blocks/heading.test.js +15 -3
  9. package/specs/editor/blocks/image.test.js +1 -2
  10. package/specs/editor/blocks/navigation.test.js +264 -370
  11. package/specs/editor/blocks/preformatted.test.js +2 -1
  12. package/specs/editor/blocks/site-title.test.js +2 -31
  13. package/specs/editor/fixtures/menu-items-request-fixture.json +84 -0
  14. package/specs/editor/fixtures/menu-items-response-fixture.json +240 -144
  15. package/specs/editor/plugins/custom-post-types.test.js +4 -3
  16. package/specs/editor/various/adding-patterns.test.js +1 -1
  17. package/specs/editor/various/block-grouping.test.js +2 -18
  18. package/specs/editor/various/block-hierarchy-navigation.test.js +3 -3
  19. package/specs/editor/various/change-detection.test.js +5 -0
  20. package/specs/editor/various/editor-modes.test.js +7 -0
  21. package/specs/editor/various/font-size-picker.test.js +1 -7
  22. package/specs/editor/various/inserting-blocks.test.js +6 -2
  23. package/specs/editor/various/keyboard-navigable-blocks.test.js +6 -0
  24. package/specs/editor/various/list-view.test.js +2 -2
  25. package/specs/editor/various/navigable-toolbar.test.js +2 -2
  26. package/specs/editor/various/preview.test.js +1 -1
  27. package/specs/editor/various/reusable-blocks.test.js +1 -26
  28. package/specs/editor/various/writing-flow.test.js +8 -4
  29. package/specs/site-editor/document-settings.test.js +1 -1
  30. package/specs/site-editor/multi-entity-saving.test.js +108 -55
  31. package/specs/site-editor/template-part.test.js +88 -68
  32. package/specs/widgets/customizing-widgets.test.js +4 -0
@@ -4,7 +4,8 @@
4
4
  import {
5
5
  createJSONResponse,
6
6
  createNewPost,
7
- getEditedPostContent,
7
+ createMenu as createClassicMenu,
8
+ deleteAllMenus as deleteAllClassicMenus,
8
9
  insertBlock,
9
10
  setUpResponseMocking,
10
11
  pressKeyWithModifier,
@@ -13,74 +14,19 @@ import {
13
14
  openPreviewPage,
14
15
  selectBlockByClientId,
15
16
  getAllBlocks,
17
+ ensureSidebarOpened,
18
+ __experimentalRest as rest,
19
+ publishPost,
16
20
  } from '@wordpress/e2e-test-utils';
17
21
 
18
22
  /**
19
23
  * Internal dependencies
20
24
  */
21
- import menuItemsFixture from '../fixtures/menu-items-response-fixture.json';
22
-
23
- const menusFixture = [
24
- {
25
- name: 'Test Menu 1',
26
- slug: 'test-menu-1',
27
- },
28
- {
29
- name: 'Test Menu 2',
30
- slug: 'test-menu-2',
31
- },
32
- {
33
- name: 'Test Menu 3',
34
- slug: 'test-menu-3',
35
- },
36
- ];
37
-
38
- // Matching against variations of the same URL encoded and non-encoded
39
- // produces the most reliable mocking.
40
- const REST_MENUS_ROUTES = [
41
- '/wp/v2/menus',
42
- `rest_route=${ encodeURIComponent( '/wp/v2/menus' ) }`,
43
- ];
44
- const REST_MENU_ITEMS_ROUTES = [
45
- '/wp/v2/menu-items',
46
- `rest_route=${ encodeURIComponent( '/wp/v2/menu-items' ) }`,
47
- ];
48
-
49
- const REST_PAGES_ROUTES = [
50
- '/wp/v2/pages',
51
- `rest_route=${ encodeURIComponent( '/wp/v2/pages' ) }`,
52
- ];
25
+ import menuItemsFixture from '../fixtures/menu-items-request-fixture.json';
53
26
 
54
- /**
55
- * Determines if a given URL matches any of a given collection of
56
- * routes (extressed as substrings).
57
- *
58
- * @param {string} reqUrl the full URL to be tested for matches.
59
- * @param {Array} routes array of strings to match against the URL.
60
- */
61
- function matchUrlToRoute( reqUrl, routes ) {
62
- return routes.some( ( route ) => reqUrl.includes( route ) );
63
- }
64
-
65
- async function mockPagesResponse( pages ) {
66
- const mappedPages = pages.map( ( { title, slug }, index ) => ( {
67
- id: index + 1,
68
- type: 'page',
69
- link: `https://this/is/a/test/page/${ slug }`,
70
- title: {
71
- rendered: title,
72
- raw: title,
73
- },
74
- } ) );
75
-
76
- await setUpResponseMocking( [
77
- {
78
- match: ( request ) =>
79
- matchUrlToRoute( request.url(), REST_PAGES_ROUTES ),
80
- onRequestMatch: createJSONResponse( mappedPages ),
81
- },
82
- ] );
83
- }
27
+ const POSTS_ENDPOINT = '/wp/v2/posts';
28
+ const PAGES_ENDPOINT = '/wp/v2/pages';
29
+ const NAVIGATION_MENUS_ENDPOINT = '/wp/v2/navigation';
84
30
 
85
31
  async function mockSearchResponse( items ) {
86
32
  const mappedItems = items.map( ( { title, slug }, index ) => ( {
@@ -101,76 +47,6 @@ async function mockSearchResponse( items ) {
101
47
  ] );
102
48
  }
103
49
 
104
- /**
105
- * Creates mocked REST API responses for calls to menus and menu-items
106
- * endpoints.
107
- * Note: this needs to be within a single call to
108
- * `setUpResponseMocking` as you can only setup response mocking once per test run.
109
- *
110
- * @param {Array} menus menus to provide as mocked responses to menus entity API requests.
111
- * @param {Array} menuItems menu items to provide as mocked responses to menu-items entity API requests.
112
- */
113
- async function mockAllMenusResponses(
114
- menus = menusFixture,
115
- menuItems = menuItemsFixture
116
- ) {
117
- const mappedMenus = menus.length
118
- ? menus.map( ( menu, index ) => ( {
119
- ...menu,
120
- id: index + 1,
121
- } ) )
122
- : [];
123
-
124
- await setUpResponseMocking( [
125
- {
126
- match: ( request ) =>
127
- matchUrlToRoute( request.url(), REST_MENUS_ROUTES ),
128
- onRequestMatch: createJSONResponse( mappedMenus ),
129
- },
130
- {
131
- match: ( request ) =>
132
- matchUrlToRoute( request.url(), REST_MENU_ITEMS_ROUTES ),
133
- onRequestMatch: createJSONResponse( menuItems ),
134
- },
135
- ] );
136
- }
137
-
138
- async function mockEmptyMenusAndPagesResponses() {
139
- const emptyResponse = [];
140
- await setUpResponseMocking( [
141
- {
142
- match: ( request ) =>
143
- matchUrlToRoute( request.url(), REST_MENUS_ROUTES ),
144
- onRequestMatch: createJSONResponse( emptyResponse ),
145
- },
146
- {
147
- match: ( request ) =>
148
- matchUrlToRoute( request.url(), REST_PAGES_ROUTES ),
149
- onRequestMatch: createJSONResponse( emptyResponse ),
150
- },
151
- ] );
152
- }
153
-
154
- async function mockCreatePageResponse( title, slug ) {
155
- const page = {
156
- id: 1,
157
- title: { raw: title, rendered: title },
158
- type: 'page',
159
- link: `https://this/is/a/test/create/page/${ slug }`,
160
- slug,
161
- };
162
-
163
- await setUpResponseMocking( [
164
- {
165
- match: ( request ) =>
166
- request.url().includes( `rest_route` ) &&
167
- request.url().includes( `pages` ) &&
168
- request.method() === 'POST',
169
- onRequestMatch: createJSONResponse( page ),
170
- },
171
- ] );
172
- }
173
-
174
50
  /**
175
51
  * Interacts with the LinkControl to perform a search and select a returned suggestion
176
52
  *
@@ -220,7 +96,7 @@ async function updateActiveNavigationLink( { url, label, type } ) {
220
96
  }
221
97
  }
222
98
 
223
- async function selectDropDownOption( optionText ) {
99
+ async function selectClassicMenu( optionText ) {
224
100
  const dropdown = await page.waitForXPath(
225
101
  "//*[contains(@class, 'wp-block-navigation-placeholder__actions__dropdown')]"
226
102
  );
@@ -236,27 +112,11 @@ const PLACEHOLDER_ACTIONS_XPATH = `//*[contains(@class, '${ PLACEHOLDER_ACTIONS_
236
112
  const START_EMPTY_XPATH = `${ PLACEHOLDER_ACTIONS_XPATH }//button[text()='Start empty']`;
237
113
  const ADD_ALL_PAGES_XPATH = `${ PLACEHOLDER_ACTIONS_XPATH }//button[text()='Add all pages']`;
238
114
 
239
- async function createNavBlockWithAllPages() {
240
- const allPagesButton = await page.waitForXPath( ADD_ALL_PAGES_XPATH );
241
- await allPagesButton.click();
242
- }
243
-
244
- async function createEmptyNavBlock() {
245
- const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH );
246
- await startEmptyButton.click();
247
- }
248
-
249
- async function toggleSidebar() {
250
- await page.click(
251
- '.edit-post-header__settings button[aria-label="Settings"]'
252
- );
253
- }
254
-
255
115
  async function turnResponsivenessOn() {
256
116
  const blocks = await getAllBlocks();
257
117
 
258
118
  await selectBlockByClientId( blocks[ 0 ].clientId );
259
- await toggleSidebar();
119
+ await ensureSidebarOpened();
260
120
 
261
121
  const [ responsivenessToggleButton ] = await page.$x(
262
122
  '//label[text()[contains(.,"Enable responsive menu")]]'
@@ -267,123 +127,169 @@ async function turnResponsivenessOn() {
267
127
  await saveDraft();
268
128
  }
269
129
 
270
- beforeEach( async () => {
271
- await createNewPost();
272
- } );
130
+ /**
131
+ * Delete all items for the given REST resources using the REST API.
132
+ *
133
+ * @param {*} endpoints The endpoints of the resources to delete.
134
+ */
135
+ async function deleteAll( endpoints ) {
136
+ for ( const path of endpoints ) {
137
+ const items = await rest( { path } );
138
+
139
+ for ( const item of items ) {
140
+ await rest( {
141
+ method: 'DELETE',
142
+ path: `${ path }/${ item.id }?force=true`,
143
+ } );
144
+ }
145
+ }
146
+ }
273
147
 
274
- afterEach( async () => {
275
- await setUpResponseMocking( [] );
276
- } );
148
+ /**
149
+ * Create a set of pages using the REST API.
150
+ *
151
+ * @param {Array} pages An array of page objects.
152
+ */
153
+ async function createPages( pages ) {
154
+ for ( const page of pages ) {
155
+ await rest( {
156
+ method: 'POST',
157
+ path: PAGES_ENDPOINT,
158
+ data: {
159
+ status: 'publish',
160
+ ...page,
161
+ },
162
+ } );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Replace unique ids in nav block content, since these won't be consistent
168
+ * between test runs.
169
+ *
170
+ * @param {string} content HTML block content, either raw or rendered.
171
+ *
172
+ * @return {string} HTML block content with stripped ids
173
+ */
174
+ function stripPageIds( content ) {
175
+ return content
176
+ .replace( /page_id=\d+/gm, 'page_id=[number]' )
177
+ .replace( /"id":\d+/gm, '"id":[number]' );
178
+ }
179
+
180
+ /**
181
+ * Check navigation block content by fetching the navigation menu.
182
+ *
183
+ * @return {string} Menu content.
184
+ */
185
+ async function getNavigationMenuRawContent() {
186
+ const menuRef = await page.evaluate( () => {
187
+ const blocks = wp.data.select( 'core/block-editor' ).getBlocks();
188
+ const navigationBlock = blocks.find(
189
+ ( block ) => block.name === 'core/navigation'
190
+ );
191
+
192
+ return navigationBlock.attributes.ref;
193
+ } );
194
+
195
+ const response = await rest( {
196
+ method: 'GET',
197
+ path: `/wp/v2/navigation/${ menuRef }?context=edit`,
198
+ } );
199
+
200
+ return stripPageIds( response.content.raw );
201
+ }
277
202
 
278
203
  // Disable reason - these tests are to be re-written.
279
204
  // eslint-disable-next-line jest/no-disabled-tests
280
- describe.skip( 'Navigation', () => {
281
- describe( 'Creating from existing Pages', () => {
205
+ describe( 'Navigation', () => {
206
+ beforeEach( async () => {
207
+ await deleteAll( [
208
+ POSTS_ENDPOINT,
209
+ PAGES_ENDPOINT,
210
+ NAVIGATION_MENUS_ENDPOINT,
211
+ ] );
212
+ await deleteAllClassicMenus();
213
+ } );
214
+
215
+ afterEach( async () => {
216
+ await setUpResponseMocking( [] );
217
+ } );
218
+
219
+ afterAll( async () => {
220
+ await deleteAll( [
221
+ POSTS_ENDPOINT,
222
+ PAGES_ENDPOINT,
223
+ NAVIGATION_MENUS_ENDPOINT,
224
+ ] );
225
+ await deleteAllClassicMenus();
226
+ } );
227
+
228
+ describe( 'placeholder', () => {
282
229
  it( 'allows a navigation block to be created using existing pages', async () => {
283
- // Mock the response from the Pages endpoint. This is done so that the pages returned are always
284
- // consistent and to test the feature more rigorously than the single default sample page.
285
- await mockPagesResponse( [
286
- {
287
- title: 'Home',
288
- slug: 'home',
289
- },
230
+ await createPages( [
290
231
  {
291
232
  title: 'About',
292
- slug: 'about',
233
+ menu_order: 0,
293
234
  },
294
235
  {
295
236
  title: 'Contact Us',
296
- slug: 'contact',
237
+ menu_order: 1,
238
+ },
239
+ {
240
+ title: 'FAQ',
241
+ menu_order: 2,
297
242
  },
298
243
  ] );
299
244
 
300
- // Add the navigation block.
301
- await insertBlock( 'Navigation' );
302
-
303
- await createNavBlockWithAllPages();
304
-
305
- // Snapshot should contain the mocked pages.
306
- expect( await getEditedPostContent() ).toMatchSnapshot();
307
- } );
308
-
309
- it( 'does not display option to create from existing Pages if there are no Pages', async () => {
310
- // Force no Pages or Menus to be returned by API responses.
311
- await mockEmptyMenusAndPagesResponses();
245
+ await createNewPost();
312
246
 
313
247
  // Add the navigation block.
314
248
  await insertBlock( 'Navigation' );
315
-
316
- await page.waitForXPath( START_EMPTY_XPATH );
317
-
318
- const placeholderActionsLength = await page.$$eval(
319
- `.${ PLACEHOLDER_ACTIONS_CLASS } button`,
320
- ( els ) => els.length
249
+ const allPagesButton = await page.waitForXPath(
250
+ ADD_ALL_PAGES_XPATH
321
251
  );
252
+ await allPagesButton.click();
322
253
 
323
- // Should only be showing "Start empty"
324
- expect( placeholderActionsLength ).toEqual( 1 );
254
+ // Wait for the page list block to be present
255
+ await page.waitForSelector( 'div[aria-label="Block: Page List"]' );
256
+
257
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
325
258
  } );
326
- } );
327
259
 
328
- describe( 'Creating from existing Menus', () => {
329
260
  it( 'allows a navigation block to be created from existing menus', async () => {
330
- await mockAllMenusResponses();
331
-
332
- // Add the navigation block.
333
- await insertBlock( 'Navigation' );
334
-
335
- await selectDropDownOption( 'Test Menu 2' );
336
-
337
- // Scope element selector to the Editor's "Content" region as otherwise it picks up on
338
- // block previews.
339
- const navLinkSelector =
340
- '[aria-label="Editor content"][role="region"] .wp-block-navigation-item';
341
-
342
- await page.waitForSelector( navLinkSelector );
343
-
344
- const navBlockItemsLength = await page.$$eval(
345
- navLinkSelector,
346
- ( els ) => els.length
261
+ await createClassicMenu( { name: 'Test Menu 1' } );
262
+ await createClassicMenu(
263
+ { name: 'Test Menu 2' },
264
+ menuItemsFixture
347
265
  );
348
266
 
349
- // Assert the correct number of Nav Link blocks were inserted.
350
- expect( navBlockItemsLength ).toEqual( menuItemsFixture.length );
267
+ await createNewPost();
268
+ await insertBlock( 'Navigation' );
269
+ await selectClassicMenu( 'Test Menu 2' );
351
270
 
352
- // Snapshot should contain the mocked menu items.
353
- expect( await getEditedPostContent() ).toMatchSnapshot();
271
+ // Wait for a navigation link block before making assertion.
272
+ await page.waitForSelector( '*[aria-label="Block: Custom Link"]' );
273
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
354
274
  } );
355
275
 
356
276
  it( 'creates an empty navigation block when the selected existing menu is also empty', async () => {
357
- // Force mock to return no Menus Items (empty menu)
358
- const emptyMenuItems = [];
359
- await mockAllMenusResponses( menusFixture, emptyMenuItems );
360
-
361
- // Add the navigation block.
277
+ await createClassicMenu( { name: 'Test Menu 1' } );
278
+ await createNewPost();
362
279
  await insertBlock( 'Navigation' );
280
+ await selectClassicMenu( 'Test Menu 1' );
363
281
 
364
- await selectDropDownOption( 'Test Menu 1' );
365
-
366
- // Scope element selector to the "Editor content" as otherwise it picks up on
367
- // Block Style live previews.
368
- const navBlockItemsLength = await page.$$eval(
369
- '[aria-label="Editor content"][role="region"] li[aria-label="Block: Link"]',
370
- ( els ) => els.length
282
+ // Wait for the appender so that we know the navigation menu was created.
283
+ await page.waitForSelector(
284
+ 'nav[aria-label="Block: Navigation"] button[aria-label="Add block"]'
371
285
  );
372
-
373
- // Assert an empty Nav Block is created.
374
- expect( navBlockItemsLength ).toEqual( 0 );
375
-
376
- // Snapshot should contain the mocked menu items.
377
- expect( await getEditedPostContent() ).toMatchSnapshot();
286
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
378
287
  } );
379
288
 
380
- it( 'does not display option to create from existing menus if there are no menus', async () => {
381
- // Force no Menus to be returned by API response.
382
- await mockEmptyMenusAndPagesResponses();
289
+ it( 'does not display the options to create from pages or menus if there are none', async () => {
290
+ await createNewPost();
383
291
 
384
- // Add the navigation block.
385
292
  await insertBlock( 'Navigation' );
386
-
387
293
  await page.waitForXPath( START_EMPTY_XPATH );
388
294
 
389
295
  const placeholderActionsLength = await page.$$eval(
@@ -391,21 +297,21 @@ describe.skip( 'Navigation', () => {
391
297
  ( els ) => els.length
392
298
  );
393
299
 
394
- // Should only be showing create empty menu.
300
+ // Should only be showing "Start empty".
395
301
  expect( placeholderActionsLength ).toEqual( 1 );
396
302
  } );
397
303
  } );
398
304
 
399
305
  it( 'allows an empty navigation block to be created and manually populated using a mixture of internal and external links', async () => {
400
- // Add the navigation block.
306
+ await createNewPost();
401
307
  await insertBlock( 'Navigation' );
308
+ const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH );
309
+ await startEmptyButton.click();
402
310
 
403
- // Create an empty nav block.
404
- await page.waitForSelector( '.wp-block-navigation-placeholder' );
405
-
406
- await createEmptyNavBlock();
407
-
408
- await page.click( '.wp-block-navigation .block-list-appender' );
311
+ const appender = await page.waitForSelector(
312
+ '.wp-block-navigation .block-list-appender'
313
+ );
314
+ await appender.click();
409
315
 
410
316
  // Add a link to the Link block.
411
317
  await updateActiveNavigationLink( {
@@ -414,9 +320,14 @@ describe.skip( 'Navigation', () => {
414
320
  type: 'url',
415
321
  } );
416
322
 
323
+ // Select the parent navigation block to show the appender.
417
324
  await showBlockToolbar();
325
+ await page.click( 'button[aria-label="Select Navigation"]' );
418
326
 
419
- await page.click( '.wp-block-navigation .block-list-appender' );
327
+ const appenderAgain = await page.waitForSelector(
328
+ '.wp-block-navigation .block-list-appender'
329
+ );
330
+ await appenderAgain.click();
420
331
 
421
332
  // After adding a new block, search input should be shown immediately.
422
333
  // Verify that Escape would close the popover.
@@ -436,7 +347,7 @@ describe.skip( 'Navigation', () => {
436
347
  expect( isInURLInput ).toBe( true );
437
348
  await page.keyboard.press( 'Escape' );
438
349
 
439
- //click the link placeholder
350
+ // Click the link placeholder.
440
351
  const placeholder = await page.waitForSelector(
441
352
  '.wp-block-navigation-link__placeholder'
442
353
  );
@@ -455,20 +366,22 @@ describe.skip( 'Navigation', () => {
455
366
  type: 'entity',
456
367
  } );
457
368
 
369
+ await publishPost();
370
+
458
371
  // Expect a Navigation Block with two Links in the snapshot.
459
- expect( await getEditedPostContent() ).toMatchSnapshot();
372
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
460
373
  } );
461
374
 
462
375
  it( 'encodes URL when create block if needed', async () => {
463
- // Add the navigation block.
376
+ await createNewPost();
464
377
  await insertBlock( 'Navigation' );
378
+ const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH );
379
+ await startEmptyButton.click();
465
380
 
466
- // Create an empty nav block.
467
- await page.waitForSelector( '.wp-block-navigation-placeholder' );
468
-
469
- await createEmptyNavBlock();
470
-
471
- await page.click( '.wp-block-navigation .block-list-appender' );
381
+ const appender = await page.waitForSelector(
382
+ '.wp-block-navigation .block-list-appender'
383
+ );
384
+ await appender.click();
472
385
 
473
386
  // Add a link to the Link block.
474
387
  await updateActiveNavigationLink( {
@@ -477,8 +390,12 @@ describe.skip( 'Navigation', () => {
477
390
  } );
478
391
 
479
392
  await showBlockToolbar();
393
+ await page.click( 'button[aria-label="Select Navigation"]' );
480
394
 
481
- await page.click( '.wp-block-navigation .block-list-appender' );
395
+ const appenderAgain = await page.waitForSelector(
396
+ '.wp-block-navigation .block-list-appender'
397
+ );
398
+ await appenderAgain.click();
482
399
 
483
400
  // Wait for URL input to be focused
484
401
  await page.waitForSelector(
@@ -514,47 +431,30 @@ describe.skip( 'Navigation', () => {
514
431
  type: 'entity',
515
432
  } );
516
433
 
434
+ await publishPost();
435
+
517
436
  // Expect a Navigation Block with two Links in the snapshot.
518
437
  // The 2nd link should not be double encoded.
519
- expect( await getEditedPostContent() ).toMatchSnapshot();
438
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
520
439
  } );
521
440
 
522
- it( 'allows pages to be created from the navigation block and their links added to menu', async () => {
523
- // Mock request for creating pages and the page search response.
524
- // We mock the page search to return no results and we use a very long
525
- // page name because if the search returns existing pages then the
526
- // "Create" suggestion might be below the scroll fold within the
527
- // `LinkControl` search suggestions UI. If this happens then it's not
528
- // possible to wait for the element to appear and the test will
529
- // erroneously fail.
530
- await mockSearchResponse( [] );
531
- await mockCreatePageResponse(
532
- 'A really long page name that will not exist',
533
- 'my-new-page'
534
- );
535
-
536
- // Add the navigation block.
441
+ // URL details endpoint is throwing a 404, which causes this test to fail.
442
+ it.skip( 'allows pages to be created from the navigation block and their links added to menu', async () => {
443
+ await createNewPost();
537
444
  await insertBlock( 'Navigation' );
445
+ const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH );
446
+ await startEmptyButton.click();
538
447
 
539
- // Create an empty nav block.
540
- await createEmptyNavBlock();
541
-
542
- await page.click( '.wp-block-navigation .block-list-appender' );
448
+ const appender = await page.waitForSelector(
449
+ '.wp-block-navigation .block-list-appender'
450
+ );
451
+ await appender.click();
543
452
 
544
453
  // Wait for URL input to be focused
545
454
  await page.waitForSelector(
546
455
  'input.block-editor-url-input__input:focus'
547
456
  );
548
457
 
549
- // After adding a new block, search input should be shown immediately.
550
- const isInURLInput = await page.evaluate(
551
- () =>
552
- !! document.activeElement.matches(
553
- 'input.block-editor-url-input__input'
554
- )
555
- );
556
- expect( isInURLInput ).toBe( true );
557
-
558
458
  // Insert name for the new page.
559
459
  await page.type(
560
460
  'input[placeholder="Search or type url"]',
@@ -583,23 +483,17 @@ describe.skip( 'Navigation', () => {
583
483
  await draftLink.click();
584
484
 
585
485
  // Expect a Navigation Block with a link for "A really long page name that will not exist".
586
- expect( await getEditedPostContent() ).toMatchSnapshot();
486
+ expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
587
487
  } );
588
488
 
589
- it( 'allows navigation submenus to open on click instead of hover', async () => {
590
- await mockAllMenusResponses();
591
-
592
- // Add the navigation block.
489
+ it( 'renders buttons for the submenu opener elements when the block is set to open on click instead of hover', async () => {
490
+ await createClassicMenu( { name: 'Test Menu 2' }, menuItemsFixture );
491
+ await createNewPost();
593
492
  await insertBlock( 'Navigation' );
493
+ await selectClassicMenu( 'Test Menu 2' );
594
494
 
595
- await selectDropDownOption( 'Test Menu 2' );
596
-
597
- // const blocks = await getAllBlocks();
598
- // await selectBlockByClientId( blocks[ 0 ].clientId );
599
-
600
- await toggleSidebar();
601
-
602
- const [ openOnClickButton ] = await page.$x(
495
+ await ensureSidebarOpened();
496
+ const openOnClickButton = await page.waitForXPath(
603
497
  '//label[contains(text(),"Open on click")]'
604
498
  );
605
499
 
@@ -634,16 +528,15 @@ describe.skip( 'Navigation', () => {
634
528
  } );
635
529
 
636
530
  it( 'Shows the quick inserter when the block contains non-navigation specific blocks', async () => {
637
- // Add the navigation block.
531
+ await createNewPost();
638
532
  await insertBlock( 'Navigation' );
533
+ const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH );
534
+ await startEmptyButton.click();
639
535
 
640
- // Create an empty nav block.
641
- await page.waitForSelector( '.wp-block-navigation-placeholder' );
642
-
643
- await createEmptyNavBlock();
644
-
645
- // Add a Link block first.
646
- await page.click( '.wp-block-navigation .block-list-appender' );
536
+ const appender = await page.waitForSelector(
537
+ '.wp-block-navigation .block-list-appender'
538
+ );
539
+ await appender.click();
647
540
 
648
541
  // Add a link to the Link block.
649
542
  await updateActiveNavigationLink( {
@@ -655,24 +548,20 @@ describe.skip( 'Navigation', () => {
655
548
  // Now add a different block type.
656
549
  await insertBlock( 'Site Title' );
657
550
 
658
- // Now try inserting another Link block via the quick inserter.
659
- await page.focus( '.wp-block-navigation .block-list-appender' );
660
-
661
- await page.click( '.wp-block-navigation .block-list-appender' );
662
-
663
- const linkButton = await page.waitForSelector(
664
- '.block-editor-inserter__quick-inserter .editor-block-list-item-navigation-link'
551
+ await showBlockToolbar();
552
+ await page.click( 'button[aria-label="Select Navigation"]' );
553
+ const appenderAgain = await page.waitForSelector(
554
+ '.wp-block-navigation .block-list-appender'
665
555
  );
666
- await linkButton.click();
556
+ await appenderAgain.click();
667
557
 
668
- await updateActiveNavigationLink( {
669
- url: 'https://wordpress.org/news/',
670
- label: 'WP News',
671
- type: 'url',
672
- } );
558
+ const quickInserter = await page.waitForSelector(
559
+ '.block-editor-inserter__quick-inserter'
560
+ );
673
561
 
674
- // Expect a Navigation block with two links and a Site Title.
675
- expect( await getEditedPostContent() ).toMatchSnapshot();
562
+ // Expect the quick inserter to be truthy, which it will be because we
563
+ // waited for it. It's nice to end a test with an assertion though.
564
+ expect( quickInserter ).toBeTruthy();
676
565
  } );
677
566
 
678
567
  // The following tests are unstable, roughly around when https://github.com/WordPress/wordpress-develop/pull/1412
@@ -680,20 +569,20 @@ describe.skip( 'Navigation', () => {
680
569
  it.skip( 'loads frontend code only if the block is present', async () => {
681
570
  // Mock the response from the Pages endpoint. This is done so that the pages returned are always
682
571
  // consistent and to test the feature more rigorously than the single default sample page.
683
- await mockPagesResponse( [
684
- {
685
- title: 'Home',
686
- slug: 'home',
687
- },
688
- {
689
- title: 'About',
690
- slug: 'about',
691
- },
692
- {
693
- title: 'Contact Us',
694
- slug: 'contact',
695
- },
696
- ] );
572
+ // await mockPagesResponse( [
573
+ // {
574
+ // title: 'Home',
575
+ // slug: 'home',
576
+ // },
577
+ // {
578
+ // title: 'About',
579
+ // slug: 'about',
580
+ // },
581
+ // {
582
+ // title: 'Contact Us',
583
+ // slug: 'contact',
584
+ // },
585
+ // ] );
697
586
 
698
587
  // Create first block at the start in order to enable preview.
699
588
  await insertBlock( 'Navigation' );
@@ -710,9 +599,11 @@ describe.skip( 'Navigation', () => {
710
599
 
711
600
  expect( isScriptLoaded ).toBe( false );
712
601
 
713
- await createNavBlockWithAllPages();
602
+ const allPagesButton = await page.waitForXPath( ADD_ALL_PAGES_XPATH );
603
+ await allPagesButton.click();
714
604
  await insertBlock( 'Navigation' );
715
- await createNavBlockWithAllPages();
605
+ const allPagesButton2 = await page.waitForXPath( ADD_ALL_PAGES_XPATH );
606
+ await allPagesButton2.click();
716
607
  await turnResponsivenessOn();
717
608
 
718
609
  await previewPage.reload( {
@@ -735,22 +626,21 @@ describe.skip( 'Navigation', () => {
735
626
  expect( tagCount ).toBe( 1 );
736
627
  } );
737
628
 
738
- // eslint-disable-next-line jest/no-disabled-tests
739
629
  it.skip( 'loads frontend code only if responsiveness is turned on', async () => {
740
- await mockPagesResponse( [
741
- {
742
- title: 'Home',
743
- slug: 'home',
744
- },
745
- {
746
- title: 'About',
747
- slug: 'about',
748
- },
749
- {
750
- title: 'Contact Us',
751
- slug: 'contact',
752
- },
753
- ] );
630
+ // await mockPagesResponse( [
631
+ // {
632
+ // title: 'Home',
633
+ // slug: 'home',
634
+ // },
635
+ // {
636
+ // title: 'About',
637
+ // slug: 'about',
638
+ // },
639
+ // {
640
+ // title: 'Contact Us',
641
+ // slug: 'contact',
642
+ // },
643
+ // ] );
754
644
 
755
645
  await insertBlock( 'Navigation' );
756
646
  await saveDraft();
@@ -766,7 +656,8 @@ describe.skip( 'Navigation', () => {
766
656
 
767
657
  expect( isScriptLoaded ).toBe( false );
768
658
 
769
- await createNavBlockWithAllPages();
659
+ const allPagesButton = await page.waitForXPath( ADD_ALL_PAGES_XPATH );
660
+ await allPagesButton.click();
770
661
 
771
662
  await turnResponsivenessOn();
772
663
 
@@ -785,7 +676,7 @@ describe.skip( 'Navigation', () => {
785
676
  expect( isScriptLoaded ).toBe( true );
786
677
  } );
787
678
 
788
- describe( 'Creating and restarting', () => {
679
+ describe.skip( 'Creating and restarting', () => {
789
680
  async function populateNavWithOneItem() {
790
681
  // Add a Link block first.
791
682
  await page.waitForSelector(
@@ -814,26 +705,26 @@ describe.skip( 'Navigation', () => {
814
705
  it( 'only update a single entity currently linked with the block', async () => {
815
706
  // Mock the response from the Pages endpoint. This is done so that the pages returned are always
816
707
  // consistent and to test the feature more rigorously than the single default sample page.
817
- await mockPagesResponse( [
818
- {
819
- title: 'Home',
820
- slug: 'home',
821
- },
822
- {
823
- title: 'About',
824
- slug: 'about',
825
- },
826
- {
827
- title: 'Contact Us',
828
- slug: 'contact',
829
- },
830
- ] );
708
+ // await mockPagesResponse( [
709
+ // {
710
+ // title: 'Home',
711
+ // slug: 'home',
712
+ // },
713
+ // {
714
+ // title: 'About',
715
+ // slug: 'about',
716
+ // },
717
+ // {
718
+ // title: 'Contact Us',
719
+ // slug: 'contact',
720
+ // },
721
+ // ] );
831
722
 
832
- // Add the navigation block.
833
723
  await insertBlock( 'Navigation' );
834
-
835
- // Create an empty nav block.
836
- await createEmptyNavBlock();
724
+ const startEmptyButton = await page.waitForXPath(
725
+ START_EMPTY_XPATH
726
+ );
727
+ await startEmptyButton.click();
837
728
  await populateNavWithOneItem();
838
729
 
839
730
  // Let's confirm that the menu entity was updated.
@@ -859,7 +750,10 @@ describe.skip( 'Navigation', () => {
859
750
  await page.focus( '.wp-block-navigation' );
860
751
 
861
752
  await resetNavBlockToInitialState();
862
- await createEmptyNavBlock();
753
+ const startEmptyButton2 = await page.waitForXPath(
754
+ START_EMPTY_XPATH
755
+ );
756
+ await startEmptyButton2.click();
863
757
  await populateNavWithOneItem();
864
758
 
865
759
  // Let's confirm that only the last menu entity was updated.