Skip to content

Commit a2d83ac

Browse files
authored
Merge pull request #65 from contentstack/fix/DX-202-class-attribute-fix
fix: class to class-name changed
2 parents 0a83383 + 7a0c84f commit a2d83ac

File tree

8 files changed

+82
-148
lines changed

8 files changed

+82
-148
lines changed

__test__/gql/gql-json-to-html.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ describe('Node parser reference content', () => {
120120

121121
GQL.jsonToHTML({entry, paths})
122122

123-
expect(entry[0].single_rte).toEqual('<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
124-
expect(entry[0].multiple_rte).toEqual(['<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>'])
123+
expect(entry[0].single_rte).toEqual('<a class=\"embedded-entry\" href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
124+
expect(entry[0].multiple_rte).toEqual(['<a class=\"embedded-entry\" href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>'])
125125
done()
126126
})
127127

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const plainTextHtmlWithId = "<p class=\"class_p\"><em><u><span id=\"blue\">data<
2020
const htmlTextIdInAttrs = "<p id=\"id_p\"><em><u>data</u></em></p>"
2121
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>"
2222
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>"
23-
const referenceObjHtml = "<p><a href=\"/test\" target=\"_self\">Embed entry as a link</a></p><p><a href=\"/entry-3\" target=\"_blank\">Open entry as a link in new tab</a></p><p><a href=\"/entry-2\" target=\"_self\">Bold entry</a></p><p><a href=\"/entry-4\" target=\"_blank\"><strong>Bold entry open in new tab</strong></a></p>"
24-
const referenceObjHtmlBlock = "<p><a href=\"/Test\" target=\"_self\">Embed entry as a link</a></p><p><a href=\"undefined\" target=\"_blank\">Embed entry as a link open in new tab</a></p><ul><li><a href=\"undefined\" target=\"_self\">Entry as a link</a></li><li><a href=\"undefined\" target=\"_blank\">Open entry as a link in new tab</a></li><li><a href=\"undefined\" target=\"_self\"><strong><u>Entry as a link bold</u></strong></a></li><li><a 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>"
23+
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>"
24+
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>"
2525
export {
2626
h1Html,
2727
h2Html,

__test__/mock/json-element-mock.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const orderListJson = {
204204
"style": {
205205
"text-align": "justify"
206206
},
207-
"class": "class",
207+
"class-name": "class",
208208
"redactor-attributes": {}
209209
},
210210
"uid": "160bbd7430b98bd3d996",
@@ -261,7 +261,7 @@ const orderListJson = {
261261
}
262262
],
263263
"id": "7f413d448a",
264-
"attrs": {class: "table", id: "table_id"}
264+
"attrs": {"class-name": "table", "id": "table_id"}
265265
}
266266
],
267267
type: "doc"
@@ -582,7 +582,7 @@ const unorderListJson = {
582582
}
583583
],
584584
"id": "b083fa46ef899420ab19",
585-
"attrs": {class: "table", id: "table_id"}
585+
"attrs": {"class-name": "table", id: "table_id"}
586586
}
587587
],
588588
type: "doc"
@@ -719,7 +719,7 @@ const tableJson = {
719719
"uid": "b9082",
720720
"type": "thead",
721721
"attrs": {
722-
"class": "class"
722+
"class-name": "class"
723723
},
724724
"children": [
725725
{
@@ -768,14 +768,14 @@ const tableJson = {
768768
{
769769
"type": "tbody",
770770
"attrs": {
771-
"class": "class",
771+
"class-name": "class",
772772
"id":"id"
773773
},
774774
"children": [
775775
{
776776
"type": "tr",
777777
"attrs": {
778-
"class": "class",
778+
"class-name": "class",
779779
"id":"id"},
780780
"children": [
781781
{
@@ -798,7 +798,7 @@ const tableJson = {
798798
{
799799
"type": "td",
800800
"attrs": {
801-
"class": "class",
801+
"class-name": "class",
802802
"id":"id"},
803803
"children": [
804804
{
@@ -847,7 +847,7 @@ const tableJson = {
847847
{
848848
"type": "p",
849849
"attrs": {
850-
"class": "class"
850+
"class-name": "class"
851851
},
852852
"children": [
853853
{
@@ -996,7 +996,7 @@ const styleinPJson = {
996996
attrs: {
997997
url: 'example.com',
998998
target: '_blank',
999-
"class": "class"
999+
"class-name": "class"
10001000
},
10011001
children: [ { text: 'Example' } ]
10021002
},
@@ -1355,7 +1355,7 @@ const entryJsonRteWithClass = {
13551355
"children": [
13561356
{
13571357
"type": "p",
1358-
"attrs": {class: "class_p"},
1358+
"attrs": {"class-name": "class_p"},
13591359
"uid": "",
13601360
"children": [
13611361
{
@@ -1404,7 +1404,7 @@ const entryJsonRteWithId = {
14041404
"children": [
14051405
{
14061406
"type": "p",
1407-
"attrs": {class: "class_p"},
1407+
"attrs": {"class-name": "class_p"},
14081408
"uid": "",
14091409
"children": [
14101410
{
@@ -1459,7 +1459,7 @@ const jsonRteClassAndIdAttrs = {
14591459
"children": [
14601460
{
14611461
"type": "a",
1462-
"attrs": {"href": "LINK.com", class: "class_a", id: "id_p"},
1462+
"attrs": {"href": "LINK.com", "class-name": "class_a", id: "id_p"},
14631463
"uid": "",
14641464
"children": [
14651465
{
@@ -1470,7 +1470,7 @@ const jsonRteClassAndIdAttrs = {
14701470
{
14711471
"type": "img",
14721472
"attrs": {
1473-
class: "class_img",
1473+
"class-name": "class_img",
14741474
id: "id_img",
14751475
"src": "https://dummyImage.url/Donald.jog.png",
14761476
"width": 33.69418132611637,
@@ -1487,7 +1487,7 @@ const jsonRteClassAndIdAttrs = {
14871487
},
14881488
{
14891489
"type": "h1",
1490-
"attrs": {class: "class_h1", id: "id_h1"},
1490+
"attrs": {"class-name": "class_h1", id: "id_h1"},
14911491
"uid": "",
14921492
"children": [
14931493
{
@@ -1497,7 +1497,7 @@ const jsonRteClassAndIdAttrs = {
14971497
},
14981498
{
14991499
"type": "h2",
1500-
"attrs": {class: "class_h2", id: "id_h2"},
1500+
"attrs": {"class-name": "class_h2", id: "id_h2"},
15011501
"uid": "",
15021502
"children": [
15031503
{
@@ -1507,7 +1507,7 @@ const jsonRteClassAndIdAttrs = {
15071507
},
15081508
{
15091509
"type": "h3",
1510-
"attrs": {class: "class_h3", id: "id_h3"},
1510+
"attrs": {"class-name": "class_h3", id: "id_h3"},
15111511
"uid": "",
15121512
"children": [
15131513
{
@@ -1517,7 +1517,7 @@ const jsonRteClassAndIdAttrs = {
15171517
},
15181518
{
15191519
"type": "h4",
1520-
"attrs": {class: "class_h4", id: "id_h4"},
1520+
"attrs": {"class-name": "class_h4", id: "id_h4"},
15211521
"uid": "",
15221522
"children": [
15231523
{
@@ -1527,7 +1527,7 @@ const jsonRteClassAndIdAttrs = {
15271527
},
15281528
{
15291529
"type": "h5",
1530-
"attrs": {class: "class_h5", id: "id_h5"},
1530+
"attrs": {"class-name": "class_h5", id: "id_h5"},
15311531
"uid": "",
15321532
"children": [
15331533
{
@@ -1537,7 +1537,7 @@ const jsonRteClassAndIdAttrs = {
15371537
},
15381538
{
15391539
"type": "h6",
1540-
"attrs": {class: "class_h6", id: "id_h6"},
1540+
"attrs": {"class-name": "class_h6", id: "id_h6"},
15411541
"uid": "",
15421542
"children": [
15431543
{

__test__/reference-to-html.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('Reference Node To HTML', () => {
7878
const resultHTML = referenceToHTML(node, renderOption, (metadata: Metadata) => {
7979
return findEmbeddedItems(metadata, embeddedEntryJsonEntry)[0]
8080
})
81-
expect(resultHTML).toEqual('<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
81+
expect(resultHTML).toEqual('<a class=\"embedded-entry\" href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
8282
done()
8383
})
8484

@@ -157,7 +157,7 @@ describe('Reference Node To HTML', () => {
157157
const node = assetReferenceJson.children[0] as unknown as Node
158158

159159
const resultHTML = referenceToHTML(node, defaultNodeOption)
160-
expect(resultHTML).toEqual('<img id=\"img_id\" src="https://image.url/11.jpg" />')
160+
expect(resultHTML).toEqual('<img class=\"embedded-asset\" id=\"img_id\" src=\"https://image.url/11.jpg\" />')
161161
done()
162162
})
163163

@@ -172,7 +172,7 @@ describe('Reference Node To HTML', () => {
172172
const resultHTML = referenceToHTML(node, renderOption, (metadata: Metadata) => {
173173
return findEmbeddedItems(metadata, { uid: 'uid' })[0]
174174
})
175-
expect(resultHTML).toEqual('<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
175+
expect(resultHTML).toEqual('<a class=\"embedded-entry\" href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
176176
done()
177177
})
178178
})

0 commit comments

Comments
 (0)