Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #455: Improve Html parser tests #5589

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,57 @@ class HtmlParserTest {
assertThat(htmlResult.toString()).endsWith(" ")
}

@Test
fun testHtmlContentReplace_removesUnwantedNewlines() {
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
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 testHtmlContent_withImageTag_trimsLeadingAndTrailingNewlines() {
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
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
Loading