From 264b579a5600994e3b0de598124051b2777df591 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 20 Aug 2024 23:09:42 +0300 Subject: [PATCH] Test workflow with TextInputActionTest changes --- .../testing/espresso/TextInputActionTest.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/testing/src/test/java/org/oppia/android/testing/espresso/TextInputActionTest.kt b/testing/src/test/java/org/oppia/android/testing/espresso/TextInputActionTest.kt index 74400b80c8e..223320042e4 100644 --- a/testing/src/test/java/org/oppia/android/testing/espresso/TextInputActionTest.kt +++ b/testing/src/test/java/org/oppia/android/testing/espresso/TextInputActionTest.kt @@ -5,18 +5,34 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.android.material.textfield.TextInputLayout import com.google.common.truth.Truth.assertThat -import org.hamcrest.Description -import org.hamcrest.StringDescription import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.testing.TextInputActionTestActivity import org.oppia.android.testing.espresso.TextInputAction.Companion.hasErrorText -import org.oppia.android.testing.espresso.TextInputAction.Companion.hasNoErrorText import org.robolectric.annotation.LooperMode @RunWith(AndroidJUnit4::class) @LooperMode(LooperMode.Mode.PAUSED) class TextInputActionTest { + @get:Rule + var activityRule = + ActivityScenarioRule( + TextInputActionTestActivity.createIntent(ApplicationProvider.getApplicationContext()) + ) + + @Test + fun testTextExistsMatcher_errorMatchesExpectedText_matchesSafelyReturnsTrue() { + activityRule.scenario.onActivity { activity -> + val expectedErrorText = "Incorrect Administrator PIN. Please try again." + val textInputLayout = TextInputLayout(activity) + + textInputLayout.error = "Incorrect Administrator PIN. Please try again." + + val errorTextExisted = hasErrorText(expectedErrorText) + val result: Boolean = errorTextExisted.matches(textInputLayout) + assertThat(result).isTrue() + } + } }