Skip to content

Commit d417331

Browse files
authored
Merge pull request #867 from wordpress-mobile/add/tests-parsing-br-and-para-tags
Add simple tests for BR tags before P closing tag
2 parents 9eb31ed + c67747d commit d417331

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

aztec/src/test/kotlin/org/wordpress/aztec/AztecParserTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,38 @@ class AztecParserTest : AndroidTestCase() {
11641164
Assert.assertEquals(input, output)
11651165
}
11661166

1167+
/**
1168+
* Currently, this html <p>Hello There!<br></p> after being parsed to span and back to html will become
1169+
* <p>Hello There!</p>.
1170+
* This is not a bug, this is how we originally implemented the function that cleans the HTML input
1171+
* in AztecParser->tidy method.
1172+
*
1173+
* Since we're using this editor in Gutenberg Mobile project, where the selection could be sent from
1174+
* the JS side to the native, we needed to take in consideration this behavior of Aztec in GB-mobile,
1175+
* and modify the logic that does set the selection accordingly.
1176+
*
1177+
* This test just checks that the underlying parser is working as expected.
1178+
*/
1179+
@Test
1180+
@Throws(Exception::class)
1181+
fun parseHtmlToSpanToHtmlBrBeforePara_isNotEqual() {
1182+
val input = "<p>Hello There!<br></p>"
1183+
val expectedOutput = "<p>Hello There!</p>"
1184+
val span = SpannableString(mParser.fromHtml(input, RuntimeEnvironment.application.applicationContext))
1185+
val output = mParser.toHtml(span)
1186+
Assert.assertEquals(expectedOutput, output)
1187+
}
1188+
1189+
@Test
1190+
@Throws(Exception::class)
1191+
fun parseHtmlToSpanToHtmlBrBeforePara2_isNotEqual() {
1192+
val input = "<p>Hello There!<br><br><br><br></p>"
1193+
val expectedOutput = "<p>Hello There!</p>"
1194+
val span = SpannableString(mParser.fromHtml(input, RuntimeEnvironment.application.applicationContext))
1195+
val output = mParser.toHtml(span)
1196+
Assert.assertEquals(expectedOutput, output)
1197+
}
1198+
11671199
@Test
11681200
@Throws(Exception::class)
11691201
fun parseHtmlToSpanToHtmlMixedContentInListItem_isEqual() {

0 commit comments

Comments
 (0)