Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jun 5, 2024
1 parent 566430c commit 03f14d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
"clientNavigation": true
}
},
"variations": [
{
"name": "warning-with-color",
"title": "Warning with color",
"icon": "warning",
"attributes": {
"content": "This is a <strong>warning</strong> message.",
"backgroundColor": "luminous-vivid-amber"
},
"isActive": [ "content", "backgroundColor" ]
}
],
"editorStyle": "wp-block-paragraph-editor",
"style": "wp-block-paragraph"
}
42 changes: 42 additions & 0 deletions packages/blocks/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
getActiveBlockVariation,
} from '../selectors';

/**
* WordPress dependencies
*/
import { RichTextData } from '@wordpress/rich-text';

const keyBlocksByName = ( blocks ) =>
blocks.reduce(
( result, block ) => ( { ...result, [ block.name ]: block } ),
Expand Down Expand Up @@ -452,6 +457,43 @@ describe( 'selectors', () => {
} )
).toEqual( variations[ 1 ] );
} );
it( 'should support RichText attributes in the isActive array', () => {
const variations = [
{
name: 'variation-1',
attributes: {
firstTestAttribute:
'This is a <strong>RichText</strong> attribute.',
},
isActive: [ 'firstTestAttribute' ],
},
{
name: 'variation-2',
attributes: {
firstTestAttribute:
'This is a <em>RichText</em> attribute.',
},
isActive: [ 'firstTestAttribute' ],
},
];
const state =
createBlockVariationsStateWithTestBlockType( variations );

expect(
getActiveBlockVariation( state, blockName, {
firstTestAttribute: RichTextData.fromHTMLString(
'This is a <strong>RichText</strong> attribute.'
),
} )
).toEqual( variations[ 0 ] );
expect(
getActiveBlockVariation( state, blockName, {
firstTestAttribute: RichTextData.fromHTMLString(
'This is a <em>RichText</em> attribute.'
),
} )
).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 03f14d9

Please sign in to comment.