Skip to content

Commit

Permalink
fix: added fragment related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-from-contentstack committed Mar 1, 2024
1 parent 4171564 commit a376c13
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ContentstackUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)";
Expand All @@ -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)";
Expand All @@ -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)";
Expand Down
1 change: 1 addition & 0 deletions Sources/ContentstackUtils/NodeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum NodeType: String {
orderList = "ol",
unOrderList = "ul",
listItem = "li",
fragment = "fragment",

hr,

Expand Down
2 changes: 2 additions & 0 deletions Sources/ContentstackUtils/Option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ open class Option: Renderable {
return "<h6>\(next(node.children))</h6>"
case NodeType.orderList.rawValue:
return "<ol>\(next(node.children))</ol>"
case NodeType.fragment.rawValue:
return "<fragment>\(next(node.children))</fragment>"
case NodeType.unOrderList.rawValue:
return "<ul>\(next(node.children))</ul>"
case NodeType.listItem.rawValue:
Expand Down
19 changes: 19 additions & 0 deletions Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,22 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {
XCTAssertEqual(result, ["<hr>"])
}

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),
Expand Down Expand Up @@ -516,6 +532,9 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {

("testCode_Document", testCode_Document),
("testCodeArray_Document", testCodeArray_Document),

("testFragment_Document", testFragment_Document),
("testFragmentArray_Document", testFragmentArray_Document),
]

}
9 changes: 9 additions & 0 deletions Tests/ContentstackUtilsTests/DefaultRenderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ class OptionTests: XCTestCase {
})
XCTAssertEqual(result, "<ol>\(text)</ol>")
}

func testFragmentRender() {
let node = NodeParser.parse(from: kBlankDocument)

let result = defaultRender.renderNode(nodeType: NodeType.fragment.rawValue, node: node, next: { _ in
return text
})
XCTAssertEqual(result, "<fragment>\(text)</fragment>")
}

func testUnorderListRender() {
let node = NodeParser.parse(from: kBlankDocument)
Expand Down
13 changes: 13 additions & 0 deletions Tests/ContentstackUtilsTests/GQLJsonToHtml.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -299,6 +311,7 @@ class GQLJsonToHtml: XCTestCase {
("testTable_Document", testTable_Document),
("testBlockquote_Document", testBlockquote_Document),
("testCode_Document", testCode_Document),
("testFragment_Document", testFragment_Document),
]

}
112 changes: 112 additions & 0 deletions Tests/ContentstackUtilsTests/JsonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
"""
1 change: 1 addition & 0 deletions Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ let kBlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</b
let kCodeHtml = "<code>Code template.</code>"
let kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>"
let kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>"
let kFragmentHtml = "<ul><li><fragment><strong>One</strong></fragment><ul><li>nested one </li><li>nested two </li></ul></li><li>Two</li></ul>"
1 change: 1 addition & 0 deletions Tests/ContentstackUtilsTests/NodeTypeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a376c13

Please sign in to comment.