Skip to content

Commit

Permalink
Add a basic test for shortcode transformation (#7823)
Browse files Browse the repository at this point in the history
* Add a basic test for shortcode transformation

* Use `createBlock()` to generate a more predictable block
  • Loading branch information
danielbachhuber authored Jul 9, 2018
1 parent 84c1e73 commit fab861a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions blocks/api/raw-handling/test/shortcode-converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* WordPress dependences
*/
import { registerCoreBlocks } from '@wordpress/core-blocks';

/**
* Internal dependencies
*/
import segmentHTMLToShortcodeBlock from '../shortcode-converter';
import { createBlock } from '../../factory';

describe( 'segmentHTMLToShortcodeBlock', () => {
beforeAll( () => {
registerCoreBlocks();
} );

it( 'should convert a standalone shortcode between two paragraphs', () => {
const original = `<p>Foo</p>
[foo bar="apple"]
<p>Bar</p>`;
const transformed = segmentHTMLToShortcodeBlock( original, 0 );
expect( transformed ).toHaveLength( 3 );
expect( transformed[ 0 ] ).toBe( `<p>Foo</p>
` );
const expectedBlock = createBlock( 'core/shortcode', {
text: '[foo bar="apple"]',
} );
// uuid will always be random.
expectedBlock.uid = transformed[ 1 ].uid;
expect( transformed[ 1 ] ).toEqual( expectedBlock );
expect( transformed[ 2 ] ).toBe( `
<p>Bar</p>` );
} );
} );

0 comments on commit fab861a

Please sign in to comment.