diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt index d13a5dca065..9aabc25f075 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt @@ -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() { @@ -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) + } } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt index 54109859994..82071abed1f 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt @@ -101,12 +101,12 @@ class StateViewModel @Inject constructor( fun getPendingAnswer( retrieveAnswerHandler: (List) -> InteractionAnswerHandler? - ): UserAnswer { + ): UserAnswer? { return getPendingAnswerWithoutError( retrieveAnswerHandler( getAnswerItemList() ) - ) ?: UserAnswer.getDefaultInstance() + ) } fun canQuicklyToggleBetweenSwahiliAndEnglish( diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt index d1d1fb3814c..a2750d5203a 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt @@ -442,6 +442,25 @@ class StateFragmentTest { } } + // Regression test for #4708. + @Test + @RunOn(TestPlatform.ESPRESSO) // Robolectric tests don't rotate like this to recreate activity + fun testStateFragment_loadExp_secondState_invalidAnswer_changeConfiguration_submitButtonExists() { + 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()