Skip to content

Commit

Permalink
Add unit test for object comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jun 4, 2024
1 parent f6e4d98 commit 8b0dacc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/blocks/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,51 @@ describe( 'selectors', () => {
} )
).toEqual( variations[ 1 ] );
} );
it( 'should compare object attributes in the isActive array based on given properties', () => {
const variations = [
{
name: 'variation-1',
attributes: {
testAttribute: {
nestedProperty: 1,
secondNestedProperty: 10,
},
},
isActive: [ 'testAttribute' ],
},
{
name: 'variation-2',
attributes: {
testAttribute: {
nestedProperty: 2,
secondNestedProperty: 20,
},
},
isActive: [ 'testAttribute' ],
},
];
const state =
createBlockVariationsStateWithTestBlockType( variations );

expect(
getActiveBlockVariation( state, blockName, {
testAttribute: {
nestedProperty: 1,
secondNestedProperty: 10,
otherNestedProperty: 5555,
},
} )
).toEqual( variations[ 0 ] );
expect(
getActiveBlockVariation( state, blockName, {
testAttribute: {
nestedProperty: 2,
secondNestedProperty: 20,
otherNestedProperty: 5555,
},
} )
).toEqual( variations[ 1 ] );
} );
it( 'should return the active variation based on the given isActive array (multiple values)', () => {
const variations = [
{
Expand Down

0 comments on commit 8b0dacc

Please sign in to comment.