Skip to content

Commit

Permalink
test: Mobile editor mocks getPostType resolution
Browse files Browse the repository at this point in the history
The mobile editor only supports the `post-only` rendering mode, so we
presume a resolved `getPostType` selector to unblock editor rendering.
This is necessary as the editor provider awaits post type resolution
before rendering the entirety of the editor.
  • Loading branch information
dcalhoun committed Nov 15, 2024
1 parent fcb1449 commit ec543c5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/native/integration-test-helpers/initialize-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { v4 as uuid } from 'uuid';
import { createElement, cloneElement } from '@wordpress/element';
// eslint-disable-next-line no-restricted-imports
import { initializeEditor as internalInitializeEditor } from '@wordpress/edit-post';
import { store as coreStore } from '@wordpress/core-data';
import { select } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -28,6 +30,21 @@ import { getGlobalStyles } from './get-global-styles';
* @return {import('@testing-library/react-native').RenderAPI} A Testing Library screen.
*/
export async function initializeEditor( props, { component } = {} ) {
const resolutionSpy = jest.spyOn(
select( coreStore ),
'hasFinishedResolution'
);
const actualResolution = resolutionSpy.getMockImplementation();
resolutionSpy.mockImplementation( ( selectorName, args ) => {
// The mobile editor only supports the `post-only` rendering mode, so we
// presume a resolved `getPostType` selector to unblock editor rendering.
if ( 'getPostType' === selectorName ) {
return true;
}

return actualResolution( selectorName, args );
} );

const uniqueId = uuid();
const postId = `post-id-${ uniqueId }`;
const postType = 'post';
Expand Down

0 comments on commit ec543c5

Please sign in to comment.