From 770c296cd2b6dd706ec01ef8323e9906ded90bee Mon Sep 17 00:00:00 2001 From: Jayesh Deorukhkar Date: Thu, 27 Jun 2024 11:02:10 +0530 Subject: [PATCH 1/4] fix: improper if condition for percentage in image widths --- src/toRedactor.tsx | 4 ++-- test/expectedJson.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/toRedactor.tsx b/src/toRedactor.tsx index 96c5135..6449121 100644 --- a/src/toRedactor.tsx +++ b/src/toRedactor.tsx @@ -375,9 +375,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string if (attrsJson['width']) { let width = attrsJson['width'] if (width.slice(width.length - 1) === '%') { - style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};` - } else { style = `width: ${allattrs['width'] + '%'}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};` + } else { + style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};` } } else { if (allattrs['width']) { diff --git a/test/expectedJson.ts b/test/expectedJson.ts index 1509588..73bdfac 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -615,7 +615,7 @@ export default { ] } ], - "htmlUpdated": "

" + "htmlUpdated": "

" }, "7": { "html": "

this is link

paragraph with class

paragraph with id

", @@ -1909,6 +1909,6 @@ export default { } ] } - } - + } + } \ No newline at end of file From 8aebda7b875fed4dd4f6ea2eead71b48ea7eca3a Mon Sep 17 00:00:00 2001 From: Jayesh Deorukhkar Date: Mon, 1 Jul 2024 09:28:29 +0530 Subject: [PATCH 2/4] test: added test cases --- test/expectedJson.ts | 93 ++++++++++++++++++++++++++++++++++++++++- test/toRedactor.test.ts | 10 ++--- 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/test/expectedJson.ts b/test/expectedJson.ts index 73bdfac..52afccd 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -1909,6 +1909,97 @@ export default { } ] } - } + }, + "RT-154": { + "html": "

", + "json": [ + { + "type": "p", + "attrs": {}, + "uid": "67d60b59926c48b58cb6b5d899401c01", + "children": [ + { + "text": "" + } + ] + }, + { + "type": "reference", + "attrs": { + "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "default": true, + "asset-type": "image/jpg", + "display-type": "display", + "type": "asset", + "style": { + "height": "auto" + }, + "redactor-attributes": { + "asset_uid": "blt5523ee02703e39f5", + "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "width": "24.193548387096776%", + "height": "auto", + "style": "width: 24.193548387096776; height: auto;" + }, + "width": 24.193548387096776 + }, + "uid": "fe969de8727c4074a23442a71b57ebb8", + "children": [ + { + "text": "" + } + ] + }, + { + "type": "p", + "attrs": {}, + "uid": "8c912298ad0a4a458c189f12603c05fb", + "children": [ + { + "text": "" + } + ] + }, + { + "type": "embed", + "attrs": { + "src": "https://www.youtube.com/embed/CSvFpBOe8eY", + "style": {}, + "redactor-attributes": { + "src": "https://www.youtube.com/embed/CSvFpBOe8eY" + } + }, + "uid": "26067652d613404b8091f6e83d7af301", + "children": [ + { + "text": "" + } + ] + }, + { + "type": "reference", + "attrs": { + "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "default": true, + "asset-type": "image/jpg", + "display-type": "display", + "type": "asset", + "style": {}, + "redactor-attributes": { + "asset_uid": "blta2aad0332073026c", + "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "height": "auto" + } + }, + "uid": "d56e691f59ce4d35934c6aa9325188a2", + "children": [ + { + "text": "" + } + ] + } + ], + "htmlUpdated": "

" + } } \ No newline at end of file diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index b336961..a3ba579 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -33,12 +33,10 @@ describe("Testing json to html conversion", () => { let testResult = isEqual(htmlValue, expectedValue['5'].html) expect(testResult).toBe(true) }) - it("Image and iframe conversion", () => { - let jsonValue = expectedValue["6"].json - - let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue }) - let testResult = isEqual(htmlValue, expectedValue['6'].htmlUpdated) - expect(testResult).toBe(true) + it.each(["6", "RT-154"])("Image and iframe conversion", (index) => { + let jsonValue = expectedValue[index].json + let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue }) + expect(htmlValue).toBe(expectedValue[index].htmlUpdated) }) it("Link ,divider and property conversion", () => { let jsonValue = expectedValue["7"].json From 7281750006d1ecf58bd6fd2706861b4e0d633b50 Mon Sep 17 00:00:00 2001 From: Jayesh Deorukhkar <52153715+Jayesh2812@users.noreply.github.com> Date: Wed, 3 Jul 2024 11:14:09 +0530 Subject: [PATCH 3/4] fix: update package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fe2e40..ecd7740 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/json-rte-serializer", - "version": "2.0.7", + "version": "2.0.8", "description": "This Package converts Html Document to Json and vice-versa.", "main": "lib/index.js", "module": "lib/index.mjs", From 50b58d9fa10c180085812fbd15b315c1bf671e37 Mon Sep 17 00:00:00 2001 From: Jayesh Deorukhkar Date: Thu, 4 Jul 2024 16:39:16 +0530 Subject: [PATCH 4/4] fix: remove dev urls from test case data --- test/expectedJson.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/expectedJson.ts b/test/expectedJson.ts index 52afccd..4504206 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -527,7 +527,7 @@ export default { ] }, "6": { - "html": "

", + "html": "

", "json": [ { "type": "p", @@ -542,7 +542,7 @@ export default { { "type": "reference", "attrs": { - "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "asset-link": "https://images.com/captain_pardip.jpg", "default": true, "asset-type": "image/jpg", "display-type": "display", @@ -552,7 +552,7 @@ export default { }, "redactor-attributes": { "asset_uid": "blt5523ee02703e39f5", - "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "src": "https://images.com/captain_pardip.jpg", "width": "24.193548387096776", "height": "auto", "style": "width: 24.193548387096776; height: auto;" @@ -595,7 +595,7 @@ export default { { "type": "reference", "attrs": { - "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "asset-link": "https://images.com/logo_1.jpg", "default": true, "asset-type": "image/jpg", "display-type": "display", @@ -603,7 +603,7 @@ export default { "style": {}, "redactor-attributes": { "asset_uid": "blta2aad0332073026c", - "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "src": "https://images.com/logo_1.jpg", "height": "auto" } }, @@ -615,7 +615,7 @@ export default { ] } ], - "htmlUpdated": "

" + "htmlUpdated": "

" }, "7": { "html": "

this is link

paragraph with class

paragraph with id

", @@ -821,7 +821,7 @@ export default { "htmlValue": "

test

" }, "11": { - "html": "

", + "html": "

", "json": [ { "type": "p", @@ -843,7 +843,7 @@ export default { }, "type": "asset", "target": "_self", - "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "asset-link": "https://images.com/captain_pardip.jpg", "asset-uid": "blt5523ee02703e39f5", "display-type": "display", "asset-name": "test", @@ -1911,7 +1911,7 @@ export default { } }, "RT-154": { - "html": "

", + "html": "

", "json": [ { "type": "p", @@ -1926,7 +1926,7 @@ export default { { "type": "reference", "attrs": { - "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "asset-link": "https://images.com/captain_pardip.jpg", "default": true, "asset-type": "image/jpg", "display-type": "display", @@ -1936,7 +1936,7 @@ export default { }, "redactor-attributes": { "asset_uid": "blt5523ee02703e39f5", - "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg", + "src": "https://images.com/captain_pardip.jpg", "width": "24.193548387096776%", "height": "auto", "style": "width: 24.193548387096776; height: auto;" @@ -1979,7 +1979,7 @@ export default { { "type": "reference", "attrs": { - "asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "asset-link": "https://images.com/logo_1.jpg", "default": true, "asset-type": "image/jpg", "display-type": "display", @@ -1987,7 +1987,7 @@ export default { "style": {}, "redactor-attributes": { "asset_uid": "blta2aad0332073026c", - "src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg", + "src": "https://images.com/logo_1.jpg", "height": "auto" } }, @@ -1999,7 +1999,7 @@ export default { ] } ], - "htmlUpdated": "

" + "htmlUpdated": "

" } } \ No newline at end of file