Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 18, 2022
1 parent f55e063 commit c4f27a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/block-editor/src/components/block-title/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jest.mock( '@wordpress/blocks', () => {

case 'name-with-long-label':
return { title: 'Block With Long Label' };
case 'name-with-section':
return { title: 'Block With Section Support' };
}
},
__experimentalGetBlockLabel( { title } ) {
Expand All @@ -48,6 +50,11 @@ jest.mock( '@wordpress/blocks', () => {
return title;
}
},
hasBlockSupport( name, support, defaultSupport = false ) {
if ( support === '__experimentalSection' ) {
return name === 'name-with-section' ? true : defaultSupport;
}
},
};
} );

Expand Down Expand Up @@ -178,4 +185,17 @@ describe( 'BlockTitle', () => {
'This is a longer label than typical for blocks to have.'
);
} );

it( 'should return section title if the block supports it', () => {
useSelect.mockImplementation( () => ( {
name: 'name-with-section',
attributes: { isSection: true, sectionName: 'My custom section' },
} ) );

const wrapper = shallow(
<BlockTitle clientId="id-name-with-long-label" />
);

expect( wrapper.text() ).toBe( 'My custom section' );
} );
} );

0 comments on commit c4f27a0

Please sign in to comment.