Skip to content

Commit

Permalink
Merge pull request #2171 from WordPress/update/inserter/search
Browse files Browse the repository at this point in the history
Strip whitespace on inserter search term.
  • Loading branch information
timmyc authored Aug 3, 2017
2 parents 1954f50 + 80c82c6 commit d709c8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion editor/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getBlocks, getRecentlyUsedBlocks } from '../selectors';
import { showInsertionPoint, hideInsertionPoint } from '../actions';

export const searchBlocks = ( blocks, searchTerm ) => {
const normalizedSearchTerm = searchTerm.toLowerCase();
const normalizedSearchTerm = searchTerm.toLowerCase().trim();
const matchSearch = ( string ) => string.toLowerCase().indexOf( normalizedSearchTerm ) !== -1;

return blocks.filter( ( block ) =>
Expand Down
20 changes: 20 additions & 0 deletions editor/inserter/test/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ describe( 'InserterMenu', () => {
expect( visibleBlocks.at( 1 ).childAt( 1 ).text() ).toBe( 'Advanced Text' );
expect( visibleBlocks.at( 2 ).childAt( 1 ).text() ).toBe( 'A Text Embed' );
} );

it( 'should trim whitespace of search terms', () => {
const wrapper = shallow(
<InserterMenu
instanceId={ 1 }
blocks={ [] }
recentlyUsedBlocks={ [] }
/>
);
wrapper.setState( { filterValue: ' text' } );

const tabs = wrapper.find( '.editor-inserter__tab' );
expect( tabs.length ).toBe( 0 );

const visibleBlocks = wrapper.find( '.editor-inserter__block' );
expect( visibleBlocks.length ).toBe( 3 );
expect( visibleBlocks.at( 0 ).childAt( 1 ).text() ).toBe( 'Text' );
expect( visibleBlocks.at( 1 ).childAt( 1 ).text() ).toBe( 'Advanced Text' );
expect( visibleBlocks.at( 2 ).childAt( 1 ).text() ).toBe( 'A Text Embed' );
} );
} );

describe( 'searchBlocks', () => {
Expand Down

0 comments on commit d709c8e

Please sign in to comment.