Skip to content

Commit

Permalink
Fix and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 18, 2024
1 parent 9f927dd commit d031611
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,7 @@ describe( 'selectors', () => {
byClientId: new Map(),
attributes: new Map(),
parents: new Map(),
order: new Map(),
},
blockListSettings: {},
settings: {
Expand All @@ -2711,6 +2712,7 @@ describe( 'selectors', () => {
blocks: {
byClientId: new Map(),
attributes: new Map(),
order: new Map(),
},
blockListSettings: {},
settings: {
Expand All @@ -2728,6 +2730,7 @@ describe( 'selectors', () => {
byClientId: new Map(),
attributes: new Map(),
parents: new Map(),
order: new Map(),
},
blockListSettings: {},
settings: {},
Expand Down Expand Up @@ -3002,7 +3005,7 @@ describe( 'selectors', () => {
byClientId: new Map(
Object.entries( {
block1: { name: 'core/test-block-ancestor' },
block2: { name: 'core/block' },
block2: { name: 'core/block1' },
} )
),
attributes: new Map(
Expand Down Expand Up @@ -3037,6 +3040,37 @@ describe( 'selectors', () => {
).toBe( true );
} );

it( 'should prevent blocks from being inserted within sections', () => {
const state = {
blocks: {
byClientId: new Map(
Object.entries( {
block1: { name: 'core/block' }, // reusable blocks are always sections.
} )
),
attributes: new Map(
Object.entries( {
block1: {},
} )
),
parents: new Map(
Object.entries( {
block1: '',
} )
),
order: new Map( [ [ '', [ 'block1' ] ] ] ),
},
blockListSettings: {
block1: {},
},
settings: {},
blockEditingModes: new Map(),
};
expect(
canInsertBlockType( state, 'core/test-block-a', 'block1' )
).toBe( false );
} );

it( 'should allow blocks to be inserted if both parent and ancestor restrictions are met', () => {
const state = {
blocks: {
Expand Down

0 comments on commit d031611

Please sign in to comment.