Skip to content

Commit

Permalink
Remove wrapper from image raw transform; Added test cases; (#4740)
Browse files Browse the repository at this point in the history
With the latest code changes the wrapper in the image raw transform is no longer required. Added integration tests cases to avoid regressing on image raw handling.
  • Loading branch information
jorgefilipecosta authored Feb 8, 2018
1 parent 61cf994 commit e2c824a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions blocks/api/raw-handling/test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const types = [
'ms-word-online',
'evernote',
'iframe-embed',
'one-image',
'two-images',
];

describe( 'raw handling: integration', () => {
Expand Down
1 change: 1 addition & 0 deletions blocks/api/raw-handling/test/integration/one-image-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img class="alignnone wp-image-5114 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" width="300" height="137" />
3 changes: 3 additions & 0 deletions blocks/api/raw-handling/test/integration/one-image-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" /></figure>
<!-- /wp:image -->
4 changes: 4 additions & 0 deletions blocks/api/raw-handling/test/integration/two-images-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<img class="alignnone wp-image-5114 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" width="300" height="137" />


<img class="alignnone wp-image-5109 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-05-2017-17-52-09-9-300x248.gif" alt="" width="300" height="248" />
7 changes: 7 additions & 0 deletions blocks/api/raw-handling/test/integration/two-images-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" /></figure>
<!-- /wp:image -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-05-2017-17-52-09-9-300x248.gif" alt="" /></figure>
<!-- /wp:image -->
6 changes: 2 additions & 4 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ export const settings = {
return tag === 'img' || ( hasImage && tag === 'figure' );
},
transform( node ) {
const targetNode = node.parentNode.querySelector( 'figure,img' );
const matches = /align(left|center|right)/.exec( targetNode.className );
const matches = /align(left|center|right)/.exec( node.className );
const align = matches ? matches[ 1 ] : undefined;
const blockType = getBlockType( 'core/image' );
const attributes = getBlockAttributes( blockType, targetNode.outerHTML, { align } );

const attributes = getBlockAttributes( blockType, node.outerHTML, { align } );
return createBlock( 'core/image', attributes );
},
},
Expand Down

0 comments on commit e2c824a

Please sign in to comment.