Skip to content

Commit

Permalink
[RNMobile] Use BlockEdit component when testing component rendering (#…
Browse files Browse the repository at this point in the history
…29569)

* Replace edit component with BlockEdit in unit tests

BlockEdit adds the block edit context, which could be required by some parts of an edit component when it's rendered in a unit test.
  • Loading branch information
fluiddot authored Mar 9, 2021
1 parent 26925dc commit fc78dd3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
20 changes: 18 additions & 2 deletions packages/block-library/src/audio/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { act, create } from 'react-test-renderer';
/**
* WordPress dependencies
*/
import { MediaUploadProgress } from '@wordpress/block-editor';
import { MediaUploadProgress, BlockEdit } from '@wordpress/block-editor';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import AudioEdit from '../edit.native.js';
import { metadata, settings, name } from '../index';

const AudioEdit = ( { clientId, ...props } ) => (
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } />
);

const getTestComponentWithContent = ( attributes = {} ) => {
return create(
Expand All @@ -20,6 +25,17 @@ const getTestComponentWithContent = ( attributes = {} ) => {
};

describe( 'Audio block', () => {
beforeAll( () => {
registerBlockType( name, {
...metadata,
...settings,
} );
} );

afterAll( () => {
unregisterBlockType( name );
} );

it( 'renders placeholder without crashing', () => {
const component = getTestComponentWithContent();
const rendered = component.toJSON();
Expand Down
25 changes: 23 additions & 2 deletions packages/block-library/src/code/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
* External dependencies
*/
import renderer from 'react-test-renderer';
import { TextInput } from 'react-native';

/**
* WordPress dependencies
*/
import { BlockEdit } from '@wordpress/block-editor';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import Code from '../edit';
import { TextInput } from 'react-native';
import { metadata, settings, name } from '../index';

const Code = ( { clientId, ...props } ) => (
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } />
);

describe( 'Code', () => {
beforeAll( () => {
registerBlockType( name, {
...metadata,
...settings,
} );
} );

afterAll( () => {
unregisterBlockType( name );
} );

it( 'renders without crashing', () => {
const component = renderer.create(
<Code attributes={ { content: '' } } />
Expand Down
25 changes: 23 additions & 2 deletions packages/block-library/src/shortcode/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
* External dependencies
*/
import renderer from 'react-test-renderer';
import { TextInput } from 'react-native';

/**
* WordPress dependencies
*/
import { BlockEdit } from '@wordpress/block-editor';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import Shortcode from '../edit';
import { TextInput } from 'react-native';
import { metadata, settings, name } from '../index';

const Shortcode = ( { clientId, ...props } ) => (
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } />
);

describe( 'Shortcode', () => {
beforeAll( () => {
registerBlockType( name, {
...metadata,
...settings,
} );
} );

afterAll( () => {
unregisterBlockType( name );
} );

it( 'renders without crashing', () => {
const component = renderer.create(
<Shortcode attributes={ { text: '' } } />
Expand Down
20 changes: 18 additions & 2 deletions packages/block-library/src/verse/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ import renderer from 'react-test-renderer';
/**
* Internal dependencies
*/
import Verse from '../edit';
import { metadata, settings, name } from '../index';

/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { RichText, BlockEdit } from '@wordpress/block-editor';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';

const Verse = ( { clientId, ...props } ) => (
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } />
);

describe( 'Verse Block', () => {
beforeAll( () => {
registerBlockType( name, {
...metadata,
...settings,
} );
} );

afterAll( () => {
unregisterBlockType( name );
} );

it( 'renders without crashing', () => {
const component = renderer.create(
<Verse attributes={ { content: '' } } />
Expand Down

0 comments on commit fc78dd3

Please sign in to comment.