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

Fixes #3906: Incorrect output for rich text in hints and solution #4666

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.domain.hintsandsolution.isHintRevealed
import org.oppia.android.domain.hintsandsolution.isSolutionRevealed
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.parser.html.CustomHtmlContentHandler
import javax.inject.Inject

private const val DEFAULT_HINT_AND_SOLUTION_SUMMARY = ""
Expand Down Expand Up @@ -82,7 +83,13 @@ class HintsViewModel @Inject constructor(
fun computeHintListDropDownIconContentDescription(): String {
return resourceHandler.getStringInLocaleWithWrapping(
R.string.show_hide_hint_list,
hintsAndSolutionSummary.get() ?: DEFAULT_HINT_AND_SOLUTION_SUMMARY
hintsAndSolutionSummary.get()?.let {
CustomHtmlContentHandler.fromHtml(
it,
imageRetriever = null,
customTagHandlers = mapOf()
)
} ?: DEFAULT_HINT_AND_SOLUTION_SUMMARY
)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/hints_summary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
android:layout_height="wrap_content"
android:background="@color/component_color_hints_and_solution_summary_bottom_background_color"
android:fontFamily="sans-serif"
android:importantForAccessibility="no"
android:paddingStart="12dp"
android:paddingTop="16dp"
android:paddingEnd="12dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,48 @@ class ExplorationActivityTest {
explorationDataController.stopPlayingExploration(isCompletion = false)
}

@Test
@RunOn(TestPlatform.ROBOLECTRIC) // TODO(#3858): Enable for Espresso.
fun testExpActivity_showHintAndSolution_hasCorrectContentDescription() {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
launch<ExplorationActivity>(
createExplorationActivityIntent(
internalProfileId,
TEST_TOPIC_ID_0,
TEST_STORY_ID_0,
TEST_EXPLORATION_ID_2,
shouldSavePartialProgress = false
)
).use {
explorationDataController.startPlayingNewExploration(
internalProfileId,
TEST_TOPIC_ID_0,
TEST_STORY_ID_0,
TEST_EXPLORATION_ID_2
)
testCoroutineDispatchers.runCurrent()
clickContinueButton()
// Submit two incorrect answers.
submitFractionAnswer(answerText = "1/3")
submitFractionAnswer(answerText = "1/4")

// Reveal the hint.
openHintsAndSolutionsDialog()
pressRevealHintButton(hintPosition = 0)

// Ensure the hint description is correct and doesn't contain any HTML.
onView(withId(R.id.expand_list_icon))
.check(
matches(
withContentDescription(
"Show/Hide hint list of Remember that two halves, when added together," +
" make one whole.\n\n"
)
)
)
}
explorationDataController.stopPlayingExploration(isCompletion = false)
}

// TODO(#3858): Enable for Espresso.
@Test
@RunOn(TestPlatform.ROBOLECTRIC, buildEnvironments = [BuildEnvironment.BAZEL])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -429,6 +430,33 @@ class QuestionPlayerActivityTest {
}
}

@Test
@RunOn(TestPlatform.ROBOLECTRIC) // TODO(#3858): Enable for Espresso.
fun testQuestionPlayer_showHintsAndSolution_hasCorrectContentDescription() {
updateContentLanguage(profileId, OppiaLanguage.ENGLISH)
launchForSkillList(SKILL_ID_LIST).use {
// Submit two incorrect answers.
selectMultipleChoiceOption(optionPosition = 3)
selectMultipleChoiceOption(optionPosition = 3)

// Reveal the hint.
openHintsAndSolutionsDialog()
pressRevealHintButton(hintPosition = 0)

// Ensure the hint description is correct and doesn't contain any HTML.
onView(withId(R.id.expand_list_icon))
.check(
matches(
withContentDescription(
"Show/Hide hint list of To write a fraction, you need to know " +
"its denominator, which is the total number of pieces in the whole. " +
"All of these pieces should be the same size.\n\n"
)
)
)
}
}

// TODO(#3858): Enable for Espresso.
@Test
@RunOn(TestPlatform.ROBOLECTRIC, buildEnvironments = [BuildEnvironment.BAZEL])
Expand Down