Skip to content

Commit

Permalink
Fixed up tests, removed ordering recent blocks by title
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki committed Jul 11, 2017
1 parent 8f00652 commit ead5309
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
10 changes: 3 additions & 7 deletions editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import moment from 'moment';
import { first, last, get, values, sortBy } from 'lodash';
import { first, last, get, values } from 'lodash';
import createSelector from 'rememo';

/**
Expand Down Expand Up @@ -677,10 +677,6 @@ export function getNotices( state ) {
* @return {Array} List of recently used blocks
*/
export function getRecentlyUsedBlocks( state ) {
// resolves the block names in the state to the block type settings,
// and orders by title so they don't jump around as much in the recent tab
return sortBy(
state.editor.recentlyUsedBlocks.map( blockType => getBlockType( blockType ) ),
( blockType ) => blockType.title
);
// resolves the block names in the state to the block type settings
return state.editor.recentlyUsedBlocks.map( blockType => getBlockType( blockType ) );
}
11 changes: 6 additions & 5 deletions editor/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ export const editor = combineUndoableReducers( {
.filter( ( blockType ) => 'common' === blockType.category )
.slice( 0, maxRecent )
.map( ( blockType ) => blockType.name );
case 'INSERT_BLOCK':
case 'INSERT_BLOCKS':
// This is where we record the block usage so it can show up in
// the recent blocks.
return [
action.block.name,
...without( state, action.block.name ),
].slice( 0, maxRecent );
let newState = [ ...state ];
action.blocks.forEach( ( block ) => {
newState = [ block.name, ...without( newState, block.name ) ];
} );
return newState.slice( 0, maxRecent );
}
return state;
},
Expand Down
21 changes: 10 additions & 11 deletions editor/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@ describe( 'state', () => {

it( 'should record recently used blocks', () => {
const original = editor( undefined, {} );
expect( original.recentlyUsedBlocks ).to.not.include( 'core-embed/twitter' );

const state = editor( original, {
type: 'INSERT_BLOCK',
block: {
type: 'INSERT_BLOCKS',
blocks: [ {
uid: 'bacon',
name: 'core-embed/twitter',
},
} ],
} );

expect( state.recentlyUsedBlocks ).to.eql( [ 'core-embed/twitter' ] );
expect( state.recentlyUsedBlocks[ 0 ] ).toEqual( 'core-embed/twitter' );

const twoRecentBlocks = editor( state, {
type: 'INSERT_BLOCK',
block: {
type: 'INSERT_BLOCKS',
blocks: [ {
uid: 'eggs',
name: 'core-embed/youtube',
},
} ],
} );

expect( twoRecentBlocks.recentlyUsedBlocks ).to.eql( [ 'core-embed/youtube', 'core-embed/twitter' ] );
expect( twoRecentBlocks.recentlyUsedBlocks[ 0 ] ).toEqual( 'core-embed/youtube' );
expect( twoRecentBlocks.recentlyUsedBlocks[ 1 ] ).toEqual( 'core-embed/twitter' );
} );

it( 'should populate recently used blocks with the common category', () => {
Expand All @@ -116,7 +115,7 @@ describe( 'state', () => {
},
} );

expect( initial.recentlyUsedBlocks ).to.have.eql( [ 'core/test-block' ] );
expect( initial.recentlyUsedBlocks ).toEqual( expect.arrayContaining( [ 'core/test-block', 'core/text' ] ) );
} );

it( 'should replace the block', () => {
Expand Down

0 comments on commit ead5309

Please sign in to comment.