Skip to content

Commit f5e87e2

Browse files
committed
fix: update link rendering to omit href attribute when undefined
1 parent 203a5e5 commit f5e87e2

File tree

9 files changed

+365
-31
lines changed

9 files changed

+365
-31
lines changed

__test__/default-node-options.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('Default node render options - Missing attrs cases', () => {
267267
children: []
268268
} as unknown as Node
269269
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodeNoAttrs, next)
270-
expect(renderString).toEqual('<a href="">text</a>')
270+
expect(renderString).toEqual('<a>text</a>')
271271
done()
272272
})
273273

@@ -278,7 +278,7 @@ describe('Default node render options - Missing attrs cases', () => {
278278
children: []
279279
} as Node
280280
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodePartialAttrs, next)
281-
expect(renderString).toEqual('<a style="color: red;" href="">text</a>')
281+
expect(renderString).toEqual('<a style="color: red;">text</a>')
282282
done()
283283
})
284284

@@ -455,7 +455,7 @@ describe('Default node render options - Missing attrs cases', () => {
455455
children: []
456456
} as Node
457457
const renderString = (defaultNodeOption.reference as RenderNode)(referenceLinkNoHref, next)
458-
expect(renderString).toEqual('<a href="">text</a>')
458+
expect(renderString).toEqual('<a>text</a>')
459459
done()
460460
})
461461

@@ -466,7 +466,7 @@ describe('Default node render options - Missing attrs cases', () => {
466466
children: []
467467
} as Node
468468
const renderString = (defaultNodeOption.reference as RenderNode)(referenceAssetLinkNoHref, next)
469-
expect(renderString).toEqual('<a href="" type="asset" content-type-uid="sys_assets" sys-style-type="download">text</a>')
469+
expect(renderString).toEqual('<a type="asset" content-type-uid="sys_assets" sys-style-type="download">text</a>')
470470
done()
471471
})
472472

__test__/default-options.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Default Option test', () => {
2727
it('Default options Entry with only uid test', done => {
2828
expect(entryBlockFunction(entryContentBlank, embedAttributes)).toEqual(`<div><p>${entryContentBlank.uid}</p><p>Content type: <span>${entryContentBlank._content_type_uid}</span></p></div>`)
2929
expect(entryInlineFunction(entryContentBlank, embedAttributes)).toEqual(`<span>${entryContentBlank.uid}</span>`)
30-
expect(entryLinkFunction(entryContentBlank, embedAttributes)).toEqual(`<a href="undefined">${entryContentBlank.uid}</a>`)
30+
expect(entryLinkFunction(entryContentBlank, embedAttributes)).toEqual(`<a>${entryContentBlank.uid}</a>`)
3131
done()
3232
})
3333

@@ -41,7 +41,7 @@ describe('Default Option test', () => {
4141
it('Default options Entry with only uid, title test', done => {
4242
expect(entryBlockFunction(entryContentTitle, embedAttributes)).toEqual(`<div><p>${entryContentTitle.title}</p><p>Content type: <span>${entryContentTitle._content_type_uid}</span></p></div>`)
4343
expect(entryInlineFunction(entryContentTitle, embedAttributes)).toEqual(`<span>${entryContentTitle.title}</span>`)
44-
expect(entryLinkFunction(entryContentTitle, embedAttributes)).toEqual(`<a href="undefined">${entryContentTitle.title}</a>`)
44+
expect(entryLinkFunction(entryContentTitle, embedAttributes)).toEqual(`<a>${entryContentTitle.title}</a>`)
4545
done()
4646
})
4747

@@ -58,8 +58,8 @@ describe('Default Option test', () => {
5858
})
5959

6060
it('Default options Asset with only uid test', done => {
61-
expect(assetDisplaableFunction(assetContentBlank, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentBlank.uid}" />`)
62-
expect(assetDownloadFunction(assetContentBlank, embedAttributes)).toEqual(`<a href="undefined\">${assetContentBlank.uid}</a>`)
61+
expect(assetDisplaableFunction(assetContentBlank, embedAttributes)).toEqual(`<img alt="${assetContentBlank.uid}" />`)
62+
expect(assetDownloadFunction(assetContentBlank, embedAttributes)).toEqual(`<a>${assetContentBlank.uid}</a>`)
6363
done()
6464
})
6565

@@ -71,8 +71,8 @@ describe('Default Option test', () => {
7171

7272

7373
it('Default options Asset with uid and filename test', done => {
74-
expect(assetDisplaableFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentonlyFileName.filename}" />`)
75-
expect(assetDownloadFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<a href="undefined">${assetContentonlyFileName.uid}</a>`)
74+
expect(assetDisplaableFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<img alt="${assetContentonlyFileName.filename}" />`)
75+
expect(assetDownloadFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<a>${assetContentonlyFileName.uid}</a>`)
7676
done()
7777
})
7878

@@ -83,8 +83,8 @@ describe('Default Option test', () => {
8383
})
8484

8585
it('Default options Asset with uid and title test', done => {
86-
expect(assetDisplaableFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentonlyTitle.title}" />`)
87-
expect(assetDownloadFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<a href="undefined">${assetContentonlyTitle.title || assetContentonlyTitle.uid}</a>`)
86+
expect(assetDisplaableFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<img alt="${assetContentonlyTitle.title}" />`)
87+
expect(assetDownloadFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<a>${assetContentonlyTitle.title || assetContentonlyTitle.uid}</a>`)
8888
done()
8989
})
9090

@@ -101,11 +101,11 @@ describe('Default Option test', () => {
101101

102102
it('Default options Link text test', done => {
103103
expect(entryLinkFunction(entryContentURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
104-
expect(entryLinkFunction(entryContentTitle, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
105-
expect(entryLinkFunction(entryContentBlank, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
104+
expect(entryLinkFunction(entryContentTitle, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
105+
expect(entryLinkFunction(entryContentBlank, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
106106
expect(entryLinkFunction(entryContentTitleURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
107-
expect(assetDisplaableFunction(assetContentBlank, embedAttributesText)).toEqual(`<img src="undefined" alt="${linkText}" />`)
108-
expect(assetDownloadFunction(assetContentBlank, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
107+
expect(assetDisplaableFunction(assetContentBlank, embedAttributesText)).toEqual(`<img alt="${linkText}" />`)
108+
expect(assetDownloadFunction(assetContentBlank, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
109109
done()
110110
})
111111
})

__test__/mock/entry-mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,6 @@ export const entrymultipleRTERenderOption = `<div>
644644
<MYCONTENT><div><p>entry_uid_21</p><p>Content type: <span>1234</span></p></div>
645645
<span>entry_uid_21</span>
646646
<p><br><br></p>
647-
<img src=\"undefined\" alt=\"asset_uid_12\" /></MYCONTENT>
647+
<img alt=\"asset_uid_12\" /></MYCONTENT>
648648
</div>
649649
<p></p>`

__test__/mock/json-element-mock-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const htmlTextIdInAttrs = "<p id=\"id_p\"><em><u>data</u></em></p>"
2222
const classAndIdAttrsHtml = "<a class=\"class_a\" id=\"id_p\" href=\"LINK.com\">link</a><img class=\"class_img\" id=\"id_img\" src=\"https://dummyImage.url/Donald.jog.png\" /><h1 class=\"class_h1\" id=\"id_h1\">heading1</h1><h2 class=\"class_h2\" id=\"id_h2\">heading2</h2><h3 class=\"class_h3\" id=\"id_h3\">heading3</h3><h4 class=\"class_h4\" id=\"id_h4\">heading4</h4><h5 class=\"class_h5\" id=\"id_h5\">heading5</h5><h6 class=\"class_h6\" id=\"id_h6\">heading6</h6>"
2323
const styleObjHtml = "<h1 style=\"text-align:justify;\">heading1</h1><h2 style=\"text-align:left;\">heading2</h2><h3 style=\"text-align:right;\">heading3</h3><h4 style=\"text-align:justify;\">heading4</h4><h5 style=\"text-align:justify;\">heading5</h5><h6 style=\"text-align:justify;\">heading6</h6>"
2424
const referenceObjHtml = "<p><a class=\"embedded-entry redactor-component block-entry\" href=\"/test\" target=\"_self\">Embed entry as a link</a></p><p><a class=\"embedded-entry redactor-component block-entry\" href=\"/entry-3\" target=\"_blank\">Open entry as a link in new tab</a></p><p><a class=\"embedded-entry redactor-component block-entry\" href=\"/entry-2\" target=\"_self\">Bold entry</a></p><p><a class=\"embedded-entry redactor-component block-entry\" href=\"/entry-4\" target=\"_blank\"><strong>Bold entry open in new tab</strong></a></p>"
25-
const referenceObjHtmlBlock = "<p><a class=\"embedded-entry redactor-component block-entry\" href=\"/Test\" target=\"_self\">Embed entry as a link</a></p><p><a class=\"embedded-entry redactor-component block-entry\" href=\"undefined\" target=\"_blank\">Embed entry as a link open in new tab</a></p><ul><li><a class=\"embedded-entry redactor-component block-entry\" href=\"undefined\" target=\"_self\">Entry as a link</a></li><li><a class=\"embedded-entry redactor-component block-entry\" href=\"undefined\" target=\"_blank\">Open entry as a link in new tab</a></li><li><a class=\"embedded-entry redactor-component block-entry\" href=\"undefined\" target=\"_self\"><strong><u>Entry as a link bold</u></strong></a></li><li><a class=\"embedded-entry redactor-component block-entry\" href=\"khjgf\" target=\"_blank\"><strong><u>Open bold entry as a link in new tab </u></strong></a></li><li><a href=\"https://\" target=\"_self\"><strong><u>Link URL</u></strong></a></li><li><a href=\"https://\" target=\"_blank\"><strong><u>Open link in new tab</u></strong></a></li></ul>"
25+
const referenceObjHtmlBlock = "<p><a class=\"embedded-entry redactor-component block-entry\" href=\"/Test\" target=\"_self\">Embed entry as a link</a></p><p><a class=\"embedded-entry redactor-component block-entry\" target=\"_blank\">Embed entry as a link open in new tab</a></p><ul><li><a class=\"embedded-entry redactor-component block-entry\" target=\"_self\">Entry as a link</a></li><li><a class=\"embedded-entry redactor-component block-entry\" target=\"_blank\">Open entry as a link in new tab</a></li><li><a class=\"embedded-entry redactor-component block-entry\" target=\"_self\"><strong><u>Entry as a link bold</u></strong></a></li><li><a class=\"embedded-entry redactor-component block-entry\" href=\"khjgf\" target=\"_blank\"><strong><u>Open bold entry as a link in new tab </u></strong></a></li><li><a href=\"https://\" target=\"_self\"><strong><u>Link URL</u></strong></a></li><li><a href=\"https://\" target=\"_blank\"><strong><u>Open link in new tab</u></strong></a></li></ul>"
2626
const imagetags = "<figure style=\"text-align:right;max-width:137px;float:right;width:137px;max-height:257px;height:257px;\"><a href=\"https://batman.com\" target=\"_blank\"><img asset_uid=\"asset-UID\" class=\"embedded-asset\" src=\"https://images.contentstack.io/v3/assets/api-key/asset-UID/random-uid/batman.png\" alt=\"batman\" target=\"_blank\" style=\"text-align:right;max-width:137px;float:right;width:137px;max-height:257px;height:257px;\" /></a><figcaption>The Batman</figcaption></figure>"
2727
const escapeHtml = "<p>&lt;p&gt;Welcome to Contentstack! &lt;script&gt;console.log(/&quot;Hello from Contentstack!/&quot;);&lt;/script&gt; Explore our platform to create, manage, and publish content seamlessly.&lt;/p&gt;</p>"
2828
const breakTestHtml = "<p>Normal text with <br />break tag after break.</p>"

0 commit comments

Comments
 (0)