Skip to content

Commit

Permalink
Blocks: Fix searching of blocks when description is non-string
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored and noahtallen committed Sep 19, 2022
1 parent 5d00e5a commit 13a9305
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/blocks/src/store/selectors.js
Expand Up @@ -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 ) )
);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/blocks/src/store/test/selectors.js
Expand Up @@ -605,6 +605,10 @@ describe( 'selectors', () => {
...blockTypeBase,
category,
};
const blockTypeWithNonStringDescription = {
...blockTypeBase,
description: <div>writing flow</div>,
};

const state = {
blockTypes: {
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 13a9305

Please sign in to comment.