From a26dc17e0e97d4c3b1a316665384a038a15de59c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 17 Dec 2021 21:05:23 +0000 Subject: [PATCH] Fix flaky Navigation block e2e test by mocking out URL details endpoint to avoid 404 (#37501) --- .../specs/editor/blocks/navigation.test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/e2e-tests/specs/editor/blocks/navigation.test.js b/packages/e2e-tests/specs/editor/blocks/navigation.test.js index 6f99aca050999..e8fc8a228a10f 100644 --- a/packages/e2e-tests/specs/editor/blocks/navigation.test.js +++ b/packages/e2e-tests/specs/editor/blocks/navigation.test.js @@ -435,6 +435,19 @@ describe( 'Navigation', () => { } ); it( 'allows pages to be created from the navigation block and their links added to menu', async () => { + // The URL Details endpoint 404s for the created page, since it will + // be a draft that is inaccessible publicly. To avoid this we mock + // out the endpoint response to be empty which will be handled gracefully + // in the UI whilst avoiding any 404s. + await setUpResponseMocking( [ + { + match: ( request ) => + request.url().includes( `rest_route` ) && + request.url().includes( `url-details` ), + onRequestMatch: createJSONResponse( [] ), + }, + ] ); + await createNewPost(); await insertBlock( 'Navigation' ); const startEmptyButton = await page.waitForXPath( START_EMPTY_XPATH ); @@ -469,12 +482,6 @@ describe( 'Navigation', () => { `//a[contains(@class, "block-editor-link-control__search-item-title") and contains(., "${ pageTitle }")]` ); - // The URL Details endpoint 404s for the created page, since it will - // be a draft that is inaccessible publicly. Wait for the HTTP request - // to finish, since this seems to make the test more stable. - await page.waitForNetworkIdle(); - expect( console ).toHaveErrored(); - await publishPost(); // Expect a Navigation Block with a link for "A really long page name that will not exist".