Skip to content

Commit

Permalink
Add tests for insertAfterBlock, insertBeforeBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Mar 5, 2021
1 parent d58b653 commit 81e9228
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const {
enterFormattedText,
exitFormattedText,
hideInsertionPoint,
insertAfterBlock,
insertBeforeBlock,
insertBlock,
insertBlocks,
mergeBlocks,
Expand Down Expand Up @@ -741,6 +743,136 @@ describe( 'actions', () => {
} );
} );

describe( 'insertAfterBlock', () => {
it( 'should call insert default block without blockName', () => {
const clientId = 'testClientId';
const rootClientId = 'testRootId';
const generator = insertAfterBlock( clientId );
expect( generator.next().value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockRootClientId',
clientId
)
);
expect( generator.next( rootClientId ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getTemplateLock',
rootClientId
)
);
expect( generator.next( false ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockIndex',
clientId,
rootClientId
)
);
//expect undefined since we didn't register a default block name
expect( generator.next( 1 ).value ).toEqual( undefined );
} );
it( 'should call insertBlock with blockName', () => {
const clientId = 'testClientId';
const rootClientId = 'testRootId';
const generator = insertAfterBlock(
clientId,
'test/custom-default'
);
expect( generator.next().value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockRootClientId',
clientId
)
);
expect( generator.next( rootClientId ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getTemplateLock',
rootClientId
)
);
expect( generator.next( false ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockIndex',
clientId,
rootClientId
)
);
expect( () => generator.next( 1 ) ).toThrow(
"Block type 'test/custom-default' is not registered."
);
} );
} );

describe( 'insertBeforeBlock', () => {
it( 'should call insert default block without blockName', () => {
const clientId = 'testClientId';
const rootClientId = 'testRootId';
const generator = insertBeforeBlock( clientId );
expect( generator.next().value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockRootClientId',
clientId
)
);
expect( generator.next( rootClientId ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getTemplateLock',
rootClientId
)
);
expect( generator.next( false ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockIndex',
clientId,
rootClientId
)
);
//expect undefined since we didn't register a default block name
expect( generator.next( 1 ).value ).toEqual( undefined );
} );
it( 'should call insertBlock with blockName', () => {
const clientId = 'testClientId';
const rootClientId = 'testRootId';
const generator = insertBeforeBlock(
clientId,
'test/custom-default'
);
expect( generator.next().value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockRootClientId',
clientId
)
);
expect( generator.next( rootClientId ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getTemplateLock',
rootClientId
)
);
expect( generator.next( false ).value ).toEqual(
controls.select(
blockEditorStoreName,
'getBlockIndex',
clientId,
rootClientId
)
);
expect( () => generator.next( 1 ) ).toThrow(
"Block type 'test/custom-default' is not registered."
);
} );
} );

describe( '__unstableSetInsertionPoint', () => {
it( 'should return the SET_INSERTION_POINT action', () => {
expect( __unstableSetInsertionPoint() ).toEqual( {
Expand Down

0 comments on commit 81e9228

Please sign in to comment.