From 183ef1a7649751a9858552207f367eaf9dbe5814 Mon Sep 17 00:00:00 2001 From: dufresnesteven Date: Tue, 16 Jun 2020 10:53:58 +0900 Subject: [PATCH] Add back in tests removed in rebase. --- .../src/store/test/selectors.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/packages/block-directory/src/store/test/selectors.js b/packages/block-directory/src/store/test/selectors.js index 148dc7494c086..ff2b6911d6045 100644 --- a/packages/block-directory/src/store/test/selectors.js +++ b/packages/block-directory/src/store/test/selectors.js @@ -102,6 +102,76 @@ describe( 'selectors', () => { } ); } ); + describe( 'getNewBlockTypes', () => { + it( 'should retrieve the block types that are installed and in the post content', () => { + getNewBlockTypes.registry = { + select: jest.fn( () => ( { getBlocks: () => blockList } ) ), + }; + const state = { + blockManagement: { + installedBlockTypes: [ + blockTypeInstalled, + blockTypeUnused, + ], + }, + }; + const blockTypes = getNewBlockTypes( state ); + expect( blockTypes ).toHaveLength( 1 ); + expect( blockTypes[ 0 ] ).toEqual( blockTypeInstalled ); + } ); + + it( 'should return an empty array if no blocks are used', () => { + getNewBlockTypes.registry = { + select: jest.fn( () => ( { getBlocks: () => [] } ) ), + }; + const state = { + blockManagement: { + installedBlockTypes: [ + blockTypeInstalled, + blockTypeUnused, + ], + }, + }; + const blockTypes = getNewBlockTypes( state ); + expect( blockTypes ).toHaveLength( 0 ); + } ); + } ); + + describe( 'getUnusedBlockTypes', () => { + it( 'should retrieve the block types that are installed but not used', () => { + getUnusedBlockTypes.registry = { + select: jest.fn( () => ( { getBlocks: () => blockList } ) ), + }; + const state = { + blockManagement: { + installedBlockTypes: [ + blockTypeInstalled, + blockTypeUnused, + ], + }, + }; + const blockTypes = getUnusedBlockTypes( state ); + expect( blockTypes ).toHaveLength( 1 ); + expect( blockTypes[ 0 ] ).toEqual( blockTypeUnused ); + } ); + + it( 'should return all block types if no blocks are used', () => { + getUnusedBlockTypes.registry = { + select: jest.fn( () => ( { getBlocks: () => [] } ) ), + }; + const state = { + blockManagement: { + installedBlockTypes: [ + blockTypeInstalled, + blockTypeUnused, + ], + }, + }; + const blockTypes = getUnusedBlockTypes( state ); + expect( blockTypes ).toHaveLength( 2 ); + } ); + } ); + describe( 'getErrorNoticeForBlock', () => { const state = { errorNotices: {