diff --git a/packages/block-editor/src/store/test/actions.js b/packages/block-editor/src/store/test/actions.js index 82209edb4f610b..e2a5931dd7f581 100644 --- a/packages/block-editor/src/store/test/actions.js +++ b/packages/block-editor/src/store/test/actions.js @@ -185,8 +185,14 @@ describe( 'actions', () => { const replaceBlockGenerator = replaceBlocks( [ 'chicken' ], blocks ); - // Skip getSettings select. - replaceBlockGenerator.next(); + expect( + replaceBlockGenerator.next().value, + ).toEqual( { + args: [], + selectorName: 'getSettings', + storeName: 'core/block-editor', + type: 'SELECT', + } ); expect( replaceBlockGenerator.next().value, @@ -330,6 +336,139 @@ describe( 'actions', () => { } ); describe( 'insertBlocks', () => { + it( 'should apply default styles to blocks if blocks do not contain a style', () => { + const ribsBlock = { + clientId: 'ribs', + name: 'core/test-ribs', + }; + const chickenBlock = { + clientId: 'chicken', + name: 'core/test-chicken', + }; + const chickenRibsBlock = { + clientId: 'chicken-ribs', + name: 'core/test-chicken-ribs', + }; + const blocks = [ + ribsBlock, + chickenBlock, + chickenRibsBlock, + ]; + + const insertBlocksGenerator = insertBlocks( blocks, 5, 'testrootid', false ); + + expect( + insertBlocksGenerator.next().value, + ).toEqual( { + args: [], + selectorName: 'getSettings', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( { + defaultBlockStyles: { + 'core/test-ribs': 'squared', + 'core/test-chicken-ribs': 'colorful', + }, + } ).value, + ).toEqual( { + args: [ 'core/test-ribs', 'testrootid' ], + selectorName: 'canInsertBlockType', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( true ).value + ).toEqual( { + args: [ 'core/test-chicken', 'testrootid' ], + selectorName: 'canInsertBlockType', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( true ).value, + ).toEqual( { + args: [ 'core/test-chicken-ribs', 'testrootid' ], + selectorName: 'canInsertBlockType', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( true ), + ).toEqual( { + done: true, + value: { + type: 'INSERT_BLOCKS', + blocks: [ + { ...ribsBlock, attributes: { className: 'is-style-squared' } }, + chickenBlock, + { ...chickenRibsBlock, attributes: { className: 'is-style-colorful' } }, + ], + index: 5, + rootClientId: 'testrootid', + time: expect.any( Number ), + updateSelection: false, + }, + } ); + } ); + + it( 'should keep styles explicitly set even if different from the default', () => { + const ribsWithStyleBlock = { + clientId: 'ribs', + name: 'core/test-ribs', + attributes: { + className: 'is-style-colorful', + }, + }; + const blocks = [ + ribsWithStyleBlock, + ]; + + const insertBlocksGenerator = insertBlocks( blocks, 5, 'testrootid', false ); + + expect( + insertBlocksGenerator.next().value, + ).toEqual( { + args: [], + selectorName: 'getSettings', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( { + defaultBlockStyles: { + 'core/test-ribs': 'squared', + }, + } ).value, + ).toEqual( { + args: [ 'core/test-ribs', 'testrootid' ], + selectorName: 'canInsertBlockType', + storeName: 'core/block-editor', + type: 'SELECT', + } ); + + expect( + insertBlocksGenerator.next( true ), + ).toEqual( { + done: true, + value: { + type: 'INSERT_BLOCKS', + blocks: [ + { ...ribsWithStyleBlock, attributes: { className: 'is-style-colorful' } }, + ], + index: 5, + rootClientId: 'testrootid', + time: expect.any( Number ), + updateSelection: false, + }, + } ); + } ); it( 'should filter the allowed blocks in INSERT_BLOCKS action', () => { const ribsBlock = { clientId: 'ribs',