Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons committed Mar 18, 2021
1 parent 40364c9 commit d826cf9
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const {
__experimentalGetParsedReusableBlock,
__experimentalGetAllowedPatterns,
__experimentalGetScopedBlockPatterns,
__unstableGetClientIdWithClientIdsTree,
__unstableGetClientIdsTree,
} = selectors;

describe( 'selectors', () => {
Expand Down Expand Up @@ -3535,3 +3537,76 @@ describe( 'getInserterItems with core blocks prioritization', () => {
expect( items.map( ( { name } ) => name ) ).toEqual( expectedResult );
} );
} );

describe( '__unstableGetClientIdWithClientIdsTree', () => {
it( "should return a stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
const state = {
blocks: {
order: {
'': [ 'foo' ],
foo: [ 'bar', 'baz' ],
bar: [ 'qux' ],
},
},
};

expect(
__unstableGetClientIdWithClientIdsTree( state, 'foo' )
).toEqual( {
clientId: 'foo',
innerBlocks: [
{
clientId: 'bar',
innerBlocks: [ { clientId: 'qux', innerBlocks: [] } ],
},
{ clientId: 'baz', innerBlocks: [] },
],
} );
} );
} );
describe( '__unstableGetClientIdsTree', () => {
it( "should return the full content tree starting from the given root, consisting of stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
const state = {
blocks: {
order: {
'': [ 'foo' ],
foo: [ 'bar', 'baz' ],
bar: [ 'qux' ],
},
},
};

expect( __unstableGetClientIdsTree( state, 'foo' ) ).toEqual( [
{
clientId: 'bar',
innerBlocks: [ { clientId: 'qux', innerBlocks: [] } ],
},
{ clientId: 'baz', innerBlocks: [] },
] );
} );

it( "should return the full content tree starting from the root, consisting of stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
const state = {
blocks: {
order: {
'': [ 'foo' ],
foo: [ 'bar', 'baz' ],
bar: [ 'qux' ],
},
},
};

expect( __unstableGetClientIdsTree( state ) ).toEqual( [
{
clientId: 'foo',
innerBlocks: [
{
clientId: 'bar',
innerBlocks: [ { clientId: 'qux', innerBlocks: [] } ],
},
{ clientId: 'baz', innerBlocks: [] },
],
},
] );
} );
} );

0 comments on commit d826cf9

Please sign in to comment.