Skip to content

Commit

Permalink
Test that the inserter limits the suggested items to MAX_SUGGESTED_ITEMS
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 8, 2018
1 parent 5950a15 commit cd3e91e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion editor/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export class InserterMenu extends Component {
sortItems( items ) {
if ( 'suggested' === this.state.tab && ! this.state.filterValue ) {
const sortedItems = orderBy( items, [ 'utility', 'frecency' ], [ 'desc', 'desc' ] );
return sortedItems.slice( 0, MAX_SUGGESTED_ITEMS );

const maxSuggestedItems = this.props.maxSuggestedItems || MAX_SUGGESTED_ITEMS;
return sortedItems.slice( 0, maxSuggestedItems );
}

const getCategoryIndex = ( item ) => {
Expand Down
18 changes: 17 additions & 1 deletion editor/components/inserter/test/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe( 'InserterMenu', () => {
expect( visibleBlocks ).toHaveLength( 0 );
} );

it( 'should show frecently used items in the suggested tab', () => {
it( 'should show items in the suggested tab ordered by utility,frecency', () => {
const wrapper = mount(
<InserterMenu
position={ 'top center' }
Expand All @@ -155,6 +155,22 @@ describe( 'InserterMenu', () => {
expect( visibleBlocks.at( 3 ).text() ).toBe( 'More' );
} );

it( 'should limit the number of items shown in the suggested tab', () => {
const wrapper = mount(
<InserterMenu
position={ 'top center' }
instanceId={ 1 }
items={ items }
debouncedSpeak={ noop }
fetchSharedBlocks={ noop }
maxSuggestedItems={ 2 }
/>
);

const visibleBlocks = wrapper.find( '.editor-inserter__block' );
expect( visibleBlocks ).toHaveLength( 2 );
} );

it( 'should show items from the embed category in the embed tab', () => {
const wrapper = mount(
<InserterMenu
Expand Down

0 comments on commit cd3e91e

Please sign in to comment.