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 #5205

Merged
merged 3 commits into from
Oct 28, 2023
Merged
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)
}
}
}

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()
)
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
}

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_invalidAnswer_changeConfiguration_submitButtonIsDisplayed() {
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