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

Added FractionInputInteractionViewTest.kt #4242

Original file line number Diff line number Diff line change
Expand Up @@ -127,156 +127,6 @@ class InputInteractionViewTestActivityTest {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

@Test
fun testFractionInput_withNoInput_hasCorrectPendingAnswerType() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.fraction.denominator).isEqualTo(0)
assertThat(pendingAnswer.answer.fraction.numerator).isEqualTo(0)
assertThat(pendingAnswer.answer.fraction.wholeNumber).isEqualTo(0)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withNegativeNumber_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(editTextInputAction.appendText("-9"))
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(true)
assertThat(pendingAnswer.answer.fraction.wholeNumber).isEqualTo(9)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withWholeNumber_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(editTextInputAction.appendText("9"))
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(false)
assertThat(pendingAnswer.answer.fraction.wholeNumber).isEqualTo(9)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withFraction_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"9/10"
)
)
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(false)
assertThat(pendingAnswer.answer.fraction.numerator).isEqualTo(9)
assertThat(pendingAnswer.answer.fraction.denominator).isEqualTo(10)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withNegativeFraction_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"-9/10"
)
)
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(true)
assertThat(pendingAnswer.answer.fraction.numerator).isEqualTo(9)
assertThat(pendingAnswer.answer.fraction.denominator).isEqualTo(10)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withMixedNumber_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"5 9/10"
)
)
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(false)
assertThat(pendingAnswer.answer.fraction.wholeNumber).isEqualTo(5)
assertThat(pendingAnswer.answer.fraction.numerator).isEqualTo(9)
assertThat(pendingAnswer.answer.fraction.denominator).isEqualTo(10)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withNegativeMixedNumber_hasCorrectPendingAnswer() {
val activityScenario = ActivityScenario.launch(
InputInteractionViewTestActivity::class.java
)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"-55 59/9"
)
)
activityScenario.onActivity { activity ->
val pendingAnswer = activity.fractionInteractionViewModel.getPendingAnswer()
assertThat(pendingAnswer.answer).isInstanceOf(InteractionObject::class.java)
assertThat(pendingAnswer.answer.objectTypeCase).isEqualTo(
InteractionObject.ObjectTypeCase.FRACTION
)
assertThat(pendingAnswer.answer.fraction.isNegative).isEqualTo(true)
assertThat(pendingAnswer.answer.fraction.wholeNumber).isEqualTo(55)
assertThat(pendingAnswer.answer.fraction.numerator).isEqualTo(59)
assertThat(pendingAnswer.answer.fraction.denominator).isEqualTo(9)
}
}

@Test
@Ignore("Landscape not properly supported") // TODO(#56): Reenable once landscape is supported.
fun testFractionInput_withFraction_configChange_hasCorrectPendingAnswer() {
Expand All @@ -296,225 +146,6 @@ class InputInteractionViewTestActivityTest {
.check(matches(withText("9/5")))
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and will not be used by user
fun testFractionInput_withNegativeSignOtherThanAt0_numberFormatErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"55-"
)
)
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_format
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withNegativeSignAt0MoreThan1_numberFormatErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"--55"
)
)
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_format
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withDividerMoreThanOnce_numberFormatErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"5/5/"
)
)
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_format
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withDividerAtStart_numberFormatErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"/5"
)
)
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_format
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withPartialMixedNumber_numberFormatErrorIsNotDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"5 5/"
)
)
onView(withId(R.id.fraction_input_error)).check(matches(withText("")))
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withPartialMixedNumberSubmit_numberFormatErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"5 5/"
)
)
closeSoftKeyboard()
onView(withId(R.id.submit_button)).check(matches(isDisplayed())).perform(click())
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_format
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withMixedNumber_submit_noErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"3 1/2"
)
)
closeSoftKeyboard()
onView(withId(R.id.submit_button)).check(matches(isDisplayed())).perform(click())
onView(withId(R.id.fraction_input_error)).check(matches(withText("")))
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withDivideByZero_errorIsNotDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"1/0"
)
)
onView(withId(R.id.fraction_input_error)).check(matches(withText("")))
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withDivideByZero_submit_divideByZeroErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"1/0"
)
)
closeSoftKeyboard()
onView(withId(R.id.submit_button)).check(matches(isDisplayed())).perform(click())
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_divide_by_zero
)
)
)
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withInvalidCharacter_invalidCharacterErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java).use {
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"."
)
)
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_invalid_chars
)
)
)
}
}

@Test
@DisableAccessibilityChecks // Disabled, as InputInteractionViewTestActivity is a test file and
// will not be used by user
fun testFractionInput_withLong_submit_numberTooLongErrorIsDisplayed() {
ActivityScenario.launch(InputInteractionViewTestActivity::class.java).use {
onView(withId(R.id.test_fraction_input_interaction_view))
.perform(
editTextInputAction.appendText(
"12345678"
)
)
closeSoftKeyboard()
onView(withId(R.id.submit_button)).check(matches(isDisplayed())).perform(click())
onView(withId(R.id.fraction_input_error))
.check(
matches(
withText(
R.string.fraction_error_larger_than_seven_digits
)
)
)
}
}

@Test
fun testNumericInput_withNoInput_hasCorrectPendingAnswerType() {
val activityScenario = ActivityScenario.launch(
Expand Down
Loading