Skip to content

Commit db193bc

Browse files
authored
Merge pull request #67 from contentstack/next
Feat: updateAssetURLForGQL added
2 parents 0019c7d + c1c64b1 commit db193bc

14 files changed

+323
-158
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.5) (2024-05-31)
4+
- Feat: updateAssetURLForGQL added
5+
36
## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.4) (2024-05-13)
47
- Fixes for vulnerability issues related to regular expression and options
58

__test__/default-node-options.test.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const node: Node = {
1414

1515
const imgNode: Node = {
1616
type: NodeType.IMAGE,
17-
attrs: {src: "https://image.url/Donald.jog.png"},
17+
attrs: {src: "https://image.url/Donald.jog.png", style: "color: red;"},
1818
children:[]
1919

2020
}
@@ -35,7 +35,7 @@ const linkNode: Node = {
3535

3636
const linkNodeWithURL: Node = {
3737
type: NodeType.LINK,
38-
attrs: {url: "https://image.url/Donald.jog.png"},
38+
attrs: {url: "https://image.url/Donald.jog.png", style: "color: red;"},
3939
children:[]
4040

4141
}
@@ -51,6 +51,26 @@ const embedNodeWithURL: Node = {
5151
children: []
5252
}
5353

54+
const tableDataNode: Node = {
55+
type: NodeType.TABLE_DATA,
56+
attrs: {
57+
rowSpan: 2,
58+
colSpan: 2,
59+
'redactor-attributes': { colSpan: 2, rowSpan: 2 }
60+
},
61+
children: []
62+
}
63+
64+
const tableHeadNode: Node = {
65+
type: NodeType.TABLE_HEAD,
66+
attrs: {
67+
rowSpan: 2,
68+
colSpan: 2,
69+
'redactor-attributes': { colSpan: 2, rowSpan: 2 }
70+
},
71+
children: []
72+
}
73+
5474
describe('Default node render options', () => {
5575
it('Should return document string', done => {
5676
const renderString = (defaultNodeOption[NodeType.DOCUMENT] as RenderNode)(node, next)
@@ -66,14 +86,14 @@ describe('Default node render options', () => {
6686
let renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNode, next)
6787
expect(renderString).toEqual(`<a href="${linkNode.attrs.href}">text</a>`)
6888
renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNode, next)
69-
expect(renderString).toEqual('<img src="https://image.url/Donald.jog.png" />text')
89+
expect(renderString).toEqual('<img style=\"color: red;\" src="https://image.url/Donald.jog.png" />text')
7090
renderString = (defaultNodeOption[NodeType.EMBED] as RenderNode)(embedNode, next)
7191
expect(renderString).toEqual('<iframe src="https://www.youtube.com/">text</iframe>')
7292
done()
7393
})
7494
it('Should return link string with url as attr', done => {
7595
let renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodeWithURL, next)
76-
expect(renderString).toEqual(`<a href="${linkNodeWithURL.attrs.url}">text</a>`)
96+
expect(renderString).toEqual(`<a style=\"color: red;\" href="${linkNodeWithURL.attrs.url}">text</a>`)
7797
renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNodeWithURL, next)
7898
expect(renderString).toEqual(`<img src="${imgNodeWithURL.attrs.url}" />text`)
7999
renderString = (defaultNodeOption[NodeType.EMBED] as RenderNode)(embedNodeWithURL, next)
@@ -134,11 +154,11 @@ describe('Default node render options', () => {
134154
renderString = (defaultNodeOption[NodeType.TABLE_ROW] as RenderNode)(node, next)
135155
expect(renderString).toEqual('<tr>text</tr>')
136156

137-
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(node, next)
138-
expect(renderString).toEqual('<th>text</th>')
157+
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadNode, next)
158+
expect(renderString).toEqual('<th rowspan=\"2\" colspan=\"2\">text</th>')
139159

140-
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(node, next)
141-
expect(renderString).toEqual('<td>text</td>')
160+
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNode, next)
161+
expect(renderString).toEqual('<td rowspan=\"2\" colspan=\"2\">text</td>')
142162

143163
done()
144164
})

__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

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
export const gqlResponseForAssetUpdate = {
2+
"data": {
3+
"page_json_rte": {
4+
"title": "My First JSON-Rte Entry",
5+
"system": {
6+
"content_type_uid": "page_json_rte",
7+
"uid": "uid_page_json_rte"
8+
},
9+
"rte_2": {
10+
"embedded_itemsConnection": {
11+
"edges": [
12+
{
13+
"node": {
14+
"title": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
15+
"url": "https://images.contentstack.io/v3/assets/api_key/asset_uid_1341/66427e3816e6bfae8f58d971/pexels-pixabay-33109.jpg",
16+
"content_type": "image/jpeg",
17+
"filename": "pexels-pixabay-33109.jpg",
18+
"system": {
19+
"uid": "asset_uid_1341"
20+
}
21+
}
22+
}
23+
]
24+
},
25+
"json": {
26+
"type": "doc",
27+
"uid": "rte_uid",
28+
"attrs": {},
29+
"children": [
30+
{
31+
"uid": "rte_node_uid",
32+
"type": "reference",
33+
"attrs": {
34+
"display-type": "display",
35+
"asset-uid": "asset_uid_1341",
36+
"content-type-uid": "sys_assets",
37+
"asset-link": "https://images.contentstack.io/v3/assets/api_key/asset_uid_1341/6502bb17bb60f72316481aaa/FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
38+
"asset-name": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
39+
"asset-type": "image/jpeg",
40+
"type": "asset",
41+
"class-name": "embedded-asset",
42+
"alt": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
43+
"asset-alt": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
44+
"inline": false
45+
},
46+
"children": [
47+
{
48+
"text": ""
49+
}
50+
]
51+
},
52+
{
53+
"type": "p",
54+
"attrs": {},
55+
"uid": "rte_node_2_uid",
56+
"children": [
57+
{
58+
"text": ""
59+
}
60+
]
61+
}
62+
],
63+
"_version": 10
64+
}
65+
}
66+
}
67+
}
68+
}
69+
70+
export const gqlResponseForAssetUpdateWithoutSystemUid = {
71+
"data": {
72+
"page_json_rte": {
73+
"title": "My First JSON-Rte Entry",
74+
"system": {
75+
"content_type_uid": "page_json_rte",
76+
"uid": "uid_page_json_rte"
77+
},
78+
"rte_2": {
79+
"embedded_itemsConnection": {
80+
"edges": [
81+
{
82+
"node": {
83+
"title": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
84+
"url": "https://images.contentstack.io/v3/assets/api_key/asset_uid_1341/66427e3816e6bfae8f58d971/pexels-pixabay-33109.jpg",
85+
"content_type": "image/jpeg",
86+
"filename": "pexels-pixabay-33109.jpg",
87+
}
88+
}
89+
]
90+
},
91+
"json": {
92+
"type": "doc",
93+
"uid": "rte_uid",
94+
"attrs": {},
95+
"children": [
96+
{
97+
"uid": "rte_node_uid",
98+
"type": "reference",
99+
"attrs": {
100+
"display-type": "display",
101+
"asset-uid": "asset_uid_1341",
102+
"content-type-uid": "sys_assets",
103+
"asset-link": "https://images.contentstack.io/v3/assets/api_key/asset_uid_1341/6502bb17bb60f72316481aaa/FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
104+
"asset-name": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
105+
"asset-type": "image/jpeg",
106+
"type": "asset",
107+
"class-name": "embedded-asset",
108+
"alt": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
109+
"asset-alt": "FA23_TJ_FUEL_TJM_DEL_1_STITCHED.jpg",
110+
"inline": false
111+
},
112+
"children": [
113+
{
114+
"text": ""
115+
}
116+
]
117+
},
118+
{
119+
"type": "p",
120+
"attrs": {},
121+
"uid": "rte_node_2_uid",
122+
"children": [
123+
{
124+
"text": ""
125+
}
126+
]
127+
}
128+
],
129+
"_version": 10
130+
}
131+
}
132+
}
133+
}
134+
}

__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,

0 commit comments

Comments
 (0)