From 0d1b0e8d2e1f3cfc9e99369118c0cc13cf114679 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Mon, 18 Nov 2019 18:01:56 +0000 Subject: [PATCH] Tests: Raw Handling: Cover Shortcode's `isMatch` --- test/integration/blocks-raw-handling.test.js | 34 +++++++++++++++++++ .../fixtures/shortcode-matching-in.html | 3 ++ .../fixtures/shortcode-matching-out.html | 7 ++++ 3 files changed, 44 insertions(+) create mode 100644 test/integration/fixtures/shortcode-matching-in.html create mode 100644 test/integration/fixtures/shortcode-matching-out.html diff --git a/test/integration/blocks-raw-handling.test.js b/test/integration/blocks-raw-handling.test.js index 228c6588ef96b..6f3193a2da741 100644 --- a/test/integration/blocks-raw-handling.test.js +++ b/test/integration/blocks-raw-handling.test.js @@ -11,6 +11,7 @@ import { getBlockContent, pasteHandler, rawHandler, + registerBlockType, serialize, } from '@wordpress/blocks'; import { registerCoreBlocks } from '@wordpress/block-library'; @@ -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', () => { @@ -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` ) ); diff --git a/test/integration/fixtures/shortcode-matching-in.html b/test/integration/fixtures/shortcode-matching-in.html new file mode 100644 index 0000000000000..f5b46fa16abc9 --- /dev/null +++ b/test/integration/fixtures/shortcode-matching-in.html @@ -0,0 +1,3 @@ +

[gallery ids="40,41,42"]

+

[gallery ids="1000"]

+

[gallery ids="42"]

diff --git a/test/integration/fixtures/shortcode-matching-out.html b/test/integration/fixtures/shortcode-matching-out.html new file mode 100644 index 0000000000000..02599dea66294 --- /dev/null +++ b/test/integration/fixtures/shortcode-matching-out.html @@ -0,0 +1,7 @@ + + + + + + +