From a376c131fd8eb0fd1fdec16efbefc634396fa870 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Fri, 1 Mar 2024 15:52:35 +0530 Subject: [PATCH] fix: added fragment related changes --- ContentstackUtils.xcodeproj/project.pbxproj | 8 +- Sources/ContentstackUtils/NodeType.swift | 1 + Sources/ContentstackUtils/Option.swift | 2 + .../ContentstackUtilsJsonToHtmlTest.swift | 19 +++ .../DefaultRenderTests.swift | 9 ++ .../GQLJsonToHtml.swift | 13 ++ Tests/ContentstackUtilsTests/JsonNodes.swift | 112 ++++++++++++++++++ .../JsonNodesHtmlResults.swift | 1 + .../ContentstackUtilsTests/NodeTypeTest.swift | 1 + 9 files changed, 162 insertions(+), 4 deletions(-) diff --git a/ContentstackUtils.xcodeproj/project.pbxproj b/ContentstackUtils.xcodeproj/project.pbxproj index 5025d9d..c262839 100644 --- a/ContentstackUtils.xcodeproj/project.pbxproj +++ b/ContentstackUtils.xcodeproj/project.pbxproj @@ -679,7 +679,7 @@ "DEBUG=1", ); HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; OTHER_SWIFT_FLAGS = "$(inherited) -DXcode"; @@ -718,7 +718,7 @@ INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtilsTests_Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; @@ -744,7 +744,7 @@ INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtilsTests_Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; @@ -771,7 +771,7 @@ "SWIFT_PACKAGE=1", ); HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_LDFLAGS = "-lxml2"; OTHER_SWIFT_FLAGS = "$(inherited) -DXcode"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Sources/ContentstackUtils/NodeType.swift b/Sources/ContentstackUtils/NodeType.swift index 25c7602..24e57df 100644 --- a/Sources/ContentstackUtils/NodeType.swift +++ b/Sources/ContentstackUtils/NodeType.swift @@ -23,6 +23,7 @@ public enum NodeType: String { orderList = "ol", unOrderList = "ul", listItem = "li", + fragment = "fragment", hr, diff --git a/Sources/ContentstackUtils/Option.swift b/Sources/ContentstackUtils/Option.swift index 3d3ddf8..7d1c341 100644 --- a/Sources/ContentstackUtils/Option.swift +++ b/Sources/ContentstackUtils/Option.swift @@ -88,6 +88,8 @@ open class Option: Renderable { return "
\(next(node.children))
" case NodeType.orderList.rawValue: return "
    \(next(node.children))
" + case NodeType.fragment.rawValue: + return "\(next(node.children))" case NodeType.unOrderList.rawValue: return "" case NodeType.listItem.rawValue: diff --git a/Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift b/Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift index 8dc9818..bdc0547 100644 --- a/Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift +++ b/Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift @@ -455,6 +455,22 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase { XCTAssertEqual(result, ["
"]) } + func testFragment_Document() { + let node = NodeParser.parse(from: kFragmentJson) + + let result = ContentstackUtils.jsonToHtml(node: node) + + XCTAssertEqual(result, kFragmentHtml) + } + + func testFragmentArray_Document() { + let node = NodeParser.parse(from: kFragmentJson) + + let result = ContentstackUtils.jsonToHtml(node: [node]) + + XCTAssertEqual(result, [kFragmentHtml]) + } + static var allTests = [ ("testEmpty_Node_Returns_Empty_String", testEmpty_Node_Returns_Empty_String), ("testEmpty_Nodes_Array_Returns_Empty_String_Array", testEmpty_Nodes_Array_Returns_Empty_String_Array), @@ -516,6 +532,9 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase { ("testCode_Document", testCode_Document), ("testCodeArray_Document", testCodeArray_Document), + + ("testFragment_Document", testFragment_Document), + ("testFragmentArray_Document", testFragmentArray_Document), ] } diff --git a/Tests/ContentstackUtilsTests/DefaultRenderTests.swift b/Tests/ContentstackUtilsTests/DefaultRenderTests.swift index 99aec62..bd66727 100644 --- a/Tests/ContentstackUtilsTests/DefaultRenderTests.swift +++ b/Tests/ContentstackUtilsTests/DefaultRenderTests.swift @@ -225,6 +225,15 @@ class OptionTests: XCTestCase { }) XCTAssertEqual(result, "
    \(text)
") } + + func testFragmentRender() { + let node = NodeParser.parse(from: kBlankDocument) + + let result = defaultRender.renderNode(nodeType: NodeType.fragment.rawValue, node: node, next: { _ in + return text + }) + XCTAssertEqual(result, "\(text)") + } func testUnorderListRender() { let node = NodeParser.parse(from: kBlankDocument) diff --git a/Tests/ContentstackUtilsTests/GQLJsonToHtml.swift b/Tests/ContentstackUtilsTests/GQLJsonToHtml.swift index fe57757..ca4d35f 100644 --- a/Tests/ContentstackUtilsTests/GQLJsonToHtml.swift +++ b/Tests/ContentstackUtilsTests/GQLJsonToHtml.swift @@ -276,6 +276,18 @@ class GQLJsonToHtml: XCTestCase { } } + func testFragment_Document() { + guard let json = GQLJsonRTE(node: kFragmentJson) else { return } + + if let result = try? ContentstackUtils.GQL.jsonToHtml(rte: json["single_rte"] as! [String : Any?]) as? String { + XCTAssertEqual(result, kFragmentHtml) + } + + if let result = try? ContentstackUtils.GQL.jsonToHtml(rte: json["multiple_rte"] as! [String : Any?]) as? [String] { + XCTAssertEqual(result, [kFragmentHtml]) + } + } + static var allTests = [ ("testEmpty_Node_Returns_Empty_String", testEmpty_Node_Returns_Empty_String), ("testPlainText_Document_Return_HtmlString_Result", testPlainText_Document_Return_HtmlString_Result), @@ -299,6 +311,7 @@ class GQLJsonToHtml: XCTestCase { ("testTable_Document", testTable_Document), ("testBlockquote_Document", testBlockquote_Document), ("testCode_Document", testCode_Document), + ("testFragment_Document", testFragment_Document), ] } diff --git a/Tests/ContentstackUtilsTests/JsonNodes.swift b/Tests/ContentstackUtilsTests/JsonNodes.swift index e0d1690..f62d5c8 100644 --- a/Tests/ContentstackUtilsTests/JsonNodes.swift +++ b/Tests/ContentstackUtilsTests/JsonNodes.swift @@ -854,3 +854,115 @@ let kHRJson = """ "type": "doc" } """ + +let kFragmentJson = """ +{ + "type": "doc", + "attrs": + {}, + "children": + [ + { + "type": "ul", + "children": + [ + { + "type": "li", + "attrs": + { + "style": + {}, + "redactor-attributes": + {}, + "dir": "ltr" + }, + "children": + [ + { + "type": "fragment", + "children": + [ + { + "text": "One", + "bold": true + } + ], + }, + { + "type": "ul", + "attrs": + { + "style": + {} + }, + "children": + [ + { + "type": "li", + "attrs": + { + "style": + {}, + "redactor-attributes": + {}, + "dir": "ltr" + }, + "children": + [ + { + "text": "nested one " + } + ] + }, + { + "type": "li", + "attrs": + { + "style": + {}, + "redactor-attributes": + {}, + "dir": "ltr" + }, + "children": + [ + { + "text": "nested two " + } + ] + } + ] + } + ] + }, + { + "type": "li", + "attrs": + { + "style": + {}, + "redactor-attributes": + {}, + "dir": "ltr" + }, + "children": + [ + { + "text": "Two" + } + ] + } + ], + "attrs": + { + "style": + {}, + "redactor-attributes": + {}, + "dir": "ltr" + } + } + ], + "_version": 1 +} +""" diff --git a/Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift b/Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift index 479b7e5..c73b34e 100644 --- a/Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift +++ b/Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift @@ -21,3 +21,4 @@ let kBlockquoteHtml = "
Praesent eu ex sed nibh venenatis pretium.LINK

" let kEmbedHtml = "" +let kFragmentHtml = "" diff --git a/Tests/ContentstackUtilsTests/NodeTypeTest.swift b/Tests/ContentstackUtilsTests/NodeTypeTest.swift index 0c5705f..c602fa0 100644 --- a/Tests/ContentstackUtilsTests/NodeTypeTest.swift +++ b/Tests/ContentstackUtilsTests/NodeTypeTest.swift @@ -22,6 +22,7 @@ class NodeTypeTest: XCTestCase { XCTAssertEqual(NodeType.heading_5.rawValue, "h5") XCTAssertEqual(NodeType.heading_6.rawValue, "h6") XCTAssertEqual(NodeType.orderList.rawValue, "ol") + XCTAssertEqual(NodeType.fragment.rawValue, "fragment") XCTAssertEqual(NodeType.unOrderList.rawValue, "ul") XCTAssertEqual(NodeType.listItem.rawValue, "li") XCTAssertEqual(NodeType.hr.rawValue, "hr")