From 238d4d0fb763e769b3d5be6e034894a57e2247b2 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 24 Apr 2024 15:04:21 +0400 Subject: [PATCH] Add unit test --- packages/blocks/src/api/test/registration.js | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index f9a62346a72e41..81f45f1999803e 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -13,6 +13,7 @@ import { select, dispatch } from '@wordpress/data'; import { registerBlockType, registerBlockCollection, + registerBlockVariation, unregisterBlockCollection, unregisterBlockType, setFreeformContentHandlerName, @@ -26,6 +27,7 @@ import { getBlockType, getBlockTypes, getBlockSupport, + getBlockVariations, hasBlockSupport, isReusableBlock, unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase @@ -1410,6 +1412,26 @@ describe( 'blocks', () => { expect( isReusableBlock( block ) ).toBe( false ); } ); } ); + + describe( 'registerBlockVariation', () => { + it( 'should warn when registering block variation without a name', () => { + registerBlockType( 'core/variation-block', defaultBlockSettings ); + registerBlockVariation( 'core/variation-block', { + title: 'Variation Title', + description: 'Variation description', + } ); + + expect( console ).toHaveWarnedWith( + 'Variation names must be unique strings.' + ); + expect( getBlockVariations( 'core/variation-block' ) ).toEqual( [ + { + title: 'Variation Title', + description: 'Variation description', + }, + ] ); + } ); + } ); } ); /* eslint-enable react/forbid-elements */