-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
index.js
60 lines (52 loc) · 1.46 KB
/
index.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
/**
* External dependencies
*/
import { shallow } from 'enzyme';
/**
* Internal dependencies
*/
import BlockIcon from '../../block-icon';
import {
registerBlockType,
unregisterBlockType,
} from '../../api';
import BlockAutocomplete from '../';
describe( 'BlockAutocomplete', () => {
beforeAll( () => {
registerBlockType( 'core/test-block', {
title: 'Test Block',
category: 'common',
icon: 'format-image',
keywords: [ 'example' ],
save() {},
} );
} );
afterAll( () => {
unregisterBlockType( 'core/test-block' );
} );
describe( 'onSelect()', () => {
it( 'calls onReplace callback', () => {
const onReplace = jest.fn();
const wrapper = shallow(
<BlockAutocomplete onReplace={ onReplace } />
);
wrapper.simulate( 'select', {
value: 'core/test-block',
} );
expect( onReplace ).toHaveBeenCalled();
// First argument of first call is the created block
expect( onReplace.mock.calls[ 0 ][ 0 ].name ).toBe( 'core/test-block' );
} );
} );
describe( 'render()', () => {
it( 'renders with block options', () => {
const wrapper = shallow( <BlockAutocomplete /> );
const options = wrapper.prop( 'options' );
expect( options ).toHaveLength( 1 );
expect( options[ 0 ].value ).toBe( 'core/test-block' );
expect( options[ 0 ].label[ 0 ].type ).toBe( BlockIcon );
expect( options[ 0 ].label[ 1 ] ).toBe( 'Test Block' );
expect( options[ 0 ].keywords ).toEqual( [ 'example', 'Test Block' ] );
} );
} );
} );