diff --git a/packages/e2e-tests/specs/editor/blocks/navigation.test.js b/packages/e2e-tests/specs/editor/blocks/navigation.test.js index 49269f6e547853..f54791bdb0ad89 100644 --- a/packages/e2e-tests/specs/editor/blocks/navigation.test.js +++ b/packages/e2e-tests/specs/editor/blocks/navigation.test.js @@ -22,6 +22,7 @@ import { deleteUser, switchUserToAdmin, } from '@wordpress/e2e-test-utils'; +import { addQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -30,6 +31,7 @@ import menuItemsFixture from '../fixtures/menu-items-request-fixture.json'; const POSTS_ENDPOINT = '/wp/v2/posts'; const PAGES_ENDPOINT = '/wp/v2/pages'; +const DRAFT_PAGES_ENDPOINT = [ PAGES_ENDPOINT, { status: 'draft' } ]; const NAVIGATION_MENUS_ENDPOINT = '/wp/v2/navigation'; async function mockSearchResponse( items ) { @@ -126,8 +128,17 @@ const SELECT_MENU_XPATH = `${ PLACEHOLDER_ACTIONS_XPATH }//button[text()='Select * @param {*} endpoints The endpoints of the resources to delete. */ async function deleteAll( endpoints ) { - for ( const path of endpoints ) { - const items = await rest( { path } ); + for ( const endpoint of endpoints ) { + const defaultArgs = { per_page: -1 }; + const isArrayEndpoint = Array.isArray( endpoint ); + const path = isArrayEndpoint ? endpoint[ 0 ] : endpoint; + const args = isArrayEndpoint + ? { ...defaultArgs, ...endpoint[ 1 ] } + : defaultArgs; + + const items = await rest( { + path: addQueryArgs( path, args ), + } ); for ( const item of items ) { await rest( { @@ -204,6 +215,7 @@ describe( 'Navigation', () => { await deleteAll( [ POSTS_ENDPOINT, PAGES_ENDPOINT, + DRAFT_PAGES_ENDPOINT, NAVIGATION_MENUS_ENDPOINT, ] ); await deleteAllClassicMenus(); @@ -217,6 +229,7 @@ describe( 'Navigation', () => { await deleteAll( [ POSTS_ENDPOINT, PAGES_ENDPOINT, + DRAFT_PAGES_ENDPOINT, NAVIGATION_MENUS_ENDPOINT, ] ); await deleteAllClassicMenus(); @@ -468,9 +481,6 @@ describe( 'Navigation', () => { ); const createPagePromise = createPageButton.click(); await Promise.all( [ responsePromise, createPagePromise ] ); - expect( console ).toHaveErroredWith( - 'Failed to load resource: the server responded with a status of 404 (Not Found)' - ); // Creating a draft is async, so wait for a sign of completion. In this // case the link that shows in the URL popover once a link is added. @@ -482,6 +492,9 @@ describe( 'Navigation', () => { // Expect a Navigation Block with a link for "A really long page name that will not exist". expect( await getNavigationMenuRawContent() ).toMatchSnapshot(); + expect( console ).toHaveErroredWith( + 'Failed to load resource: the server responded with a status of 404 (Not Found)' + ); } ); it( 'renders buttons for the submenu opener elements when the block is set to open on click instead of hover', async () => {