Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flaky draft creation navigation block e2e test #37931

Merged
merged 4 commits into from
Jan 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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