From 232190d43c0a814163bc1d12af567d6183a23b35 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 20 Aug 2024 22:09:44 +0300 Subject: [PATCH 1/2] Test workflow with TextInputActionTest changes --- .../testing/espresso/TextInputActionTest.kt | 80 ------------------- 1 file changed, 80 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 34d7f816950..74400b80c8e 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 @@ -19,84 +19,4 @@ import org.robolectric.annotation.LooperMode @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() - } - } - - @Test - fun testTextExistsMatcher_errorDoesNotMatchesExpectedText_matchesSafelyReturnsFalse() { - activityRule.scenario.onActivity { activity -> - val expectedErrorText = "Incorrect Administrator PIN. Please try again." - val textInputLayout = TextInputLayout(activity) - - textInputLayout.error = "This name is already in use by another profile." - - val errorTextExisted = hasErrorText(expectedErrorText) - val result: Boolean = errorTextExisted.matches(textInputLayout) - assertThat(result).isFalse() - } - } - - @Test - fun testTextExistsMatcher_descriptionMatchesExpectedDescription() { - val errorText = "Incorrect Administrator PIN. Please try again." - val expectedDescription = - "The expected error text is 'Incorrect Administrator PIN. Please try again.'" - - val errorTextExisted = hasErrorText(errorText) - var description: Description = StringDescription() - errorTextExisted.describeTo(description) - - assertThat(description.toString()).isEqualTo(expectedDescription) - } - - @Test - fun testTextDoesNotExistMatcher_errorTextIsEmpty_matchesSafelyReturnsTrue() { - activityRule.scenario.onActivity { activity -> - val textInputLayout = TextInputLayout(activity) - val errorTextNotExisted = hasNoErrorText() - - val result: Boolean = errorTextNotExisted.matches(textInputLayout) - assertThat(result).isTrue() - } - } - - @Test - fun testTextDoesNotExistMatcher_errorTextIsNotEmpty_matchesSafelyReturnsFalse() { - activityRule.scenario.onActivity { activity -> - val textInputLayout = TextInputLayout(activity) - textInputLayout.error = "Error text is not empty" - val errorTextNotExisted = hasNoErrorText() - - val result: Boolean = errorTextNotExisted.matches(textInputLayout) - assertThat(result).isFalse() - } - } - - @Test - fun testTextDoesNotExistMatcher_descriptionMatchesExpectedDescription() { - val expectedDescription = "There is no error text." - - val errorTextNotExisted = hasNoErrorText() - var description: Description = StringDescription() - errorTextNotExisted.describeTo(description) - - assertThat(description.toString()).isEqualTo(expectedDescription) - } } From 264b579a5600994e3b0de598124051b2777df591 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 20 Aug 2024 23:09:42 +0300 Subject: [PATCH 2/2] 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() + } + } }