From abbd8237174ba3565d5af149c846ca99ada9d06b Mon Sep 17 00:00:00 2001 From: Gervwyk Date: Mon, 23 Aug 2021 07:44:51 +0200 Subject: [PATCH] fix(blockTools): RenderHtml to return span by default, closes #775 #777 --- packages/blockTools/src/RenderHtml.js | 25 +++++++--- packages/blockTools/src/RenderHtml.test.js | 55 +++++++++++----------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/packages/blockTools/src/RenderHtml.js b/packages/blockTools/src/RenderHtml.js index d7b6c5891..cdebec1ea 100644 --- a/packages/blockTools/src/RenderHtml.js +++ b/packages/blockTools/src/RenderHtml.js @@ -34,17 +34,30 @@ class RenderHtml extends React.Component { } render() { - const { id, methods, style } = this.props; + const { div, html, id, methods, style } = this.props; + if (!html) { + return ''; + } + if (div) { + return ( +
{ + this.div = el; + }} + className={methods.makeCssClass(style)} + /> + ); + } return ( -
{ - if (el) { - this.div = el; - } + this.div = el; }} - className={methods.makeCssClass([{ display: 'inline-block' }, style])} + className={methods.makeCssClass(style)} /> ); } diff --git a/packages/blockTools/src/RenderHtml.test.js b/packages/blockTools/src/RenderHtml.test.js index 76347ca57..53db87990 100644 --- a/packages/blockTools/src/RenderHtml.test.js +++ b/packages/blockTools/src/RenderHtml.test.js @@ -36,59 +36,45 @@ test('Render default', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); await wrapper.instance().componentDidUpdate(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); }); test('Render default and id', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); }); test('Render string', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
A string value
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`"A string value"`); }); test('Render number', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
123
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`"123"`); }); test('Render boolean', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); }); test('Render null', async () => { const wrapper = await mount(); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); }); test('Render html', async () => { @@ -101,7 +87,22 @@ test('Render html', async () => { await wrapper.instance().componentDidMount(); await wrapper.update(); expect(wrapper.html()).toMatchInlineSnapshot( - `"
Content green background
"` + `"
Content green background
"` + ); +}); + +test('Render html div', async () => { + const wrapper = await mount( + Content green background
'} + methods={methods} + div={true} + /> + ); + await wrapper.instance().componentDidMount(); + await wrapper.update(); + expect(wrapper.html()).toMatchInlineSnapshot( + `"
Content green background
"` ); }); @@ -116,7 +117,7 @@ test('Render html and style', async () => { await wrapper.instance().componentDidMount(); await wrapper.update(); expect(wrapper.html()).toMatchInlineSnapshot( - `"
Content green background
"` + `"
Content green background
"` ); }); @@ -131,9 +132,7 @@ test('Render html iframe', async () => { ); await wrapper.instance().componentDidMount(); await wrapper.update(); - expect(wrapper.html()).toMatchInlineSnapshot( - `"
"` - ); + expect(wrapper.html()).toMatchInlineSnapshot(`""`); }); test('Render bad html', async () => { @@ -156,7 +155,7 @@ test('Render bad html', async () => { await wrapper.instance().componentDidMount(); await wrapper.update(); expect(wrapper.html()).toMatchInlineSnapshot(` - "
+ "

Link

Lowdefy link Description @@ -166,6 +165,6 @@ test('Render bad html', async () => {

-
" + " `); });