-
Notifications
You must be signed in to change notification settings - Fork 4k
/
edit.native.js
65 lines (54 loc) · 1.43 KB
/
edit.native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* External dependencies
*/
import { render } from 'test/helpers';
import { Text } from 'react-native';
/**
* WordPress dependencies
*/
import {
registerBlockType,
unregisterBlockType,
getBlockTypes,
} from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { Edit } from '../edit';
import { BlockContextProvider } from '../../block-context';
describe( 'Edit', () => {
afterEach( () => {
getBlockTypes().forEach( ( block ) => {
unregisterBlockType( block.name );
} );
} );
it( 'should return null if block type not defined', () => {
const screen = render( <Edit name="core/test-block" /> );
expect( screen.toJSON() ).toBe( null );
} );
it( 'should use edit implementation of block', () => {
const edit = () => <Text>core/test-block</Text>;
registerBlockType( 'core/test-block', {
category: 'text',
title: 'block title',
edit,
} );
const screen = render( <Edit name="core/test-block" /> );
expect( screen.getByText( 'core/test-block' ) ).toBeDefined();
} );
it( 'should assign context', () => {
const edit = ( { context } ) => <Text>{ context.value }</Text>;
registerBlockType( 'core/test-block', {
category: 'text',
title: 'block title',
usesContext: [ 'value' ],
edit,
} );
const screen = render(
<BlockContextProvider value={ { value: 'Ok' } }>
<Edit name="core/test-block" />
</BlockContextProvider>
);
expect( screen.getByText( 'Ok' ) ).toBeDefined();
} );
} );