New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix paste attributes after #1902 #2408
Conversation
@aduth Should all of these attributes have defaults set? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, I'd wondered if we just need to feed in the attributes as source
instead of defining their full type, since the full type is essentially a duplicate of what should already exist in the destination block type.
diff --git a/blocks/api/paste.js b/blocks/api/paste.js
index 84285728..76e53d3c 100644
--- a/blocks/api/paste.js
+++ b/blocks/api/paste.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
-import { find, get, flowRight as compose } from 'lodash';
+import { find, get, flowRight as compose, mapValues } from 'lodash';
/**
* WordPress dependencies
@@ -96,7 +96,7 @@ export default function( nodes ) {
const attributes = getSourcedAttributes(
node.outerHTML,
- transform.attributes,
+ mapValues( transform.attributes, ( source ) => ( { source } ) ),
);
return createBlock( blockType.name, attributes );
Can we add some unit tests for paste block transforms to capture these issues?
Codecov Report
@@ Coverage Diff @@
## master #2408 +/- ##
==========================================
+ Coverage 25.9% 26.45% +0.54%
==========================================
Files 157 157
Lines 4853 4858 +5
Branches 822 824 +2
==========================================
+ Hits 1257 1285 +28
+ Misses 3035 3017 -18
+ Partials 561 556 -5
Continue to review full report at Codecov.
|
What about cases where they don't map? I guess we should think of it when it pops up then. |
Also, it should be responsibility of |
Why shouldn't we then just loop through |
Maybe this could work if we add |
Okay, maybe not, there will always be strange cases we'll need to handle. Let's just add what you suggested. |
99617eb
to
557caa2
Compare
blocks/api/test/paste.js
Outdated
@@ -45,3 +48,44 @@ describe( 'normaliseToBlockLevelNodes', () => { | |||
} ); | |||
} ); | |||
|
|||
describe( 'paste', () => { | |||
registerBlockType( 'test/small', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the block registry is global, we should make sure to reset to its original state after our tests are done.
Example from serializer tests:
gutenberg/blocks/api/test/serializer.js
Lines 20 to 24 in 77620b2
afterEach( () => { | |
getBlockTypes().forEach( block => { | |
unregisterBlockType( block.name ); | |
} ); | |
} ); |
Yeah, in the case of the raw transforms, if we know that the original content is a match, we shouldn't need to redefine attributes and instead just trigger the default parsing of I think I might have been a little overreaching with the renaming of |
557caa2
to
867e4f8
Compare
Sounds good. Changed it. |
blocks/api/test/paste.js
Outdated
equal( pastedBlock.attributes.content, '<big>test</big>' ); | ||
} ); | ||
|
||
afterAll( () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Conventionally setup and teardown occurs together before any test cases.
No description provided.