Skip to content

Commit

Permalink
[RNMobile] Use internal initializeEditor for integration tests (#39224)
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot authored Mar 7, 2022
1 parent 82d87ff commit ef8b6a7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions test/native/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import {
subscribeParentGetHtml,
provideToNative_Html as provideToNativeHtml,
} from '@wordpress/react-native-bridge';
// Editor component is not exposed in the pacakge because is meant to be consumed
// internally, however we require it for rendering the editor in integration tests,
// for this reason it's imported with path access.
// eslint-disable-next-line no-restricted-syntax
import Editor from '@wordpress/edit-post/src/editor';
import { initializeEditor as internalInitializeEditor } from '@wordpress/edit-post';
import { createElement, cloneElement } from '@wordpress/element';

// Set up the mocks for getting the HTML output of the editor.
let triggerHtmlSerialization;
Expand Down Expand Up @@ -87,16 +84,18 @@ export async function waitForStoreResolvers( fn ) {
* @param {import('react').ReactNode} [options.component] A specific editor component to render.
* @return {import('@testing-library/react-native').RenderAPI} A Testing Library screen.
*/
export async function initializeEditor( props, { component = Editor } = {} ) {
export async function initializeEditor( props, { component } = {} ) {
const uniqueId = uuid();
const postId = `post-id-${ uniqueId }`;
const postType = 'post';

return waitForStoreResolvers( () => {
const EditorComponent = component;
const editorElement = component
? createElement( component, { postType, postId } )
: internalInitializeEditor( uniqueId, postType, postId );

const screen = render(
<EditorComponent
postId={ `post-id-${ uuid() }` }
postType="post"
initialTitle="test"
{ ...props }
/>
cloneElement( editorElement, { initialTitle: 'test', ...props } )
);

// A layout event must be explicitly dispatched in BlockList component,
Expand Down

0 comments on commit ef8b6a7

Please sign in to comment.