From 5c6d335245ce447305d4a6e34657a1fb6178d3ee Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 23 May 2017 08:55:10 -0400 Subject: [PATCH] Remove empty `attributes` from JSON test fixtures Only applies to nested elements, not to blocks themselves. --- blocks/test/fixtures/core-heading-h2-em.json | 1 - blocks/test/fixtures/core-list-ul.json | 7 ------- blocks/test/fixtures/core-preformatted.json | 4 +--- blocks/test/fixtures/core-text-multi-paragraph.json | 4 ---- blocks/test/full-content.js | 5 ++++- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/blocks/test/fixtures/core-heading-h2-em.json b/blocks/test/fixtures/core-heading-h2-em.json index 77be93a3262acd..d42b8a4d12b6d0 100644 --- a/blocks/test/fixtures/core-heading-h2-em.json +++ b/blocks/test/fixtures/core-heading-h2-em.json @@ -7,7 +7,6 @@ "The ", { "type": "em", - "attributes": {}, "children": "Inserter" }, " Tool" diff --git a/blocks/test/fixtures/core-list-ul.json b/blocks/test/fixtures/core-list-ul.json index 4e43c9815a3b7d..5c39a4b34faa25 100644 --- a/blocks/test/fixtures/core-list-ul.json +++ b/blocks/test/fixtures/core-list-ul.json @@ -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 :)" diff --git a/blocks/test/fixtures/core-preformatted.json b/blocks/test/fixtures/core-preformatted.json index d9e4a75633f4b7..083a138132eb07 100644 --- a/blocks/test/fixtures/core-preformatted.json +++ b/blocks/test/fixtures/core-preformatted.json @@ -7,13 +7,11 @@ "Some ", { "type": "em", - "attributes": {}, "children": "preformatted" }, " text...", { - "type": "br", - "attributes": {} + "type": "br" }, "And more!" ] diff --git a/blocks/test/fixtures/core-text-multi-paragraph.json b/blocks/test/fixtures/core-text-multi-paragraph.json index 22b6cc32e5c992..e1afda57342e00 100644 --- a/blocks/test/fixtures/core-text-multi-paragraph.json +++ b/blocks/test/fixtures/core-text-multi-paragraph.json @@ -6,12 +6,10 @@ "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." @@ -19,12 +17,10 @@ }, { "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..." diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index c32dcc4da6af14..b2e88941aa4ca6 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -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 ); }