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 #4708: Don't submit answer if it's invalid according to the input #5202

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -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)
}
Comment on lines +221 to +224
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer will never be null, since in StateViewModel, a default instance is always returned, so it might be useful to check that the return is not a default instance,.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your solution, you have modified the viewmodel function to be nullable, but I am concerned that you have not handled the null case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that there is anything else to do in the null case. There's already code elsewhere responsible for showing the error and disabling the submit button, for example.

So the handling of the null case here is just do to nothing, as far as I know.

}
}

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,25 @@ class StateFragmentTest {
}
}

// Regression test for #4708.
Bontrey marked this conversation as resolved.
Show resolved Hide resolved
@Test
@RunOn(TestPlatform.ESPRESSO) // Robolectric tests don't rotate like this to recreate activity
fun testStateFragment_loadExp_secondState_invalidAnswer_changeConfiguration_submitButtonExists() {
Bontrey marked this conversation as resolved.
Show resolved Hide resolved
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
Loading