From c4f27a0c460c1d6abff41487e6cea9e78900c522 Mon Sep 17 00:00:00 2001 From: Jorge Date: Mon, 18 Apr 2022 16:23:17 +0100 Subject: [PATCH] Add unit test --- .../src/components/block-title/test/index.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/block-editor/src/components/block-title/test/index.js b/packages/block-editor/src/components/block-title/test/index.js index 2611587a4e2207..7cd20a7a0540cd 100644 --- a/packages/block-editor/src/components/block-title/test/index.js +++ b/packages/block-editor/src/components/block-title/test/index.js @@ -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 } ) { @@ -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; + } + }, }; } ); @@ -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( + + ); + + expect( wrapper.text() ).toBe( 'My custom section' ); + } ); } );