[WIP] Adding Espresso test for orientation change (#2814)

* first commit

* initial commit

* added UI test for more activities

* added more tests

* improved code quality

* reverted code
This commit is contained in:
Vanshika Arora 2019-04-02 09:04:05 +05:30 committed by Vivek Maskara
parent dcbf076965
commit 4578600c1e
12 changed files with 129 additions and 6 deletions

View file

@ -16,7 +16,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@MediumTest
@RunWith(AndroidJUnit4::class)
class AchievementsActivityTest {
@get:Rule

View file

@ -0,0 +1,19 @@
package fr.free.nrw.commons
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import fr.free.nrw.commons.category.CategoryImagesActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class CategoryImagesActivityTest {
@get:Rule
var activityRule = ActivityTestRule(CategoryImagesActivity::class.java)
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -0,0 +1,19 @@
package fr.free.nrw.commons
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import fr.free.nrw.commons.explore.categories.ExploreActivity
@RunWith(AndroidJUnit4::class)
class ExploreActivityTest {
@get:Rule
var activityRule = ActivityTestRule(ExploreActivity::class.java)
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -11,7 +11,6 @@ import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.isInternal
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.filters.MediumTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import fr.free.nrw.commons.auth.LoginActivity
@ -23,8 +22,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@MediumTest
@RunWith(AndroidJUnit4::class)
class LoginActivityTest {
@get:Rule
@ -53,4 +50,9 @@ class LoginActivityTest {
.perform(ViewActions.click())
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL)));
}
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -0,0 +1,19 @@
package fr.free.nrw.commons
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import fr.free.nrw.commons.contributions.MainActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
var activityRule = ActivityTestRule(MainActivity::class.java)
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -47,4 +47,9 @@ class NavigationBaseActivityTest {
UITestHelper.sleep(500)
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId))
}
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -0,0 +1,19 @@
package fr.free.nrw.commons
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import fr.free.nrw.commons.explore.SearchActivity
@RunWith(AndroidJUnit4::class)
class SearchActivityTest {
@get:Rule
var activityRule = ActivityTestRule(SearchActivity::class.java)
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -150,4 +150,9 @@ class SettingsActivityTest {
.inAdapterView(withId(android.R.id.list))
.check(matches(not(isEnabled())))
}
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -8,7 +8,6 @@ import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.filters.MediumTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import fr.free.nrw.commons.auth.LoginActivity
@ -18,7 +17,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@MediumTest
@RunWith(AndroidJUnit4::class)
class SignupTest {
@get:Rule
@ -43,4 +41,9 @@ class SignupTest {
intended(hasComponent(SignupActivity::class.java.name))
Intents.release()
}
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -1,10 +1,13 @@
package fr.free.nrw.commons
import android.app.Activity
import android.content.pm.ActivityInfo
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.rule.ActivityTestRule
import fr.free.nrw.commons.utils.StringUtils
import timber.log.Timber
@ -57,5 +60,11 @@ class UITestHelper {
throw NotImplementedError("Configure your beta account's password")
} else return password
}
fun <T: Activity> changeOrientation(activityRule: ActivityTestRule<T>){
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
assert(activityRule.activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
assert(activityRule.activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
}
}
}

View file

@ -0,0 +1,19 @@
package fr.free.nrw.commons
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import fr.free.nrw.commons.upload.UploadActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class UploadActivityTest {
@get:Rule
var activityRule = ActivityTestRule(UploadActivity::class.java)
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}

View file

@ -98,4 +98,9 @@ class WelcomeActivityTest {
assert(activityRule.activity.isDestroyed)
}}
}
@Test
fun orientationChange() {
UITestHelper.changeOrientation(activityRule)
}
}