Skip to content

Commit

Permalink
Improve flaky draft creation navigation block e2e test (#37931)
Browse files Browse the repository at this point in the history
* Be less specific about the kind of error

* Use per_page=-1 to get all items for deletion

* Move expect(console) call to end of test

* Make sure drafts are deleted
  • Loading branch information
talldan authored Jan 13, 2022
1 parent f0982d1 commit cef5825
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
deleteUser,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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( {
Expand Down Expand Up @@ -204,6 +215,7 @@ describe( 'Navigation', () => {
await deleteAll( [
POSTS_ENDPOINT,
PAGES_ENDPOINT,
DRAFT_PAGES_ENDPOINT,
NAVIGATION_MENUS_ENDPOINT,
] );
await deleteAllClassicMenus();
Expand All @@ -217,6 +229,7 @@ describe( 'Navigation', () => {
await deleteAll( [
POSTS_ENDPOINT,
PAGES_ENDPOINT,
DRAFT_PAGES_ENDPOINT,
NAVIGATION_MENUS_ENDPOINT,
] );
await deleteAllClassicMenus();
Expand Down Expand Up @@ -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.
Expand All @@ -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 () => {
Expand Down

0 comments on commit cef5825

Please sign in to comment.