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 #4135 : Added FractionInputInteractionViewTestActivityTest #4268

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
buildToolsVersion "29.0.2"
buildToolsVersion '29.0.2'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to update this?

defaultConfig {
applicationId "org.oppia.android"
minSdkVersion 19
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<activity android:name=".app.testing.HtmlParserTestActivity" />
<activity android:name=".app.testing.HomeTestActivity" />
<activity android:name=".app.testing.InputInteractionViewTestActivity" />
<activity android:name=".app.testing.FractionInputInteractionViewTestActivity" />
<activity android:name=".app.testing.ImageRegionSelectionTestActivity" />
<activity android:name=".app.testing.ImageViewBindingAdaptersTestActivity" />
<activity android:name=".app.testing.MarginBindingAdaptersTestActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import org.oppia.android.app.testing.DragDropTestActivity
import org.oppia.android.app.testing.DrawableBindingAdaptersTestActivity
import org.oppia.android.app.testing.ExplorationInjectionActivity
import org.oppia.android.app.testing.ExplorationTestActivity
import org.oppia.android.app.testing.FractionInputInteractionViewTestActivity
import org.oppia.android.app.testing.HomeFragmentTestActivity
import org.oppia.android.app.testing.HomeTestActivity
import org.oppia.android.app.testing.HtmlParserTestActivity
Expand Down Expand Up @@ -123,6 +124,7 @@ interface ActivityComponentImpl :
fun inject(faqSingleActivity: FAQSingleActivity)
fun inject(forceNetworkTypeActivity: ForceNetworkTypeActivity)
fun inject(forceNetworkTypeTestActivity: ForceNetworkTypeTestActivity)
fun inject(fractionInputInteractionViewTestActivity: FractionInputInteractionViewTestActivity)
fun inject(helpActivity: HelpActivity)
fun inject(homeActivity: HomeActivity)
fun inject(homeFragmentTestActivity: HomeFragmentTestActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.oppia.android.util.math.FractionParser
import javax.inject.Inject

/** [StateItemViewModel] for the fraction input interaction. */
class FractionInteractionViewModel private constructor(
class FractionInteractionViewModel public constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to modify this?

By default, all constructors are public , which effectively amounts to them being visible everywhere the class is visible

https://kotlinlang.org/docs/classes.html#constructors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that we need to remove the access modifier since all constructors are public by default?

interaction: Interaction,
val hasConversationView: Boolean,
val isSplitView: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.oppia.android.app.testing

import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.customview.interaction.FractionInputInteractionView
import org.oppia.android.app.model.Interaction
import org.oppia.android.app.model.WrittenTranslationContext
import org.oppia.android.app.player.state.answerhandling.AnswerErrorCategory
import org.oppia.android.app.player.state.answerhandling.InteractionAnswerErrorOrAvailabilityCheckReceiver
import org.oppia.android.app.player.state.itemviewmodel.FractionInteractionViewModel
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.ActivityFractionInputInteractionViewTestBinding
import org.oppia.android.domain.translation.TranslationController
import javax.inject.Inject

/**
* This is a dummy activity to test input interaction views.
* It contains [FractionInputInteractionView]
*/
class FractionInputInteractionViewTestActivity :
InjectableAppCompatActivity(),
StateKeyboardButtonListener,
InteractionAnswerErrorOrAvailabilityCheckReceiver {
private lateinit var binding: ActivityFractionInputInteractionViewTestBinding
lateinit var fractionInteractionViewModel: FractionInteractionViewModel

@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

@Inject
lateinit var translationController: TranslationController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
binding = DataBindingUtil.setContentView<ActivityFractionInputInteractionViewTestBinding>(
this, R.layout.activity_fraction_input_interaction_view_test
)
fractionInteractionViewModel = FractionInteractionViewModel(
interaction = Interaction.getDefaultInstance(),
hasConversationView = false,
isSplitView = false,
errorOrAvailabilityCheckReceiver = this,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance(),
resourceHandler = resourceHandler,
translationController = translationController
)
binding.fractionInteractionViewModel = fractionInteractionViewModel
}

fun getPendingAnswerErrorOnSubmitClick(v: View) {
fractionInteractionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME)
}

override fun onEditorAction(actionCode: Int) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.databinding.DataBindingUtil
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.customview.interaction.FractionInputInteractionView
import org.oppia.android.app.customview.interaction.NumericInputInteractionView
import org.oppia.android.app.customview.interaction.TextInputInteractionView
import org.oppia.android.app.model.InputInteractionViewTestActivityParams
Expand Down Expand Up @@ -40,7 +39,7 @@ import org.oppia.android.app.player.state.itemviewmodel.MathExpressionInteractio

/**
* This is a dummy activity to test input interaction views.
* It contains [FractionInputInteractionView], [NumericInputInteractionView],and [TextInputInteractionView].
* It contains [NumericInputInteractionView],and [TextInputInteractionView].
*/
class InputInteractionViewTestActivity :
InjectableAppCompatActivity(),
Expand Down Expand Up @@ -124,16 +123,13 @@ class InputInteractionViewTestActivity :
.create(interaction = params.interaction)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to remove this line?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, we don't need line 58 and 59, please check if we need them here.

binding.numericInputViewModel = numericInputViewModel
binding.textInputViewModel = textInputViewModel
binding.fractionInteractionViewModel = fractionInteractionViewModel
binding.ratioInteractionInputViewModel = ratioExpressionInputInteractionViewModel
binding.mathExpressionInteractionsViewModel = mathExpressionViewModel
}

fun getPendingAnswerErrorOnSubmitClick(v: View) {
fractionInteractionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME)
numericInputViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME)
ratioExpressionInputInteractionViewModel
.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<import type="android.view.View"></import>

<variable
name="fractionInteractionViewModel"
type="org.oppia.android.app.player.state.itemviewmodel.FractionInteractionViewModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:gravity="center"
android:orientation="vertical"
tools:context=".testing.FractionInputInteractionViewTestActivity">

<org.oppia.android.app.customview.interaction.FractionInputInteractionView
android:id="@+id/test_fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:fontFamily="sans-serif"
android:hint="@{fractionInteractionViewModel.hintText}"
android:imeOptions="actionDone"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={fractionInteractionViewModel.answerText}"
android:textColor="@color/oppia_primary_text"
android:textColorHint="@color/edit_text_hint"
android:textSize="14sp"
android:textStyle="italic"
app:textChangedListener="@{fractionInteractionViewModel.answerTextWatcher}" />

<TextView
android:id="@+id/fraction_input_error"
style="@style/TextViewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif"
android:minHeight="32dp"
android:text="@{fractionInteractionViewModel.errorMessage}"
android:textColor="@color/edit_text_error"
android:textSize="12sp"
android:visibility="@{fractionInteractionViewModel.errorMessage.length() > 0 ? View.VISIBLE : View.INVISIBLE}" />

<Button
android:id="@+id/submit_button"
style="@style/StateButtonActive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="getPendingAnswerErrorOnSubmitClick"
android:text="Submit"
android:textColor="@color/color_def_white" />
</LinearLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

<import type="android.view.View" />

<variable
name="fractionInteractionViewModel"
type="org.oppia.android.app.player.state.itemviewmodel.FractionInteractionViewModel" />

<variable
name="numericInputViewModel"
type="org.oppia.android.app.player.state.itemviewmodel.NumericInputViewModel" />
Expand Down Expand Up @@ -40,43 +36,6 @@
android:orientation="vertical"
tools:context=".testing.InputInteractionViewTestActivity">

<org.oppia.android.app.customview.interaction.FractionInputInteractionView
android:id="@+id/test_fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:fontFamily="sans-serif"
android:hint="@{fractionInteractionViewModel.hintText}"
android:imeOptions="actionDone"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={fractionInteractionViewModel.answerText}"
android:textColor="@color/oppia_primary_text"
android:textColorHint="@color/edit_text_hint"
android:textSize="14sp"
android:textStyle="italic"
app:textChangedListener="@{fractionInteractionViewModel.answerTextWatcher}" />

<TextView
android:id="@+id/fraction_input_error"
style="@style/TextViewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif"
android:minHeight="32dp"
android:text="@{fractionInteractionViewModel.errorMessage}"
android:textColor="@color/edit_text_error"
android:textSize="12sp"
android:visibility="@{fractionInteractionViewModel.errorMessage.length() > 0 ? View.VISIBLE : View.INVISIBLE}" />

<org.oppia.android.app.customview.interaction.RatioInputInteractionView
android:id="@+id/test_ratio_input_interaction_view"
android:layout_width="match_parent"
Expand Down
Loading