Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jul 27, 2019
1 parent 51dd9dc commit ffd16b5
Showing 1 changed file with 141 additions and 2 deletions.
143 changes: 141 additions & 2 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit ffd16b5

Please sign in to comment.