Skip to content

Commit 4578600

Browse files
vanshikaaroramaskaravivek
authored andcommitted
[WIP] Adding Espresso test for orientation change (commons-app#2814)
* first commit * initial commit * added UI test for more activities * added more tests * improved code quality * reverted code
1 parent dcbf076 commit 4578600

12 files changed

+129
-6
lines changed

app/src/androidTest/java/fr/free/nrw/commons/AchievementsActivityTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.junit.Rule
1616
import org.junit.Test
1717
import org.junit.runner.RunWith
1818

19-
@MediumTest
2019
@RunWith(AndroidJUnit4::class)
2120
class AchievementsActivityTest {
2221
@get:Rule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.rule.ActivityTestRule
4+
import androidx.test.runner.AndroidJUnit4
5+
import fr.free.nrw.commons.category.CategoryImagesActivity
6+
import org.junit.Rule
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class CategoryImagesActivityTest {
12+
@get:Rule
13+
var activityRule = ActivityTestRule(CategoryImagesActivity::class.java)
14+
15+
@Test
16+
fun orientationChange() {
17+
UITestHelper.changeOrientation(activityRule)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.rule.ActivityTestRule
4+
import androidx.test.runner.AndroidJUnit4
5+
import org.junit.Rule
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
import fr.free.nrw.commons.explore.categories.ExploreActivity
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class ExploreActivityTest {
12+
@get:Rule
13+
var activityRule = ActivityTestRule(ExploreActivity::class.java)
14+
15+
@Test
16+
fun orientationChange() {
17+
UITestHelper.changeOrientation(activityRule)
18+
}
19+
}

app/src/androidTest/java/fr/free/nrw/commons/LoginActivityTest.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.test.espresso.intent.matcher.IntentMatchers
1111
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
1212
import androidx.test.espresso.intent.matcher.IntentMatchers.isInternal
1313
import androidx.test.espresso.matcher.ViewMatchers
14-
import androidx.test.filters.MediumTest
1514
import androidx.test.rule.ActivityTestRule
1615
import androidx.test.runner.AndroidJUnit4
1716
import fr.free.nrw.commons.auth.LoginActivity
@@ -23,8 +22,6 @@ import org.junit.Rule
2322
import org.junit.Test
2423
import org.junit.runner.RunWith
2524

26-
27-
@MediumTest
2825
@RunWith(AndroidJUnit4::class)
2926
class LoginActivityTest {
3027
@get:Rule
@@ -53,4 +50,9 @@ class LoginActivityTest {
5350
.perform(ViewActions.click())
5451
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL)));
5552
}
53+
54+
@Test
55+
fun orientationChange() {
56+
UITestHelper.changeOrientation(activityRule)
57+
}
5658
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.rule.ActivityTestRule
4+
import androidx.test.runner.AndroidJUnit4
5+
import fr.free.nrw.commons.contributions.MainActivity
6+
import org.junit.Rule
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class MainActivityTest {
12+
@get:Rule
13+
var activityRule = ActivityTestRule(MainActivity::class.java)
14+
15+
@Test
16+
fun orientationChange() {
17+
UITestHelper.changeOrientation(activityRule)
18+
}
19+
}

app/src/androidTest/java/fr/free/nrw/commons/NavigationBaseActivityTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ class NavigationBaseActivityTest {
4747
UITestHelper.sleep(500)
4848
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId))
4949
}
50+
51+
@Test
52+
fun orientationChange() {
53+
UITestHelper.changeOrientation(activityRule)
54+
}
5055
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.rule.ActivityTestRule
4+
import androidx.test.runner.AndroidJUnit4
5+
import org.junit.Rule
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
import fr.free.nrw.commons.explore.SearchActivity
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class SearchActivityTest {
12+
@get:Rule
13+
var activityRule = ActivityTestRule(SearchActivity::class.java)
14+
15+
@Test
16+
fun orientationChange() {
17+
UITestHelper.changeOrientation(activityRule)
18+
}
19+
}

app/src/androidTest/java/fr/free/nrw/commons/SettingsActivityTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,9 @@ class SettingsActivityTest {
150150
.inAdapterView(withId(android.R.id.list))
151151
.check(matches(not(isEnabled())))
152152
}
153+
154+
@Test
155+
fun orientationChange() {
156+
UITestHelper.changeOrientation(activityRule)
157+
}
153158
}

app/src/androidTest/java/fr/free/nrw/commons/SignupTest.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.test.espresso.intent.Intents.intended
88
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
99
import androidx.test.espresso.matcher.ViewMatchers
1010
import androidx.test.espresso.matcher.ViewMatchers.withId
11-
import androidx.test.filters.MediumTest
1211
import androidx.test.rule.ActivityTestRule
1312
import androidx.test.runner.AndroidJUnit4
1413
import fr.free.nrw.commons.auth.LoginActivity
@@ -18,7 +17,6 @@ import org.junit.Rule
1817
import org.junit.Test
1918
import org.junit.runner.RunWith
2019

21-
@MediumTest
2220
@RunWith(AndroidJUnit4::class)
2321
class SignupTest {
2422
@get:Rule
@@ -43,4 +41,9 @@ class SignupTest {
4341
intended(hasComponent(SignupActivity::class.java.name))
4442
Intents.release()
4543
}
44+
45+
@Test
46+
fun orientationChange() {
47+
UITestHelper.changeOrientation(activityRule)
48+
}
4649
}

app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt

+9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package fr.free.nrw.commons
22

3+
import android.app.Activity
4+
import android.content.pm.ActivityInfo
35
import androidx.test.espresso.Espresso.closeSoftKeyboard
46
import androidx.test.espresso.Espresso.onView
57
import androidx.test.espresso.NoMatchingViewException
68
import androidx.test.espresso.action.ViewActions
79
import androidx.test.espresso.matcher.ViewMatchers
10+
import androidx.test.rule.ActivityTestRule
811
import fr.free.nrw.commons.utils.StringUtils
912
import timber.log.Timber
1013

@@ -57,5 +60,11 @@ class UITestHelper {
5760
throw NotImplementedError("Configure your beta account's password")
5861
} else return password
5962
}
63+
fun <T: Activity> changeOrientation(activityRule: ActivityTestRule<T>){
64+
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
65+
assert(activityRule.activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
66+
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
67+
assert(activityRule.activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
68+
}
6069
}
6170
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.rule.ActivityTestRule
4+
import androidx.test.runner.AndroidJUnit4
5+
import fr.free.nrw.commons.upload.UploadActivity
6+
import org.junit.Rule
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class UploadActivityTest {
12+
@get:Rule
13+
var activityRule = ActivityTestRule(UploadActivity::class.java)
14+
15+
@Test
16+
fun orientationChange() {
17+
UITestHelper.changeOrientation(activityRule)
18+
}
19+
}

app/src/androidTest/java/fr/free/nrw/commons/WelcomeActivityTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ class WelcomeActivityTest {
9898
assert(activityRule.activity.isDestroyed)
9999
}}
100100
}
101+
102+
@Test
103+
fun orientationChange() {
104+
UITestHelper.changeOrientation(activityRule)
105+
}
101106
}

0 commit comments

Comments
 (0)