Skip to content

Commit

Permalink
Remove empty attributes from JSON test fixtures
Browse files Browse the repository at this point in the history
Only applies to nested elements, not to blocks themselves.
  • Loading branch information
nylen committed May 23, 2017
1 parent 4333b90 commit 5c6d335
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 16 deletions.
1 change: 0 additions & 1 deletion blocks/test/fixtures/core-heading-h2-em.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"The ",
{
"type": "em",
"attributes": {},
"children": "Inserter"
},
" Tool"
Expand Down
7 changes: 0 additions & 7 deletions blocks/test/fixtures/core-list-ul.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,30 @@
"values": [
{
"type": "li",
"attributes": {},
"children": "Text & Headings"
},
{
"type": "li",
"attributes": {},
"children": "Images & Videos"
},
{
"type": "li",
"attributes": {},
"children": "Galleries"
},
{
"type": "li",
"attributes": {},
"children": "Embeds, like YouTube, Tweets, or other WordPress posts."
},
{
"type": "li",
"attributes": {},
"children": "Layout blocks, like Buttons, Hero Images, Separators, etc."
},
{
"type": "li",
"attributes": {},
"children": [
"And ",
{
"type": "em",
"attributes": {},
"children": "Lists"
},
" like this one of course :)"
Expand Down
4 changes: 1 addition & 3 deletions blocks/test/fixtures/core-preformatted.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"Some ",
{
"type": "em",
"attributes": {},
"children": "preformatted"
},
" text...",
{
"type": "br",
"attributes": {}
"type": "br"
},
"And more!"
]
Expand Down
4 changes: 0 additions & 4 deletions blocks/test/fixtures/core-text-multi-paragraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@
"content": [
{
"type": "p",
"attributes": {},
"children": [
"The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of ",
{
"type": "em",
"attributes": {},
"children": "pieces of content"
},
"—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you'll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting."
]
},
{
"type": "p",
"attributes": {},
"children": [
"What you are reading now is a ",
{
"type": "strong",
"attributes": {},
"children": "text block"
},
", the most basic block of all. A text block can have multiple paragraphs, if that's how you prefer to write your posts. But you can also split it by hitting enter twice. Once blocks are split they get their own controls to be moved freely around the post..."
Expand Down
5 changes: 4 additions & 1 deletion blocks/test/full-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ function normalizeReactTree( element ) {
if ( isObject( element ) ) {
const toReturn = {
type: element.type,
attributes: omit( element.props, 'children' ),
};
const attributes = omit( element.props, 'children' );
if ( Object.keys( attributes ).length ) {
toReturn.attributes = attributes;
}
if ( element.props.children ) {
toReturn.children = normalizeReactTree( element.props.children );
}
Expand Down

0 comments on commit 5c6d335

Please sign in to comment.