зеркало из https://github.com/nextcloud/android.git
use idling resources
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
Родитель
9ce429ad87
Коммит
c797c1efc2
|
@ -7,32 +7,44 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.core.app.launchActivity
|
||||
import androidx.test.espresso.IdlingRegistry
|
||||
import com.nextcloud.utils.EspressoIdlingResource
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.lib.resources.notifications.models.Action
|
||||
import com.owncloud.android.lib.resources.notifications.models.Notification
|
||||
import com.owncloud.android.lib.resources.notifications.models.RichObject
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
class NotificationsActivityIT : AbstractIT() {
|
||||
@get:Rule
|
||||
var activityRule = IntentsTestRule(NotificationsActivity::class.java, true, false)
|
||||
private val testClassName = "com.owncloud.android.ui.activity.NotificationsActivityIT"
|
||||
|
||||
@Before
|
||||
fun registerIdlingResource() {
|
||||
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
|
||||
}
|
||||
|
||||
@After
|
||||
fun unregisterIdlingResource() {
|
||||
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun empty() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
sut.runOnUiThread { sut.populateList(ArrayList<Notification>()) }
|
||||
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
launchActivity<NotificationsActivity>().use { scenario ->
|
||||
scenario.onActivity { sut ->
|
||||
onIdleSync {
|
||||
sut.runOnUiThread { sut.populateList(ArrayList()) }
|
||||
val screenShotName = createName(testClassName + "_" + "empty", "")
|
||||
screenshotViaName(sut, screenShotName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,24 +129,24 @@ class NotificationsActivityIT : AbstractIT() {
|
|||
)
|
||||
)
|
||||
|
||||
activityRule.launchActivity(null).apply {
|
||||
runOnUiThread {
|
||||
populateList(notifications)
|
||||
launchActivity<NotificationsActivity>().use { scenario ->
|
||||
scenario.onActivity { sut ->
|
||||
sut.runOnUiThread { sut.populateList(notifications) }
|
||||
val screenShotName = createName(testClassName + "_" + "showNotifications", "")
|
||||
screenshotViaName(sut, screenShotName)
|
||||
}
|
||||
shortSleep()
|
||||
screenshot(binding.list)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun error() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
shortSleep()
|
||||
|
||||
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
|
||||
|
||||
screenshot(sut)
|
||||
launchActivity<NotificationsActivity>().use { scenario ->
|
||||
scenario.onActivity { sut ->
|
||||
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
|
||||
val screenShotName = createName(testClassName + "_" + "error", "")
|
||||
screenshotViaName(sut, screenShotName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,6 +192,8 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
|
|||
|
||||
@VisibleForTesting
|
||||
fun populateList(notifications: List<Notification>?) {
|
||||
EspressoIdlingResource.increment()
|
||||
|
||||
initializeAdapter()
|
||||
adapter?.setNotificationItems(notifications)
|
||||
binding.loadingContent.visibility = View.GONE
|
||||
|
@ -207,6 +209,8 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
|
|||
binding.swipeContainingList.visibility = View.GONE
|
||||
binding.swipeContainingEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
EspressoIdlingResource.decrement()
|
||||
}
|
||||
|
||||
private fun fetchAndSetData() {
|
||||
|
@ -292,6 +296,8 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
|
|||
|
||||
@VisibleForTesting
|
||||
fun setEmptyContent(headline: String?, message: String?) {
|
||||
EspressoIdlingResource.increment()
|
||||
|
||||
binding.swipeContainingList.visibility = View.GONE
|
||||
binding.loadingContent.visibility = View.GONE
|
||||
binding.swipeContainingEmpty.visibility = View.VISIBLE
|
||||
|
@ -301,6 +307,8 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
|
|||
binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_notification)
|
||||
binding.emptyList.emptyListViewText.visibility = View.VISIBLE
|
||||
binding.emptyList.emptyListIcon.visibility = View.VISIBLE
|
||||
|
||||
EspressoIdlingResource.decrement()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче