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

Fix part of #3861: Submit-time errors permanently break the answer submission flow #4230

Merged
merged 8 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -29,6 +29,8 @@ class StringToFractionParser {
fun getSubmitTimeError(text: String): FractionParsingError {
if (invalidCharsLengthRegex.find(text) != null)
return FractionParsingError.NUMBER_TOO_LONG
if (text.endsWith("/"))
return FractionParsingError.INVALID_FORMAT
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
val fraction = parseFraction(text)
return when {
fraction == null -> FractionParsingError.INVALID_FORMAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ class StringToFractionParserTest {
}
}

@Test
fun testSubmitTimeError_noDenominator_returnsInvalidFormat() {
val error = stringToFractionParser.getSubmitTimeError("3/")
assertThat(error).isEqualTo(StringToFractionParser.FractionParsingError.INVALID_FORMAT)
}

@Test
fun testSubmitTimeError_noDenominator_invalidFormat_hasRelevantErrorMessage() {
activityRule.scenario.onActivity { activity ->
val errorMessage = stringToFractionParser.getSubmitTimeError("3/")
.getErrorMessageFromStringRes(activity.appLanguageResourceHandler)
assertThat(errorMessage)
.isEqualTo("Please enter a valid fraction (e.g., 5/3 or 1 2/3)")
}
}

@Test
fun testRealTimeError_regularFraction_returnsValid() {
val error = stringToFractionParser.getRealTimeAnswerError("2/3")
Expand Down