Skip to content

Commit

Permalink
Merge branch 'oppia:develop' into issue_triage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank77maruti authored Dec 10, 2024
2 parents d445fde + edb01a8 commit c979ab6
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,57 @@ class HtmlParserTest {
assertThat(htmlResult.toString()).endsWith(" ")
}

@Test
fun testHtmlContentParsing_removesUnwantedNewlines() {
val htmlParser = htmlParserFactory.create(
resourceBucketName,
entityType = "",
entityId = "",
imageCenterAlign = true,
displayLocale = appLanguageLocaleHandler.getDisplayLocale()
)
val (_, htmlResult) = activityScenarioRule.scenario.runWithActivity {
val textView: TextView = it.findViewById(R.id.test_html_content_text_view)
val htmlResult = htmlParser.parseOppiaHtml(
"<ul><li>\n\tThe counting numbers (1, 2, 3, 4, 5 ….)\n\n</li><li>\n\tHow to tell" +
" whether one counting number is bigger or smaller than another.\n\n</li></ul>",
textView
)
textView.text = htmlResult
return@runWithActivity textView to htmlResult
}

assertThat(htmlResult.toString()).isEqualTo(
"The counting numbers (1, 2, 3, 4, 5 ….)\nHow to tell whether one counting " +
"number is bigger or smaller than another"
)
}

@Test
fun testHtmlContentParsing_withImageTag_trimsLeadingAndTrailingNewlines() {
val htmlParser = htmlParserFactory.create(
resourceBucketName,
entityType = "",
entityId = "",
imageCenterAlign = true,
displayLocale = appLanguageLocaleHandler.getDisplayLocale()
)
val htmlResult = activityScenarioRule.scenario.runWithActivity {
val textView: TextView = it.findViewById(R.id.test_html_content_text_view)
return@runWithActivity htmlParser.parseOppiaHtml(
"\n<oppia-noninteractive-image filepath-with-value=\"test.png\">" +
"</oppia-noninteractive-image>\n",
textView
)
}
val imageSpans = htmlResult.getSpansFromWholeString(ImageSpan::class)
assertThat(imageSpans).hasLength(1)
assertThat(imageSpans.first().source).isEqualTo("test.png")

assertThat(htmlResult.toString().startsWith("\n")).isFalse()
assertThat(htmlResult.toString().endsWith("\n")).isFalse()
}

@Test
fun testHtmlContent_changeDeviceToLtr_textViewDirectionIsSetToLtr() {
val htmlParser = htmlParserFactory.create(
Expand Down

0 comments on commit c979ab6

Please sign in to comment.