From e6df4eb009a4de84d79b8729bc295b3860b5d30e Mon Sep 17 00:00:00 2001 From: vrajdesai78 Date: Tue, 7 Dec 2021 23:35:25 +0530 Subject: [PATCH] AccessbilityTestRule file deleted --- .../android/testing/AccessibilityTestRule.kt | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 testing/src/main/java/org/oppia/android/testing/AccessibilityTestRule.kt diff --git a/testing/src/main/java/org/oppia/android/testing/AccessibilityTestRule.kt b/testing/src/main/java/org/oppia/android/testing/AccessibilityTestRule.kt deleted file mode 100644 index 4f7fb9ac428..00000000000 --- a/testing/src/main/java/org/oppia/android/testing/AccessibilityTestRule.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.oppia.android.testing - -import android.os.Build -import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers.withClassName -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheckNames -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import org.hamcrest.CoreMatchers.`is` -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.CoreMatchers.endsWith -import org.junit.rules.TestRule -import org.junit.runner.Description -import org.junit.runners.model.Statement - -// TODO(#3351): Merge AccessibilityTestRule with OppiaTestRule. -private const val DEFAULT_ENABLED_STATE = true - -/** - * JUnit rule to enable [AccessibilityChecks] on Espresso. This does not work when run on Robolectric. - * - * Reference: https://developer.android.com/training/testing/espresso/accessibility-checking - */ -class AccessibilityTestRule : TestRule { - override fun apply(base: Statement?, description: Description?): Statement { - return object : Statement() { - override fun evaluate() { - val isEnabled = description.areAccessibilityChecksEnabled() - if (getCurrentPlatform() == TestPlatform.ESPRESSO && isEnabled) { - AccessibilityChecks.enable().apply { - // Suppressing failures for all views which matches with below conditions as we do not - // want to change the UI to pass these failures as it will change the expected behaviour - // for learner. - setSuppressingResultMatcher( - allOf( - matchesCheckNames(`is`("TouchTargetSizeViewCheck")), - matchesViews(withContentDescription("More options")), - matchesViews(withClassName(endsWith("OverflowMenuButton"))) - ) - ) - }.setRunChecksFromRootView(true) - } - base?.evaluate() - } - } - } - - private fun getCurrentPlatform(): TestPlatform { - return if (Build.FINGERPRINT.contains("robolectric", ignoreCase = true)) { - TestPlatform.ROBOLECTRIC - } else { - TestPlatform.ESPRESSO - } - } - - private companion object { - private fun Description?.areAccessibilityChecksEnabled(): Boolean { - val methodAccessibilityStatus = this?.areAccessibilityTestsEnabledForMethod() - val classAccessibilityStatus = this?.testClass?.areAccessibilityTestsEnabledForClass() - return methodAccessibilityStatus ?: classAccessibilityStatus ?: DEFAULT_ENABLED_STATE - } - - private fun Description.areAccessibilityTestsEnabledForMethod(): Boolean { - return getAnnotation(DisableAccessibilityChecks::class.java) == null - } - - private fun Class.areAccessibilityTestsEnabledForClass(): Boolean { - return getAnnotation(DisableAccessibilityChecks::class.java) == null - } - } -}