const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); const { recordRequests, waitForRequestsToSettle, } = require( './record-requests' ); test.describe( 'Preload', () => { let pageId; test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); await requestUtils.resetPreferences(); // Posts left behind by earlier specs change the startup requests: // with at least one post, emptytheme's index template query loop // renders the Post Excerpt block, whose editor component fetches // /wp/v2/types/post?context=edit. await requestUtils.deleteAllPosts(); const pg = await requestUtils.createPage( { content: '\n

Hello

\n', status: 'publish', } ); pageId = pg.id; } ); test.afterAll( async ( { requestUtils } ) => { await requestUtils.deleteAllPages(); await requestUtils.activateTheme( 'twentytwentyone' ); } ); test( 'Site editor root should fetch a known set of routes during startup', async ( { page, admin, } ) => { const { requests, stop } = recordRequests( page ); await admin.visitSiteEditor(); await page .frameLocator( 'iframe[name="editor-canvas"]' ) .locator( '[data-block]' ) .first() .waitFor(); await waitForRequestsToSettle( requests ); stop(); // `POST /wp/v2/users/me` (preferences persistence) occasionally // fires twice within the captured window; the duplicate count // isn't stable across runs, so this assertion deduplicates. // To do: these should all be removed or preloaded. expect( Array.from( new Set( requests ) ).sort() ).toEqual( [ 'GET /wp/v2/posts?context=edit&offset=0&order=desc&orderby=date&per_page=10&ignore_sticky=false', 'GET /wp/v2/template-parts/emptytheme//header?context=edit', 'OPTIONS /wp/v2/settings', 'POST /wp/v2/users/me', ].sort() ); } ); test( 'Editing a page should fetch a known set of routes during startup', async ( { page, admin, } ) => { const { requests, stop } = recordRequests( page ); await admin.visitAdminPage( 'site-editor.php', `p=%2Fpage&postId=${ pageId }&canvas=edit` ); await page .frameLocator( 'iframe[name="editor-canvas"]' ) .getByRole( 'document', { name: 'Block: Heading' } ) .filter( { hasText: 'Hello' } ) .waitFor(); await waitForRequestsToSettle( requests ); stop(); // `POST /wp/v2/users/me` (preferences persistence) occasionally // fires twice within the captured window; the duplicate count // isn't stable across runs, so this assertion deduplicates. // To do: these should all be removed or preloaded. expect( Array.from( new Set( requests ) ).sort() ).toEqual( [ `GET /wp/v2/comments?context=edit&post=${ pageId }&type=note&status=all&per_page=100`, `GET /wp/v2/pages/${ pageId }/autosaves?context=edit`, 'GET /wp/v2/taxonomies?context=edit', 'GET /wp/v2/templates/lookup?slug=front-page', 'GET /wp/v2/templates?context=edit&per_page=100&post_type=page', 'GET /wp/v2/types/page?context=edit', 'GET /wp/v2/users/me', 'GET /wp/v2/users?context=view&include%5B0%5D=1&who=authors', 'GET /wp/v2/view-config?kind=postType&name=page', 'GET /wp/v2/view-config?kind=postType&name=page&_fields=form', 'OPTIONS /wp/v2/settings', 'OPTIONS /wp/v2/templates', 'POST /wp/v2/users/me', ].sort() ); } ); } );