Skip to content

Commit

Permalink
Don't submit answer if it's invalid according to the input
Browse files Browse the repository at this point in the history
or else after submitting the recycler view will not restore items on configuration change. See oppia#4708 for more details

before:
https://drive.google.com/file/d/1bLgo-AYro0UbffR6X8nWo8Xv7oUuNJFa/view?usp=sharing
after:
https://drive.google.com/file/d/1Oek7j6dgjJmgasyyd9FHtQo4E7zTvEBd/view?usp=sharing
  • Loading branch information
Long Wei committed Oct 24, 2023
1 parent d471d79 commit ae9d8ec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ class StateFragmentPresenter @Inject constructor(

fun onSubmitButtonClicked() {
hideKeyboard()
handleSubmitAnswer(viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler))
val answer = viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler)
if (answer != null) {
handleSubmitAnswer(answer)
}
}

fun onResponsesHeaderClicked() {
Expand All @@ -215,7 +218,10 @@ class StateFragmentPresenter @Inject constructor(
fun handleKeyboardAction() {
hideKeyboard()
if (viewModel.getCanSubmitAnswer().get() == true) {
handleSubmitAnswer(viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler))
val answer = viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler)
if (answer != null) {
handleSubmitAnswer(answer)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class StateViewModel @Inject constructor(

fun getPendingAnswer(
retrieveAnswerHandler: (List<StateItemViewModel>) -> InteractionAnswerHandler?
): UserAnswer {
): UserAnswer? {
return getPendingAnswerWithoutError(
retrieveAnswerHandler(
getAnswerItemList()
)
) ?: UserAnswer.getDefaultInstance()
)
}

fun canQuicklyToggleBetweenSwahiliAndEnglish(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,24 @@ class StateFragmentTest {
}
}

@Test
@RunOn(TestPlatform.ESPRESSO) // Robolectric tests don't rotate like this to recreate activity
fun testStateFragment_loadExp_secondState_invalidAnswer_changeConfiguration_submitButtonIsEnabled() { // ktlint-disable max-line-length
setUpTestWithLanguageSwitchingFeatureOff()
launchForExploration(TEST_EXPLORATION_ID_2, shouldSavePartialProgress = false).use {
startPlayingExploration()
clickContinueInteractionButton()

typeFractionText("1/")

clickSubmitAnswerButton()

rotateToLandscape()

onView(withId(R.id.submit_answer_button)).check(matches(isDisplayed()))
}
}

@Test
fun testStateFragment_loadExp_secondState_invalidAnswer_updated_submitAnswerIsEnabled() {
setUpTestWithLanguageSwitchingFeatureOff()
Expand Down

0 comments on commit ae9d8ec

Please sign in to comment.