Skip to content

Commit

Permalink
Tests: Raw Handling: Cover Shortcode's isMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Nov 19, 2019
1 parent d238e4a commit 0d1b0e8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/integration/blocks-raw-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getBlockContent,
pasteHandler,
rawHandler,
registerBlockType,
serialize,
} from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
Expand All @@ -24,6 +25,38 @@ describe( 'Blocks raw handling', () => {
// Load all hooks that modify blocks
require( '../../packages/editor/src/hooks' );
registerCoreBlocks();
registerBlockType( 'test/gallery', {
title: 'Test Gallery',
category: 'common',
attributes: {
ids: {
type: 'array',
default: [],
},
},
transforms: {
from: [
{
type: 'shortcode',
tag: 'gallery',
isMatch( { named: { ids } } ) {
return ids.indexOf( 42 ) > -1;
},
attributes: {
ids: {
type: 'array',
shortcode: ( { named: { ids } } ) =>
ids.split( ',' ).map( ( id ) => (
parseInt( id, 10 )
) ),
},
},
priority: 9,
},
],
},
save: () => null,
} );
} );

it( 'should filter inline content', () => {
Expand Down Expand Up @@ -249,6 +282,7 @@ describe( 'Blocks raw handling', () => {
'wordpress',
'gutenberg',
'caption-shortcode',
'shortcode-matching',
].forEach( ( type ) => {
it( type, () => {
const HTML = readFile( path.join( __dirname, `fixtures/${ type }-in.html` ) );
Expand Down
3 changes: 3 additions & 0 deletions test/integration/fixtures/shortcode-matching-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>[gallery ids="40,41,42"]</p>
<p>[gallery ids="1000"]</p>
<p>[gallery ids="42"]</p>
7 changes: 7 additions & 0 deletions test/integration/fixtures/shortcode-matching-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- wp:test/gallery {"ids":[40,41,42]} /-->

<!-- wp:gallery {"ids":[1000],"columns":3,"linkTo":"attachment"} -->
<figure class="wp-block-gallery columns-3 is-cropped"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><img data-id="1000" class="wp-image-1000"/></figure></li></ul></figure>
<!-- /wp:gallery -->

<!-- wp:test/gallery {"ids":[42]} /-->

0 comments on commit 0d1b0e8

Please sign in to comment.