From a37e090caaed28dba600824f25bae34713c97880 Mon Sep 17 00:00:00 2001
From: nikitamarysolomanpvt
<54615666+nikitamarysolomanpvt@users.noreply.github.com>
Date: Wed, 23 Oct 2019 15:04:00 +0530
Subject: [PATCH] Fix #150, #155: TextInputInteractionView and
FractionInputInteractionView low-fi (#246)
* NumberInputInteractionView dynamically created on state interaction id NumericInput from dummy data welcome.json ,welcome.json file "init_state_name"modified to "Numeric input",
* NumberInputInteractionView dynamically created on state interaction id NumericInput from dummy data welcome.json
* added fetch button, and fetch textview to fetch the data from dynamic numbertextinputlayout onbutton click. on button click listner implemented
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* numericInputTypeView test case is in progress
* numericInputTypeView test case is in progress
* nit changes as per #223
* nit changes as per #223
* On configuration changes save and restore the text of numericInputType
* Test Cases for NumericInputInteractionView,
Moved test case to StateFragment
* Test Cases for NumericInputInteractionView,
Moved test case to StateFragment,PR suggestions updated
* PR suggestions updated
* PR suggestions updated
* Merge branch 'develop' of https://github.com/oppia/oppia-android into topic-player-multiple-tabs
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
# app/src/main/res/values/styles.xml
* nit changes as per PR review
* nit changes as per PR review
* nit changes as per PR review
* nit changes as per PR review
* Number input test Activity test cases
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* setReal type in getPendingAnswer
* updated test cases, disabled long click to prevent pasting value
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* nit changes
* NumericInputInteractionViewTestActivity renamed to InputInteractionViewTestActivity and test case updated
* nit changes
* nit changes
* nit changes
* nit
* NumericInputInteractionView attributes are moved to xml,testcases updated as per PR review of Ben, other nit changes
* NumericInputInteractionView attributes are moved to xml,testcases updated as per PR review of Ben, other nit changes
* TextInputInteractionView
* TextInputInteractionView
* test cases
* nit
* nit
* nit
* nit
* nit
* Merge branches 'develop' and 'lowfi-input-interaction-views' of https://github.com/oppia/oppia-android into lowfi-input-interaction-views
# Conflicts:
# app/src/main/java/org/oppia/app/activity/InputInteractionViewTestActivity.kt
# app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt
# app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml
# app/src/main/res/values/dimens.xml
# app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt
* nit
* nit
* nit
* nit
* Merge branches 'develop' and 'text-input-lowfi-numeric-input-interaction-view-part-2' of https://github.com/oppia/oppia-android into text-input-lowfi-numeric-input-interaction-view-part-2
# Conflicts:
# app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt
* nit
* NumberWithUnitsInputInteractionView
* nit
* nit
* NumberWithUnitsInputInteractionView
* moved InputInteractionViewTestActivityTest to testing folder
---
.../FractionInputInteractionView.kt | 30 +++
.../NumericInputInteractionView.kt | 2 +-
.../interaction/TextInputInteractionView.kt | 28 +++
.../app/parser/StringToFractionParser.kt | 34 +++
.../InputInteractionViewTestActivity.kt | 6 +-
...ty_numeric_input_interaction_view_test.xml | 29 ++-
.../InputInteractionViewTestActivityTest.kt | 84 -------
.../InputInteractionViewTestActivityTest.kt | 225 ++++++++++++++++++
8 files changed, 350 insertions(+), 88 deletions(-)
create mode 100644 app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt
create mode 100644 app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt
create mode 100644 app/src/main/java/org/oppia/app/parser/StringToFractionParser.kt
rename app/src/main/java/org/oppia/app/{activity => testing}/InputInteractionViewTestActivity.kt (62%)
delete mode 100644 app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt
create mode 100644 app/src/sharedTest/java/org/oppia/app/testing/InputInteractionViewTestActivityTest.kt
diff --git a/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt
new file mode 100644
index 00000000000..7fe57dfc8bd
--- /dev/null
+++ b/app/src/main/java/org/oppia/app/customview/interaction/FractionInputInteractionView.kt
@@ -0,0 +1,30 @@
+package org.oppia.app.customview.interaction
+
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.EditText
+import org.oppia.app.model.InteractionObject
+import org.oppia.app.parser.StringToFractionParser
+
+// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
+// digits="0123456789/-"
+// hint="Write fraction here."
+// inputType="text"
+// background="@drawable/edit_text_background"
+// maxLength="200".
+
+/** The custom EditText class for fraction input interaction view. */
+class FractionInputInteractionView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyle: Int = android.R.attr.editTextStyle
+) : EditText(context, attrs, defStyle), InteractionAnswerRetriever {
+
+ override fun getPendingAnswer(): InteractionObject {
+ val interactionObjectBuilder = InteractionObject.newBuilder()
+ if (!text.isNullOrEmpty()) {
+ interactionObjectBuilder.fraction = StringToFractionParser().getFractionFromString(text = text.toString())
+ }
+ return interactionObjectBuilder.build()
+ }
+}
diff --git a/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt
index ebad8a5c729..393c93d9c3f 100644
--- a/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt
+++ b/app/src/main/java/org/oppia/app/customview/interaction/NumericInputInteractionView.kt
@@ -22,7 +22,7 @@ class NumericInputInteractionView @JvmOverloads constructor(
override fun getPendingAnswer(): InteractionObject {
val interactionObjectBuilder = InteractionObject.newBuilder()
if (!text.isNullOrEmpty()) {
- interactionObjectBuilder.setReal(text.toString().toDouble())
+ interactionObjectBuilder.real = text.toString().toDouble()
}
return interactionObjectBuilder.build()
}
diff --git a/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt b/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt
new file mode 100644
index 00000000000..ad3e2355609
--- /dev/null
+++ b/app/src/main/java/org/oppia/app/customview/interaction/TextInputInteractionView.kt
@@ -0,0 +1,28 @@
+package org.oppia.app.customview.interaction
+
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.EditText
+import org.oppia.app.model.InteractionObject
+
+// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
+// hint="Write here."
+// inputType="text"
+// background="@drawable/edit_text_background"
+// maxLength="200".
+
+/** The custom EditText class for text input interaction view. */
+class TextInputInteractionView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyle: Int = android.R.attr.editTextStyle
+) : EditText(context, attrs, defStyle), InteractionAnswerRetriever {
+
+ override fun getPendingAnswer(): InteractionObject {
+ val interactionObjectBuilder = InteractionObject.newBuilder()
+ if (!text.isNullOrEmpty()) {
+ interactionObjectBuilder.normalizedString = text.toString()
+ }
+ return interactionObjectBuilder.build()
+ }
+}
diff --git a/app/src/main/java/org/oppia/app/parser/StringToFractionParser.kt b/app/src/main/java/org/oppia/app/parser/StringToFractionParser.kt
new file mode 100644
index 00000000000..ad60458c009
--- /dev/null
+++ b/app/src/main/java/org/oppia/app/parser/StringToFractionParser.kt
@@ -0,0 +1,34 @@
+package org.oppia.app.parser
+
+import org.oppia.app.model.Fraction
+
+/** This class contains method that helps to parse string to fraction. */
+class StringToFractionParser {
+ fun getFractionFromString(text: String): Fraction {
+ var inputText: String = text
+ var isNegative = false
+ var numerator = "0"
+ var denominator = "0"
+ var wholeNumber = "0"
+ val fractionObjectBuilder = Fraction.newBuilder()
+ if (inputText.startsWith("-"))
+ isNegative = true
+ inputText = inputText.replace("-", "").trim()
+ wholeNumber = if (inputText.contains("/") && inputText.contains(" ")) {
+ inputText.substringBefore(" ")
+ } else if (inputText.contains("/")) {
+ wholeNumber
+ } else {
+ inputText
+ }
+ inputText =
+ if (inputText.contains(" ")) inputText.substringAfter(" ").replace(" ", "") else inputText.replace(" ", "")
+ if (inputText.contains("/")) {
+ numerator = inputText.substringBefore("/")
+ denominator = inputText.substringAfter("/")
+ }
+ fractionObjectBuilder.setIsNegative(isNegative).setNumerator(numerator.toInt())
+ .setDenominator(denominator.toInt()).wholeNumber = wholeNumber.toInt()
+ return fractionObjectBuilder.build()
+ }
+}
diff --git a/app/src/main/java/org/oppia/app/activity/InputInteractionViewTestActivity.kt b/app/src/main/java/org/oppia/app/testing/InputInteractionViewTestActivity.kt
similarity index 62%
rename from app/src/main/java/org/oppia/app/activity/InputInteractionViewTestActivity.kt
rename to app/src/main/java/org/oppia/app/testing/InputInteractionViewTestActivity.kt
index a46f7b01a08..daac9452205 100644
--- a/app/src/main/java/org/oppia/app/activity/InputInteractionViewTestActivity.kt
+++ b/app/src/main/java/org/oppia/app/testing/InputInteractionViewTestActivity.kt
@@ -1,13 +1,15 @@
-package org.oppia.app.activity
+package org.oppia.app.testing
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import org.oppia.app.R
import org.oppia.app.customview.interaction.NumericInputInteractionView
+import org.oppia.app.customview.interaction.TextInputInteractionView
+import org.oppia.app.customview.interaction.FractionInputInteractionView
/**
* This is a dummy activity to test input interaction views.
- * It contains [NumericInputInteractionView] .
+ * It contains [NumericInputInteractionView], [TextInputInteractionView] and [FractionInputInteractionView].
*/
class InputInteractionViewTestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
diff --git a/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml b/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml
index c53db5bff2c..807f98d0bb4 100644
--- a/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml
+++ b/app/src/main/res/layout/activity_numeric_input_interaction_view_test.xml
@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
- tools:context=".activity.InputInteractionViewTestActivity">
+ tools:context=".testing.InputInteractionViewTestActivity">
+
+
diff --git a/app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt b/app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt
deleted file mode 100644
index dd28e62b571..00000000000
--- a/app/src/sharedTest/java/org/oppia/app/activity/InputInteractionViewTestActivityTest.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.oppia.app.activity
-
-import android.content.res.Configuration
-import androidx.test.espresso.Espresso.onView
-import androidx.test.espresso.matcher.ViewMatchers.withId
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.rule.ActivityTestRule
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.oppia.app.R
-import org.oppia.app.model.InteractionObject
-import androidx.test.core.app.ActivityScenario
-import androidx.test.espresso.action.ViewActions.typeText
-import androidx.test.espresso.assertion.ViewAssertions
-import androidx.test.espresso.matcher.ViewMatchers
-import com.google.common.truth.Truth.assertThat
-import org.junit.Before
-import org.oppia.app.customview.interaction.NumericInputInteractionView
-
-/** Tests for [InputInteractionViewTestActivity]. */
-@RunWith(AndroidJUnit4::class)
-class InputInteractionViewTestActivityTest {
- @get:Rule
- var activityTestRule: ActivityTestRule = ActivityTestRule(
- InputInteractionViewTestActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false
- )
- private lateinit var activityScenario: ActivityScenario
-
- @Before
- fun setUp() {
- activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
- }
-
- @Test
- fun testNumericInputInteractionView_withNoInputText_hasCorrectPendingAnswerType() {
- activityScenario.onActivity { activity ->
- val textAnswerRetriever =
- activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
- assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
- assertThat(textAnswerRetriever.getPendingAnswer().real).isWithin(1e-5).of(0.0)
- }
- }
-
- @Test
- fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswer() {
- onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9"))
- activityScenario.onActivity { activity ->
- val textAnswerRetriever =
- activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
- assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
- assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.REAL)
- assertThat(textAnswerRetriever.getPendingAnswer().real).isEqualTo(9.0)
- }
- }
-
- @Test
- fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswerWithDecimalValues() {
- onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9.5"))
- activityScenario.onActivity { activity ->
- val textAnswerRetriever =
- activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
- assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.REAL)
- assertThat(textAnswerRetriever.getPendingAnswer().real).isEqualTo(9.5)
- }
- }
-
- @Test
- fun testNumberInputInteractionView_withInputtedText_onConfigurationChange_hasCorrectPendingAnswer() {
- onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9"))
- activityScenario.onActivity { activity ->
- activity.requestedOrientation = Configuration.ORIENTATION_LANDSCAPE
- }
- onView(withId(R.id.test_number_input_interaction_view)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
- .check(
- ViewAssertions.matches(ViewMatchers.withText("9"))
- )
- activityScenario.recreate()
- onView(withId(R.id.test_number_input_interaction_view)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
- .check(
- ViewAssertions.matches(ViewMatchers.withText("9"))
- )
- }
-}
diff --git a/app/src/sharedTest/java/org/oppia/app/testing/InputInteractionViewTestActivityTest.kt b/app/src/sharedTest/java/org/oppia/app/testing/InputInteractionViewTestActivityTest.kt
new file mode 100644
index 00000000000..3b7a1092adb
--- /dev/null
+++ b/app/src/sharedTest/java/org/oppia/app/testing/InputInteractionViewTestActivityTest.kt
@@ -0,0 +1,225 @@
+package org.oppia.app.testing
+
+import android.content.res.Configuration
+import androidx.test.espresso.Espresso.onView
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.rule.ActivityTestRule
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.oppia.app.R
+import org.oppia.app.model.InteractionObject
+import androidx.test.core.app.ActivityScenario
+import androidx.test.espresso.action.ViewActions.typeText
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.espresso.matcher.ViewMatchers.withText
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.oppia.app.customview.interaction.FractionInputInteractionView
+import org.oppia.app.customview.interaction.NumericInputInteractionView
+import org.oppia.app.customview.interaction.TextInputInteractionView
+import org.oppia.app.testing.InputInteractionViewTestActivity
+
+/** Tests for [InputInteractionViewTestActivity]. */
+@RunWith(AndroidJUnit4::class)
+class InputInteractionViewTestActivityTest {
+ @get:Rule
+ var activityTestRule: ActivityTestRule = ActivityTestRule(
+ InputInteractionViewTestActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false
+ )
+ private lateinit var activityScenario: ActivityScenario
+
+ @Before
+ fun setUp() {
+ activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ }
+
+ @Test
+ fun testNumericInputInteractionView_withNoInputText_hasCorrectPendingAnswerType() {
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().real).isWithin(1e-5).of(0.0)
+ }
+ }
+
+ @Test
+ fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswer() {
+ onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.REAL)
+ assertThat(textAnswerRetriever.getPendingAnswer().real).isEqualTo(9.0)
+ }
+ }
+
+ @Test
+ fun testNumericInputInteractionView_withInputtedText_hasCorrectPendingAnswerWithDecimalValues() {
+ onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9.5"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_number_input_interaction_view) as NumericInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.REAL)
+ assertThat(textAnswerRetriever.getPendingAnswer().real).isEqualTo(9.5)
+ }
+ }
+
+ @Test
+ fun testNumberInputInteractionView_withInputtedText_onConfigurationChange_hasCorrectPendingAnswer() {
+ onView(withId(R.id.test_number_input_interaction_view)).perform(typeText("9"))
+ activityScenario.onActivity { activity ->
+ activity.requestedOrientation = Configuration.ORIENTATION_LANDSCAPE
+ }
+ onView(withId(R.id.test_number_input_interaction_view)).check(matches(isDisplayed())).check(matches(withText("9")))
+ }
+
+ fun testTextInputInteractionView_withNoInputText_hasCorrectPendingAnswerType() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_text_input_interaction_view) as TextInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().normalizedString).isEmpty()
+ }
+ }
+
+ @Test
+ fun testTextInputInteractionView_withInputtedText_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_text_input_interaction_view)).perform(typeText("abc"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_text_input_interaction_view) as TextInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.NORMALIZED_STRING)
+ assertThat(textAnswerRetriever.getPendingAnswer().normalizedString).isEqualTo("abc")
+ }
+ }
+
+ @Test
+ fun testTextInputInteractionView_withInputtedText_onConfigurationChange_hasCorrectPendingAnswer() {
+ onView(withId(R.id.test_text_input_interaction_view)).perform(typeText("abc"))
+ activityScenario.onActivity { activity ->
+ activity.requestedOrientation = Configuration.ORIENTATION_LANDSCAPE
+ }
+ onView(withId(R.id.test_text_input_interaction_view)).check(matches(isDisplayed())).check(matches(withText("abc")))
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withNoInputText_hasCorrectPendingAnswerType() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.denominator).isEqualTo(0)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.numerator).isEqualTo(0)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.wholeNumber).isEqualTo(0)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedNegativeWholeNumberText_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("-9"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(true)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.wholeNumber).isEqualTo(9)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedWholeNumberText_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("9"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(false)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.wholeNumber).isEqualTo(9)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedFractionText_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("9/10"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(false)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.numerator).isEqualTo(9)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.denominator).isEqualTo(10)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedNegativeValue_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("-9/10"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(true)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.numerator).isEqualTo(9)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.denominator).isEqualTo(10)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedWholeNumberValue_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("5 9/10"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(false)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.wholeNumber).isEqualTo(5)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.numerator).isEqualTo(9)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.denominator).isEqualTo(10)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedNegativeWholeNumberValue_hasCorrectPendingAnswer() {
+ val activityScenario = ActivityScenario.launch(InputInteractionViewTestActivity::class.java)
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("-5 9/10"))
+ activityScenario.onActivity { activity ->
+ val textAnswerRetriever =
+ activity.findViewById(R.id.test_fraction_input_interaction_view) as FractionInputInteractionView
+ assertThat(textAnswerRetriever.getPendingAnswer()).isInstanceOf(InteractionObject::class.java)
+ assertThat(textAnswerRetriever.getPendingAnswer().objectTypeCase).isEqualTo(InteractionObject.ObjectTypeCase.FRACTION)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.isNegative).isEqualTo(true)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.wholeNumber).isEqualTo(5)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.numerator).isEqualTo(9)
+ assertThat(textAnswerRetriever.getPendingAnswer().fraction.denominator).isEqualTo(10)
+ }
+ }
+
+ @Test
+ fun testFractionInputInteractionView_withInputtedText_onConfigurationChange_hasCorrectPendingAnswer() {
+ onView(withId(R.id.test_fraction_input_interaction_view)).perform(typeText("9/5"))
+ activityScenario.onActivity { activity ->
+ activity.requestedOrientation = Configuration.ORIENTATION_LANDSCAPE
+ }
+ onView(withId(R.id.test_fraction_input_interaction_view)).check(matches(isDisplayed()))
+ .check(matches(withText("9/5")))
+ }
+}