From 79840cebf10393401d70498cd7d49f209ae9e3f1 Mon Sep 17 00:00:00 2001 From: Anthony Ledesma <30462574+AnthonyLedesma@users.noreply.github.com> Date: Wed, 11 Dec 2019 14:36:16 -0700 Subject: [PATCH] Improve Dynamic Separator block stability through transforms testing (#1188) --- .../dynamic-separator/test/transforms.spec.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/blocks/dynamic-separator/test/transforms.spec.js diff --git a/src/blocks/dynamic-separator/test/transforms.spec.js b/src/blocks/dynamic-separator/test/transforms.spec.js new file mode 100644 index 00000000000..61ff2345a30 --- /dev/null +++ b/src/blocks/dynamic-separator/test/transforms.spec.js @@ -0,0 +1,49 @@ +/** + * External dependencies + */ +import { registerCoreBlocks } from '@wordpress/block-library'; +import { registerBlockType, createBlock, switchToBlockType } from '@wordpress/blocks'; + +registerCoreBlocks(); + +/** + * Internal dependencies. + */ +import { name, settings } from '../index'; + +describe( 'coblocks/dynamic-separator transforms', () => { + beforeAll( () => { + // Register the block. + registerBlockType( name, { category: 'common', ...settings } ); + } ); + + it( 'should transform from core/spacer block', () => { + const coreSpacer = createBlock( 'core/spacer', { height: 200 } ); + const transformed = switchToBlockType( coreSpacer, name ); + + expect( transformed[ 0 ].isValid ).toBe( true ); + expect( transformed[ 0 ].attributes.height ).toBe( 200 ); + } ); + + it( 'should transform from core/separator block', () => { + const coreSeparator = createBlock( 'core/separator' ); + + const transformed = switchToBlockType( coreSeparator, name ); + expect( transformed[ 0 ].isValid ).toBe( true ); + } ); + + it( 'should transform to core/spacer block', () => { + const block = createBlock( name, { height: 200 } ); + const transformed = switchToBlockType( block, 'core/spacer' ); + + expect( transformed[ 0 ].isValid ).toBe( true ); + expect( transformed[ 0 ].attributes.height ).toBe( 200 ); + } ); + + it( 'should transform to core/separator block', () => { + const block = createBlock( name ); + const transformed = switchToBlockType( block, 'core/separator' ); + + expect( transformed[ 0 ].isValid ).toBe( true ); + } ); +} );