Skip to content

Commit 6549cd3

Browse files
Merge pull request #14 from contentstack/fix/CS-44026
Fix/cs 44026
2 parents a5be7d3 + 1068233 commit 6549cd3

10 files changed

Lines changed: 163 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [ master ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, next ]
88

99
jobs:
1010
iOS:

ContentstackUtils.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@
679679
"DEBUG=1",
680680
);
681681
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
682-
MACOSX_DEPLOYMENT_TARGET = 10.10;
682+
MACOSX_DEPLOYMENT_TARGET = 10.13;
683683
ONLY_ACTIVE_ARCH = YES;
684684
OTHER_LDFLAGS = "-lxml2";
685685
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
@@ -718,7 +718,7 @@
718718
INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtilsTests_Info.plist;
719719
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
720720
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
721-
MACOSX_DEPLOYMENT_TARGET = 10.10;
721+
MACOSX_DEPLOYMENT_TARGET = 10.13;
722722
OTHER_CFLAGS = "$(inherited)";
723723
OTHER_LDFLAGS = "$(inherited)";
724724
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -744,7 +744,7 @@
744744
INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtilsTests_Info.plist;
745745
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
746746
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
747-
MACOSX_DEPLOYMENT_TARGET = 10.10;
747+
MACOSX_DEPLOYMENT_TARGET = 10.13;
748748
OTHER_CFLAGS = "$(inherited)";
749749
OTHER_LDFLAGS = "$(inherited)";
750750
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -771,7 +771,7 @@
771771
"SWIFT_PACKAGE=1",
772772
);
773773
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
774-
MACOSX_DEPLOYMENT_TARGET = 10.10;
774+
MACOSX_DEPLOYMENT_TARGET = 10.13;
775775
OTHER_LDFLAGS = "-lxml2";
776776
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
777777
PRODUCT_NAME = "$(TARGET_NAME)";

Sources/ContentstackUtils/NodeType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum NodeType: String {
2323
orderList = "ol",
2424
unOrderList = "ul",
2525
listItem = "li",
26+
fragment = "fragment",
2627

2728
hr,
2829

Sources/ContentstackUtils/Option.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ open class Option: Renderable {
8888
return "<h6>\(next(node.children))</h6>"
8989
case NodeType.orderList.rawValue:
9090
return "<ol>\(next(node.children))</ol>"
91+
case NodeType.fragment.rawValue:
92+
return "<fragment>\(next(node.children))</fragment>"
9193
case NodeType.unOrderList.rawValue:
9294
return "<ul>\(next(node.children))</ul>"
9395
case NodeType.listItem.rawValue:

Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,22 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {
455455
XCTAssertEqual(result, ["<hr>"])
456456
}
457457

458+
func testFragment_Document() {
459+
let node = NodeParser.parse(from: kFragmentJson)
460+
461+
let result = ContentstackUtils.jsonToHtml(node: node)
462+
463+
XCTAssertEqual(result, kFragmentHtml)
464+
}
465+
466+
func testFragmentArray_Document() {
467+
let node = NodeParser.parse(from: kFragmentJson)
468+
469+
let result = ContentstackUtils.jsonToHtml(node: [node])
470+
471+
XCTAssertEqual(result, [kFragmentHtml])
472+
}
473+
458474
static var allTests = [
459475
("testEmpty_Node_Returns_Empty_String", testEmpty_Node_Returns_Empty_String),
460476
("testEmpty_Nodes_Array_Returns_Empty_String_Array", testEmpty_Nodes_Array_Returns_Empty_String_Array),
@@ -516,6 +532,9 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {
516532

517533
("testCode_Document", testCode_Document),
518534
("testCodeArray_Document", testCodeArray_Document),
535+
536+
("testFragment_Document", testFragment_Document),
537+
("testFragmentArray_Document", testFragmentArray_Document),
519538
]
520539

521540
}

Tests/ContentstackUtilsTests/DefaultRenderTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ class OptionTests: XCTestCase {
225225
})
226226
XCTAssertEqual(result, "<ol>\(text)</ol>")
227227
}
228+
229+
func testFragmentRender() {
230+
let node = NodeParser.parse(from: kBlankDocument)
231+
232+
let result = defaultRender.renderNode(nodeType: NodeType.fragment.rawValue, node: node, next: { _ in
233+
return text
234+
})
235+
XCTAssertEqual(result, "<fragment>\(text)</fragment>")
236+
}
228237

229238
func testUnorderListRender() {
230239
let node = NodeParser.parse(from: kBlankDocument)

Tests/ContentstackUtilsTests/GQLJsonToHtml.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ class GQLJsonToHtml: XCTestCase {
276276
}
277277
}
278278

279+
func testFragment_Document() {
280+
guard let json = GQLJsonRTE(node: kFragmentJson) else { return }
281+
282+
if let result = try? ContentstackUtils.GQL.jsonToHtml(rte: json["single_rte"] as! [String : Any?]) as? String {
283+
XCTAssertEqual(result, kFragmentHtml)
284+
}
285+
286+
if let result = try? ContentstackUtils.GQL.jsonToHtml(rte: json["multiple_rte"] as! [String : Any?]) as? [String] {
287+
XCTAssertEqual(result, [kFragmentHtml])
288+
}
289+
}
290+
279291
static var allTests = [
280292
("testEmpty_Node_Returns_Empty_String", testEmpty_Node_Returns_Empty_String),
281293
("testPlainText_Document_Return_HtmlString_Result", testPlainText_Document_Return_HtmlString_Result),
@@ -299,6 +311,7 @@ class GQLJsonToHtml: XCTestCase {
299311
("testTable_Document", testTable_Document),
300312
("testBlockquote_Document", testBlockquote_Document),
301313
("testCode_Document", testCode_Document),
314+
("testFragment_Document", testFragment_Document),
302315
]
303316

304317
}

Tests/ContentstackUtilsTests/JsonNodes.swift

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,115 @@ let kHRJson = """
854854
"type": "doc"
855855
}
856856
"""
857+
858+
let kFragmentJson = """
859+
{
860+
"type": "doc",
861+
"attrs":
862+
{},
863+
"children":
864+
[
865+
{
866+
"type": "ul",
867+
"children":
868+
[
869+
{
870+
"type": "li",
871+
"attrs":
872+
{
873+
"style":
874+
{},
875+
"redactor-attributes":
876+
{},
877+
"dir": "ltr"
878+
},
879+
"children":
880+
[
881+
{
882+
"type": "fragment",
883+
"children":
884+
[
885+
{
886+
"text": "One",
887+
"bold": true
888+
}
889+
],
890+
},
891+
{
892+
"type": "ul",
893+
"attrs":
894+
{
895+
"style":
896+
{}
897+
},
898+
"children":
899+
[
900+
{
901+
"type": "li",
902+
"attrs":
903+
{
904+
"style":
905+
{},
906+
"redactor-attributes":
907+
{},
908+
"dir": "ltr"
909+
},
910+
"children":
911+
[
912+
{
913+
"text": "nested one "
914+
}
915+
]
916+
},
917+
{
918+
"type": "li",
919+
"attrs":
920+
{
921+
"style":
922+
{},
923+
"redactor-attributes":
924+
{},
925+
"dir": "ltr"
926+
},
927+
"children":
928+
[
929+
{
930+
"text": "nested two "
931+
}
932+
]
933+
}
934+
]
935+
}
936+
]
937+
},
938+
{
939+
"type": "li",
940+
"attrs":
941+
{
942+
"style":
943+
{},
944+
"redactor-attributes":
945+
{},
946+
"dir": "ltr"
947+
},
948+
"children":
949+
[
950+
{
951+
"text": "Two"
952+
}
953+
]
954+
}
955+
],
956+
"attrs":
957+
{
958+
"style":
959+
{},
960+
"redactor-attributes":
961+
{},
962+
"dir": "ltr"
963+
}
964+
}
965+
],
966+
"_version": 1
967+
}
968+
"""

Tests/ContentstackUtilsTests/JsonNodesHtmlResults.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ let kBlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</b
2121
let kCodeHtml = "<code>Code template.</code>"
2222
let kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>"
2323
let kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>"
24+
let kFragmentHtml = "<ul><li><fragment><strong>One</strong></fragment><ul><li>nested one </li><li>nested two </li></ul></li><li>Two</li></ul>"

Tests/ContentstackUtilsTests/NodeTypeTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class NodeTypeTest: XCTestCase {
2222
XCTAssertEqual(NodeType.heading_5.rawValue, "h5")
2323
XCTAssertEqual(NodeType.heading_6.rawValue, "h6")
2424
XCTAssertEqual(NodeType.orderList.rawValue, "ol")
25+
XCTAssertEqual(NodeType.fragment.rawValue, "fragment")
2526
XCTAssertEqual(NodeType.unOrderList.rawValue, "ul")
2627
XCTAssertEqual(NodeType.listItem.rawValue, "li")
2728
XCTAssertEqual(NodeType.hr.rawValue, "hr")

0 commit comments

Comments
 (0)