Skip to content

Commit 1046f1e

Browse files
committed
HTMLNodeToNSAttributedStringTests: New Tests
1 parent b3641ea commit 1046f1e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

AztecTests/Converters/HTMLNodeToNSAttributedStringTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class HTMLNodeToNSAttributedStringTests: XCTestCase {
5252
XCTAssertEqual(restoredSpanAttribute1?.value.toString(), "first")
5353
}
5454

55+
5556
/// Verifies that the DivFormatter effectively appends the DIV Element Representation, to the properties collection.
5657
///
5758
func testHtmlDivFormatterEffectivelyAppendsNewDivProperty() {
@@ -96,6 +97,41 @@ class HTMLNodeToNSAttributedStringTests: XCTestCase {
9697
XCTAssert(restoredDiv3.name == divNode3.name)
9798
XCTAssert(restoredDiv3.attributes == [divAttr3])
9899
}
100+
101+
102+
/// Verifies that BR elements contained within div tags do not cause any side effect.
103+
/// Ref. #658
104+
///
105+
func testLineBreakTagWithinHTMLDivGetsProperlyEncodedAndDecoded() {
106+
let inHtml = "<div><br>Aztec, don't forget me!</div>"
107+
108+
let inNode = InHTMLConverter().convert(inHtml)
109+
let attrString = attributedString(from: inNode)
110+
111+
let outNode = NSAttributedStringToNodes().convert(attrString)
112+
let outHtml = OutHTMLConverter().convert(outNode)
113+
114+
XCTAssertEqual(outHtml, inHtml)
115+
}
116+
117+
118+
/// Verifies that BR elements contained within span tags do not cause Data Loss.
119+
/// Ref. #658
120+
///
121+
func testLineBreakTagWithinUnsupportedHTMLDoesNotCauseDataLoss() {
122+
let inHtml = "<span><br>Aztec, don't forget me!</span>"
123+
let expectedHtml = "<br><span>Aztec, don't forget me!</span>"
124+
// TODO: The actual expected html should wrap the BR within a span tag. To be addressed in another PR!
125+
// let expectedHtml = "<span><br></span><span>Aztec, don't forget me!</span>"
126+
127+
let inNode = InHTMLConverter().convert(inHtml)
128+
let attrString = attributedString(from: inNode)
129+
130+
let outNode = NSAttributedStringToNodes().convert(attrString)
131+
let outHtml = OutHTMLConverter().convert(outNode)
132+
133+
XCTAssertEqual(outHtml, expectedHtml)
134+
}
99135
}
100136

101137

0 commit comments

Comments
 (0)