From 13a9305d25cc165a5a0ec0a50e4b83c58e14bcf7 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Fri, 16 Sep 2022 20:47:54 +0300 Subject: [PATCH] Blocks: Fix searching of blocks when description is non-string --- packages/blocks/src/store/selectors.js | 3 ++- packages/blocks/src/store/test/selectors.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index d625aae744691..4c3d8252129d3 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -712,7 +712,8 @@ export function isMatchingSearchTerm( state, nameOrType, searchTerm ) { isSearchMatch( blockType.title ) || some( blockType.keywords, isSearchMatch ) || isSearchMatch( blockType.category ) || - isSearchMatch( blockType.description ) + ( typeof blockType.description === 'string' && + isSearchMatch( blockType.description ) ) ); } diff --git a/packages/blocks/src/store/test/selectors.js b/packages/blocks/src/store/test/selectors.js index e8eed9958c45e..8793e1e354e44 100644 --- a/packages/blocks/src/store/test/selectors.js +++ b/packages/blocks/src/store/test/selectors.js @@ -605,6 +605,10 @@ describe( 'selectors', () => { ...blockTypeBase, category, }; + const blockTypeWithNonStringDescription = { + ...blockTypeBase, + description:
writing flow
, + }; const state = { blockTypes: { @@ -617,6 +621,10 @@ describe( 'selectors', () => { [ 'block type', blockType ], [ 'block type without category', blockTypeWithoutCategory ], [ 'block type without description', blockTypeWithoutDescription ], + [ + 'block type with non-string description', + blockTypeWithNonStringDescription, + ], ] )( 'by %s', ( label, nameOrType ) => { it( 'should return false if not match', () => { const result = isMatchingSearchTerm( @@ -690,7 +698,10 @@ describe( 'selectors', () => { } ); } - if ( nameOrType.description ) { + if ( + nameOrType.description && + typeof nameOrType.description === 'string' + ) { it( 'should return true if match using the description', () => { const result = isMatchingSearchTerm( state,