Skip to content

Commit 9c21d8e

Browse files
Merge pull request nextcloud#13472 from nextcloud/bugfix/launcher-activity-it-tests
BugFix - LauncherActivityIT Tests
2 parents ff35619 + 8dbe86a commit 9c21d8e

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,72 @@
66
*/
77
package com.nmc.android.ui
88

9+
import androidx.annotation.UiThread
10+
import androidx.test.core.app.launchActivity
911
import androidx.test.espresso.Espresso.onView
12+
import androidx.test.espresso.IdlingRegistry
1013
import androidx.test.espresso.assertion.ViewAssertions.matches
1114
import androidx.test.espresso.matcher.ViewMatchers
1215
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
1316
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
1417
import androidx.test.espresso.matcher.ViewMatchers.withId
15-
import androidx.test.ext.junit.rules.ActivityScenarioRule
1618
import androidx.test.ext.junit.runners.AndroidJUnit4
1719
import com.owncloud.android.AbstractIT
1820
import com.owncloud.android.R
19-
import org.junit.Rule
21+
import com.owncloud.android.utils.EspressoIdlingResource
22+
import org.junit.After
23+
import org.junit.Before
2024
import org.junit.Test
2125
import org.junit.runner.RunWith
2226

2327
@RunWith(AndroidJUnit4::class)
2428
class LauncherActivityIT : AbstractIT() {
2529

26-
@get:Rule
27-
val activityRule = ActivityScenarioRule(LauncherActivity::class.java)
30+
@Before
31+
fun registerIdlingResource() {
32+
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
33+
}
34+
35+
@After
36+
fun unregisterIdlingResource() {
37+
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
38+
}
2839

2940
@Test
41+
@UiThread
3042
fun testSplashScreenWithEmptyTitlesShouldHideTitles() {
31-
waitForIdleSync()
32-
33-
onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed()))
34-
35-
onView(withId(R.id.splashScreenBold)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
36-
onView(withId(R.id.splashScreenNormal)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
43+
launchActivity<LauncherActivity>().use { scenario ->
44+
scenario.onActivity { _ ->
45+
onIdleSync {
46+
onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed()))
47+
onView(
48+
withId(R.id.splashScreenBold)
49+
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
50+
onView(
51+
withId(R.id.splashScreenNormal)
52+
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
53+
}
54+
}
55+
}
3756
}
3857

3958
@Test
59+
@UiThread
4060
fun testSplashScreenWithTitlesShouldShowTitles() {
41-
waitForIdleSync()
42-
onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed()))
61+
launchActivity<LauncherActivity>().use { scenario ->
62+
scenario.onActivity {
63+
onIdleSync {
64+
onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed()))
4365

44-
activityRule.scenario.onActivity {
45-
it.setSplashTitles("Example", "Cloud")
46-
}
66+
EspressoIdlingResource.increment()
67+
it.setSplashTitles("Example", "Cloud")
68+
EspressoIdlingResource.decrement()
4769

48-
val onePercentArea = ViewMatchers.isDisplayingAtLeast(1)
49-
onView(withId(R.id.splashScreenBold)).check(matches(onePercentArea))
50-
onView(withId(R.id.splashScreenNormal)).check(matches(onePercentArea))
70+
val onePercentArea = ViewMatchers.isDisplayingAtLeast(1)
71+
onView(withId(R.id.splashScreenBold)).check(matches(onePercentArea))
72+
onView(withId(R.id.splashScreenNormal)).check(matches(onePercentArea))
73+
}
74+
}
75+
}
5176
}
5277
}

0 commit comments

Comments
 (0)