From ef8b6a75185bb5a30f826b3140d3a86651778f2b Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Mon, 7 Mar 2022 18:04:50 +0100 Subject: [PATCH] [RNMobile] Use internal initializeEditor for integration tests (#39224) --- test/native/helpers.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/native/helpers.js b/test/native/helpers.js index a2918aa6354f1d..af17feed5e49ea 100644 --- a/test/native/helpers.js +++ b/test/native/helpers.js @@ -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; @@ -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( - + cloneElement( editorElement, { initialTitle: 'test', ...props } ) ); // A layout event must be explicitly dispatched in BlockList component,